diff --git a/src/lib/utils/websocket_utils.ts b/src/lib/utils/websocket_utils.ts index 5c12c98..659580e 100644 --- a/src/lib/utils/websocket_utils.ts +++ b/src/lib/utils/websocket_utils.ts @@ -152,7 +152,7 @@ export async function fetchNostrEvent(filter: NostrFilter): Promise((resolve) => { setTimeout(() => { console.warn("[WebSocket Utils]: Fetch timeout reached"); @@ -160,18 +160,12 @@ export async function fetchNostrEvent(filter: NostrFilter): Promise { - // Find the first successful result - for (const result of results) { - if (result.status === 'fulfilled' && result.value) { - return result.value; - } - } - return null; - }); - - // Race between the fetch and the timeout - const result = await Promise.race([fetchPromise, timeoutPromise]); + // Race between individual relay results and the timeout + const result = await Promise.race([ + // Wait for the first successful result from any relay + Promise.race(relayPromises.filter(p => p !== null)), + timeoutPromise + ]); if (result) { return result;