2024-08-28 00:23:29 +02:00
|
|
|
import type { Client } from "@versia/client";
|
2025-05-26 11:19:15 +02:00
|
|
|
import type { Account } from "@versia/client/schemas";
|
|
|
|
|
import type { z } from "zod";
|
2024-04-21 21:38:51 -10:00
|
|
|
|
2024-04-26 18:50:30 -10:00
|
|
|
export const useAccount = (
|
2024-08-28 00:23:29 +02:00
|
|
|
client: MaybeRef<Client | null>,
|
2024-05-11 16:33:40 -10:00
|
|
|
accountId: MaybeRef<string | null>,
|
2024-04-26 18:50:30 -10:00
|
|
|
) => {
|
2024-04-25 19:54:02 -10:00
|
|
|
if (!client) {
|
2025-05-26 11:19:15 +02:00
|
|
|
return ref(null as z.infer<typeof Account> | null);
|
2024-04-21 21:38:51 -10:00
|
|
|
}
|
|
|
|
|
|
2025-05-26 11:19:15 +02:00
|
|
|
const output = ref(null as z.infer<typeof Account> | null);
|
2024-04-26 15:28:12 -10:00
|
|
|
|
2024-05-11 16:33:40 -10:00
|
|
|
watchEffect(() => {
|
2024-06-19 14:07:56 -10:00
|
|
|
if (toValue(accountId)) {
|
2024-05-11 23:23:38 -10:00
|
|
|
toValue(client)
|
|
|
|
|
?.getAccount(toValue(accountId) ?? "")
|
2024-05-11 16:33:40 -10:00
|
|
|
.then((res) => {
|
|
|
|
|
output.value = res.data;
|
|
|
|
|
});
|
2024-06-19 14:07:56 -10:00
|
|
|
}
|
2024-05-11 16:33:40 -10:00
|
|
|
});
|
2024-04-26 15:28:12 -10:00
|
|
|
|
|
|
|
|
return output;
|
2024-04-21 21:38:51 -10:00
|
|
|
};
|