Add check for transaction in current transactions list.

This commit is contained in:
Spencer Ofwiti 2021-05-18 16:08:25 +03:00
parent 9235c969fa
commit a003bd7124

View File

@ -108,9 +108,14 @@ export class TransactionService {
} }
addTransaction(transaction, cacheSize: number): void { addTransaction(transaction, cacheSize: number): void {
const savedIndex = this.transactions.findIndex(tx => tx.tx.txHash === transaction.tx.txHash);
if (savedIndex === 0) { return; }
if (savedIndex > 0) {
this.transactions.splice(savedIndex, 1);
}
this.transactions.unshift(transaction); this.transactions.unshift(transaction);
if (this.transactions.length > cacheSize) { if (this.transactions.length > cacheSize) {
this.transactions.length = cacheSize; this.transactions.length = Math.min(this.transactions.length, cacheSize);
} }
this.transactionList.next(this.transactions); this.transactionList.next(this.transactions);
} }