Skip to content

Commit

Permalink
fix: onramp transaction status group (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Feb 19, 2024
1 parent c54d4e1 commit 965f92c
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions packages/core/src/controllers/TransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,19 @@ export const TransactionsController = {
transactionsMap: TransactionByYearMap = {},
transactions: Transaction[] = []
) {
const grouped: TransactionByYearMap = transactionsMap

const grouped = 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] ?? []

if (
monthTransactions.find(
t =>
(t.metadata.hash && t.metadata.hash === transaction.metadata.hash) ||
t.metadata.minedAt === transaction.metadata.minedAt
)
) {
return
}
// 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,
[month]: [...monthTransactions, transaction].sort(
[month]: [...newMonthTransactions, transaction].sort(
(a, b) => new Date(b.metadata.minedAt).getTime() - new Date(a.metadata.minedAt).getTime()
)
}
Expand Down

0 comments on commit 965f92c

Please sign in to comment.