From 8d20678c754f0ea368fd8fe8c7921dd98c45cb55 Mon Sep 17 00:00:00 2001 From: enes Date: Wed, 20 Nov 2024 13:50:49 +0100 Subject: [PATCH] fix(ndk): dont create NDKRelaySet from empty arrays --- src/contexts/NDKContext.tsx | 6 ++++-- src/hooks/useComments.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/contexts/NDKContext.tsx b/src/contexts/NDKContext.tsx index e7cd380..75d0d41 100644 --- a/src/contexts/NDKContext.tsx +++ b/src/contexts/NDKContext.tsx @@ -245,7 +245,7 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => { // Find the user's relays (10s timeout). const relayUrls = await Promise.race([ getRelayListForUser(hexKey, ndk), - timeout(10000) + timeout(3000) ]) .then((ndkRelayList) => { if (ndkRelayList) return ndkRelayList[userRelaysType] @@ -265,7 +265,9 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => { .fetchEvents( filter, { closeOnEose: true, cacheUsage: NDKSubscriptionCacheUsage.PARALLEL }, - NDKRelaySet.fromRelayUrls(relayUrls, ndk, true) + relayUrls.length + ? NDKRelaySet.fromRelayUrls(relayUrls, ndk, true) + : undefined ) .then((ndkEventSet) => { const ndkEvents = Array.from(ndkEventSet) diff --git a/src/hooks/useComments.ts b/src/hooks/useComments.ts index 8b107bc..e62f918 100644 --- a/src/hooks/useComments.ts +++ b/src/hooks/useComments.ts @@ -66,7 +66,9 @@ export const useComments = ( closeOnEose: false, cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST }, - NDKRelaySet.fromRelayUrls(Array.from(relayUrls), ndk) + relayUrls.size + ? NDKRelaySet.fromRelayUrls(Array.from(relayUrls), ndk) + : undefined ) subscription.on('event', (ndkEvent) => {