Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/logic/safe/store/reducer/gatewayTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TransactionSummary } from '@gnosis.pm/safe-react-gateway-sdk'
import get from 'lodash/get'
import cloneDeep from 'lodash/cloneDeep'
import { Action, handleActions } from 'redux-actions'
Expand All @@ -10,7 +9,6 @@ import {
import {
HistoryGatewayResponse,
isConflictHeader,
isDateLabel,
isLabel,
isMultisigExecutionInfo,
isTransactionSummary,
Expand Down Expand Up @@ -51,28 +49,27 @@ export const gatewayTransactionsReducer = handleActions<GatewayTransactionsState
const newHistory: StoreStructure['history'] = cloneDeep(state[chainId]?.[safeAddress]?.history || {})

values.forEach((value) => {
if (isDateLabel(value)) {
if (!isTransactionSummary(value)) {
// DATE_LABEL is discarded as it's not needed for the current implementation
return
}

if (isTransactionSummary(value)) {
const transaction = (value as any).transaction as TransactionSummary
const startOfDate = getLocalStartOfDate(transaction.timestamp)
const transaction = value.transaction
const startOfDate = getLocalStartOfDate(transaction.timestamp)

if (typeof newHistory[startOfDate] === 'undefined') {
newHistory[startOfDate] = []
}
if (newHistory[startOfDate] === undefined) {
newHistory[startOfDate] = []
}

const txExist = newHistory[startOfDate].some(({ id }) => sameString(id, transaction.id))
const txIndex = newHistory[startOfDate].findIndex(({ id }) => sameString(id, transaction.id))

if (!txExist) {
newHistory[startOfDate].push(transaction)
// pushing a newer transaction to the existing list messes the transactions order
// this happens when most recent transactions are added to the existing txs in the store
newHistory[startOfDate] = newHistory[startOfDate].sort((a, b) => b.timestamp - a.timestamp)
}
return
if (txIndex >= 0) {
newHistory[startOfDate][txIndex] = transaction
} else {
newHistory[startOfDate].push(transaction)
// pushing a newer transaction to the existing list messes the transactions order
// this happens when most recent transactions are added to the existing txs in the store
newHistory[startOfDate] = newHistory[startOfDate].sort((a, b) => b.timestamp - a.timestamp)
}
})

Expand Down