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>
This commit is contained in:
ekzyis 2025-09-16 19:45:42 +02:00 committed by GitHub
parent e00c04c9bb
commit a0dffb2f18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(