From 0ff1e197690ba867479ac8bb5015c2da7971bf36 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 22 May 2025 12:06:00 -0700 Subject: [PATCH] Refresh the transaction list on resync --- CHANGELOG.md | 1 + src/hooks/useTransactionList.ts | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5876109bc5e..7b3f241b785 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - fixed: Primary button transforming on the animation on `GettingStartedScene` - fixed: `NotificationCenterScene` could crash if there was an undismissed new token notification and the associated wallet no longer existed - removed: Disable Fantom transaction list +- fixed: Refresh the tranaction list on resync - fixed: Show the correct username in the "Forget Account" modal. - fixed: `TransactionListRow` missing timestamp while syncing - fixed: Don't show required text for optional import options diff --git a/src/hooks/useTransactionList.ts b/src/hooks/useTransactionList.ts index 6d966c24e13..e3612913a50 100644 --- a/src/hooks/useTransactionList.ts +++ b/src/hooks/useTransactionList.ts @@ -83,16 +83,35 @@ export function useTransactionList(wallet: EdgeCurrencyWallet, tokenId: EdgeToke // Don't restart the stream if a transaction changes, // but just overlay the new transactions over the old ones: const cleanupChanged = wallet.on('transactionsChanged', txs => { - let relevant = false + // Make a set of existing transactions: const existingTxidsSet = new Set() streamedTxs.forEach(tx => existingTxidsSet.add(tx.txid)) + const oldestTx = streamedTxs[streamedTxs.length - 1] + + // Figure out what type of change this is: + let resync = false + let relevant = false for (const tx of txs) { - if (tx.tokenId === tokenId && existingTxidsSet.has(tx.txid)) { + if (!existingTxidsSet.has(tx.txid)) { + // If we don't have this transaction, + // but it's above the bottom of our list, + // then we have problem and need a refresh. + if (oldestTx == null || tx.date >= oldestTx.date) { + resync = true + } + } else if (tx.tokenId === tokenId) { + // Stomp our existing transaction with the same id: relevant = true changedTxs.set(tx.txid, tx) } } - if (relevant) requestRender() + + if (resync) restartStream() + else if (relevant) requestRender() + }) + + const cleanupRemoved = wallet.on('transactionsRemoved', () => { + restartStream() }) // Constructs a new stream, then updates `cleanupStream` and `requestMore`: @@ -160,6 +179,7 @@ export function useTransactionList(wallet: EdgeCurrencyWallet, tokenId: EdgeToke return () => { cleanupNew() cleanupChanged() + cleanupRemoved() cleanupStream() } // eslint-disable-next-line react-hooks/exhaustive-deps