From d957a8730dd49a9d5996fc311130a07e2c8f411d Mon Sep 17 00:00:00 2001 From: tomiir Date: Mon, 19 Feb 2024 16:31:09 -0600 Subject: [PATCH] chore: improve code by always filtering previously found txs --- .../src/controllers/TransactionsController.ts | 28 ++----------------- .../views/w3m-onramp-activity-view/index.ts | 5 ---- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/packages/core/src/controllers/TransactionsController.ts b/packages/core/src/controllers/TransactionsController.ts index 46304f3524..808790ee37 100644 --- a/packages/core/src/controllers/TransactionsController.ts +++ b/packages/core/src/controllers/TransactionsController.ts @@ -94,37 +94,14 @@ export const TransactionsController = { transactions: Transaction[] = [] ) { const grouped = transactionsMap - console.log('GROUPING TXS', transactions, transactionsMap) transactions.forEach(transaction => { const year = new Date(transaction.metadata.minedAt).getFullYear() const month = new Date(transaction.metadata.minedAt).getMonth() const yearTransactions = grouped[year] ?? {} const monthTransactions = yearTransactions[month] ?? [] - const repeated = monthTransactions.find( - tx => tx.id === transaction.id && tx.metadata.status === transaction.metadata.status - ) - if (repeated) { - return - } - - let newMonthTransactions = [...monthTransactions] - - const coinbaseTxToUpdate = monthTransactions.find( - tx => - tx.id === transaction.id && - tx.metadata.status === 'ONRAMP_TRANSACTION_STATUS_IN_PROGRESS' && - (transaction.metadata.status === 'ONRAMP_TRANSACTION_STATUS_SUCCESS' || - transaction.metadata.status === 'ONRAMP_TRANSACTION_STATUS_FAILED') - ) - - console.log('COINBASE TX TO UPDATE', coinbaseTxToUpdate, transaction) - - if (coinbaseTxToUpdate) { - newMonthTransactions = monthTransactions.filter( - tx => tx.metadata.minedAt !== transaction.metadata.minedAt - ) - } + // If there's a transaction with the same id, remove the old one + const newMonthTransactions = monthTransactions.filter(tx => tx.id !== transaction.id) grouped[year] = { ...yearTransactions, @@ -133,7 +110,6 @@ export const TransactionsController = { ) } }) - console.log('GROUPED', grouped) return grouped }, diff --git a/packages/scaffold/src/views/w3m-onramp-activity-view/index.ts b/packages/scaffold/src/views/w3m-onramp-activity-view/index.ts index 2b1200e336..da214f83d0 100644 --- a/packages/scaffold/src/views/w3m-onramp-activity-view/index.ts +++ b/packages/scaffold/src/views/w3m-onramp-activity-view/index.ts @@ -45,7 +45,6 @@ export class W3mOnRampActivityView extends LitElement { clearTimeout(this.refetchTimeout) }, TransactionsController.subscribe(val => { - console.log('Coinbase Transactions updated', val.coinbaseTransactions) this.coinbaseTransactions = { ...val.coinbaseTransactions } }) ] @@ -160,13 +159,10 @@ export class W3mOnRampActivityView extends LitElement { const today = new Date() const currentMonthTxs = this.coinbaseTransactions[today.getFullYear()]?.[today.getMonth()] || [] - console.log('Activity - Current month transactions', currentMonthTxs) const loadingTransactions = currentMonthTxs.filter( transaction => transaction.metadata.status === 'ONRAMP_TRANSACTION_STATUS_IN_PROGRESS' ) - console.log('Activity - Loading Transactions', loadingTransactions) - if (loadingTransactions.length === 0) { clearTimeout(this.refetchTimeout) @@ -176,7 +172,6 @@ export class W3mOnRampActivityView extends LitElement { // Wait 2 seconds before refetching this.refetchTimeout = setTimeout(async () => { const address = AccountController.state.address - console.log('Refetching transactions') await TransactionsController.fetchTransactions(address, 'coinbase') this.refetchLoadingTransactions() }, 3000)