mirror of
https://github.com/joinmarket-webui/jam.git
synced 2026-08-18 13:09:10 +02:00
refactor: reduce reloading utxos after rescan
This commit is contained in:
parent
292167a66c
commit
57e4b8bde6
1 changed files with 9 additions and 9 deletions
18
src/App.tsx
18
src/App.tsx
|
|
@ -457,27 +457,27 @@ const WalletInfoAutoReload = ({ walletFileName }: { walletFileName: WalletFileNa
|
|||
const { rescanInfo: currentRescanInfo } = useRescanStatus()
|
||||
const { refetch: refetchWalletBalance, utxosHashHex } = useJamWalletInfoContext()
|
||||
const [previousRescanning, setPreviousRescanning] = useState<boolean>(currentRescanInfo.rescanning)
|
||||
const [rescanningFinished, setRescanningFinished] = useState<boolean>(false)
|
||||
|
||||
if (previousRescanning !== currentRescanInfo.rescanning) {
|
||||
setPreviousRescanning(currentRescanInfo.rescanning)
|
||||
setRescanningFinished(previousRescanning === true && currentRescanInfo.rescanning === false)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @tanstack/query/exhaustive-deps
|
||||
useQuery({
|
||||
queryKey: [
|
||||
'reload-wallet-after-rescan-or-utxo-change',
|
||||
walletFileName,
|
||||
previousRescanning,
|
||||
currentRescanInfo.rescanning,
|
||||
refetchWalletBalance,
|
||||
utxosHashHex,
|
||||
rescanningFinished,
|
||||
],
|
||||
queryFn: async () => {
|
||||
const rescanningFinished = previousRescanning === true && currentRescanInfo.rescanning === false
|
||||
|
||||
const delayBefore: Milliseconds = rescanningFinished
|
||||
? RELOAD_WALLET_INFO_DELAY.AFTER_RESCAN
|
||||
: RELOAD_WALLET_INFO_DELAY.AFTER_UTXO_CHANGE
|
||||
console.info('Trigger refetch looking for funds after rescan or utxo changes with delay %d...', delayBefore)
|
||||
|
||||
const result = await refetchWalletBalance({ delayBefore })
|
||||
setPreviousRescanning(currentRescanInfo.rescanning)
|
||||
return result
|
||||
return await refetchWalletBalance({ delayBefore })
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue