Skip to content

Refresh the transaction list on resync #5595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions src/hooks/useTransactionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()
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`:
Expand Down Expand Up @@ -160,6 +179,7 @@ export function useTransactionList(wallet: EdgeCurrencyWallet, tokenId: EdgeToke
return () => {
cleanupNew()
cleanupChanged()
cleanupRemoved()
cleanupStream()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
Loading