This commit is contained in:
Ren Amamiya
2023-07-26 09:26:40 +07:00
parent 89dd4f5c9d
commit f52ea04541
13 changed files with 69 additions and 140 deletions

View File

@@ -1,11 +1,21 @@
import { useQuery } from '@tanstack/react-query';
import { useNDK } from '@libs/ndk/provider';
import { getActiveAccount } from '@libs/storage';
export function useAccount() {
const { ndk } = useNDK();
const { status, data: account } = useQuery(
['currentAccount'],
async () => await getActiveAccount(),
async () => {
const account = await getActiveAccount();
if (account?.pubkey) {
const user = ndk.getUser({ hexpubkey: account?.pubkey });
await user.fetchProfile();
return { ...account, ...user.profile };
}
return account;
},
{
staleTime: Infinity,
refetchOnMount: true,