diff --git a/src/contexts/NDKContext.tsx b/src/contexts/NDKContext.tsx index 61f856c..5db3ba5 100644 --- a/src/contexts/NDKContext.tsx +++ b/src/contexts/NDKContext.tsx @@ -41,8 +41,7 @@ export interface NDKContextType { ) => Promise findMetadata: ( pubkey: string, - opts?: NDKSubscriptionOptions, - storeProfileEvent?: boolean + opts?: NDKSubscriptionOptions ) => Promise getNDKRelayList: (pubkey: Hexpubkey) => Promise publish: (event: NDKEvent, explicitRelayUrls?: string[]) => Promise @@ -205,21 +204,17 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => { */ const findMetadata = async ( pubkey: string, - opts?: NDKSubscriptionOptions, - storeProfileEvent?: boolean + opts?: NDKSubscriptionOptions ): Promise => { const npub = hexToNpub(pubkey) const user = new NDKUser({ npub }) user.ndk = ndk - return await user.fetchProfile( - { - cacheUsage: NDKSubscriptionCacheUsage.PARALLEL, - ...(opts || {}) - }, - storeProfileEvent - ) + return await user.fetchProfile({ + cacheUsage: NDKSubscriptionCacheUsage.PARALLEL, + ...(opts || {}) + }) } const getNDKRelayList = async (pubkey: Hexpubkey) => { @@ -250,8 +245,7 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => { ndkRelaySet = NDKRelaySet.fromRelayUrls(explicitRelayUrls, ndk) } - return event - .publish(ndkRelaySet, 10000) + return await Promise.race([event.publish(ndkRelaySet), timeout(3000)]) .then((res) => { const relaysPublishedOn = Array.from(res) return relaysPublishedOn.map((relay) => relay.url) diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index ff38a06..a59e4ba 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -25,9 +25,8 @@ export const useAuth = () => { const { getRelayInfo } = useDvm() const { findMetadata, getNDKRelayList } = useNDKContext() - const { auth: authState, relays: relaysState } = useAppSelector( - (state) => state - ) + const authState = useAppSelector((state) => state.auth) + const relaysState = useAppSelector((state) => state.relays) const checkSession = useCallback(() => { const savedAuthToken = getAuthToken() @@ -66,7 +65,7 @@ export const useAuth = () => { const emptyMetadata = getEmptyMetadataEvent() try { - const profile = await findMetadata(pubkey, {}, true) + const profile = await findMetadata(pubkey) if (profile && profile.profileEvent) { const event: Event = JSON.parse(profile.profileEvent) diff --git a/src/layouts/Main.tsx b/src/layouts/Main.tsx index e4bb7a6..bb58718 100644 --- a/src/layouts/Main.tsx +++ b/src/layouts/Main.tsx @@ -164,7 +164,7 @@ export const MainLayout = () => { if (loggedIn) { if (!loginMethod || !usersPubkey) return logout() - findMetadata(usersPubkey, {}, true).then((profile) => { + findMetadata(usersPubkey).then((profile) => { if (profile && profile.profileEvent) { try { const event: Event = JSON.parse(profile.profileEvent)