From a003bd7124236089d38dd8fac7c60696817c4621 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 16:08:25 +0300 Subject: [PATCH] Add check for transaction in current transactions list. --- src/app/_services/transaction.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index 94164ae..bcd4ca6 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -108,9 +108,14 @@ export class TransactionService { } 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); if (this.transactions.length > cacheSize) { - this.transactions.length = cacheSize; + this.transactions.length = Math.min(this.transactions.length, cacheSize); } this.transactionList.next(this.transactions); }