From a0dffb2f188410f80c5b5b90cf9b21b1a85975a2 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 16 Sep 2025 19:45:42 +0200 Subject: [PATCH] Poll for wallets until success (#2541) * Add unit to poll interval constants * Poll for wallets until success * Stop polling on (impossible) unmount --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> --- wallets/client/hooks/query.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wallets/client/hooks/query.js b/wallets/client/hooks/query.js index 439cbcb1..56ad860f 100644 --- a/wallets/client/hooks/query.js +++ b/wallets/client/hooks/query.js @@ -37,7 +37,7 @@ import { } from '@/wallets/lib/util' import { protocolTestSendPayment } from '@/wallets/client/protocols' import { timeoutSignal } from '@/lib/time' -import { WALLET_SEND_PAYMENT_TIMEOUT_MS } from '@/lib/constants' +import { FAST_POLL_INTERVAL_MS, WALLET_SEND_PAYMENT_TIMEOUT_MS } from '@/lib/constants' import { useToast } from '@/components/toast' import { useMe } from '@/components/me' import { useTemplates, useWallets, useWalletsLoading } from '@/wallets/client/context' @@ -51,6 +51,18 @@ export function useWalletsQuery () { const { decryptWallet, ready } = useWalletDecryption() + useEffect(() => { + // the query might fail because of network errors like ERR_NETWORK_CHANGED + // but for some reason, the retry link does not retry the query so we poll instead ourselves here. + // https://github.com/stackernews/stacker.news/issues/2522 + if (!wallets) { + query.startPolling(FAST_POLL_INTERVAL_MS) + } else { + query.stopPolling() + } + return () => query.stopPolling() + }, [query.startPolling, query.stopPolling, wallets]) + useEffect(() => { if (!query.data?.wallets || !ready) return Promise.all(