clean up and improve perf
This commit is contained in:
@@ -2,10 +2,8 @@ import { NDKUserProfile } from '@nostr-dev-kit/ndk';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useNDK } from '@libs/ndk/provider';
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
export function useProfile(pubkey: string, embed?: string) {
|
||||
const { db } = useStorage();
|
||||
const { ndk } = useNDK();
|
||||
const {
|
||||
status,
|
||||
@@ -21,13 +19,7 @@ export function useProfile(pubkey: string, embed?: string) {
|
||||
|
||||
const cleanPubkey = pubkey.replace('-', '');
|
||||
const user = ndk.getUser({ hexpubkey: cleanPubkey });
|
||||
|
||||
const profile = await user.fetchProfile({ closeOnEose: true });
|
||||
if (!user.profile) return Promise.reject(new Error('profile not found'));
|
||||
|
||||
await db.createProfile(cleanPubkey, profile);
|
||||
|
||||
return user.profile;
|
||||
return await user.fetchProfile();
|
||||
},
|
||||
{
|
||||
enabled: !!ndk,
|
||||
@@ -35,6 +27,7 @@ export function useProfile(pubkey: string, embed?: string) {
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
retry: 2,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user