Skip to content

Commit

Permalink
dedup txs before displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
yushih committed Sep 27, 2024
1 parent 8721aa6 commit c583889
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,7 @@ export default class TransactionsStore extends Store<StoresMap, ActionsMap> {
throw new Error('unexpected nullish headRequest.promise');
}
headRequest.promise.then(result => {
const { txs } = this.getTxHistoryState(publicDeriverId);
runInAction(() => {
txs.splice(0, 0, ...result);
});
return this._afterLoadingNewTxs(result, publicDeriver);
return this.updateNewTransactions(result, publicDeriver);
}).catch(error => {
console.error('error when loading transaction list head', error)
});
Expand Down Expand Up @@ -550,9 +546,13 @@ export default class TransactionsStore extends Store<StoresMap, ActionsMap> {
publicDeriver: WalletState,
): Promise<void> {
const { txs } = this.getTxHistoryState(publicDeriver.publicDeriverId);
// newTxs is not supposed to have duplicate txs to existing ones but there were unknown cases
// reported
const existingTxHashes = new Set(txs.map(tx => tx.txid));
const unseenTxs = [...new Set(newTxs)].filter(tx => !existingTxHashes.has(tx.txid));
runInAction(() => {
txs.splice(0, 0, ...newTxs);
txs.splice(0, 0, ...unseenTxs);
});
await this._afterLoadingNewTxs(txs, publicDeriver);
await this._afterLoadingNewTxs(unseenTxs, publicDeriver);
}
}

0 comments on commit c583889

Please sign in to comment.