Skip to content

Commit

Permalink
fixed duplicate entries bug
Browse files Browse the repository at this point in the history
  • Loading branch information
blurpesec committed Jan 2, 2022
1 parent 45a9ae7 commit 2318960
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export default function RecentTransactionList({ accountsList, className = '' }:
const pending = accountTxs.filter(txIsPending);
const completed = accountTxs.filter(txIsSuccessful);
const failed = accountTxs.filter(txIsFailed);

const createEntries = (_: string, collection: ITxHistoryEntry[]) =>
collection.map(
({
Expand Down
14 changes: 11 additions & 3 deletions src/services/TxHistory/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getAssetByContractAndNetwork, getBaseAssetByNetwork } from '@services/S
import { ITxMetaTypes } from '@store/txHistory.slice';
import { Asset, IAccount, ITxReceipt, Network, TxType } from '@types';
import { fromTokenBase, fromWei, isSameAddress, isVoid, toWei, Wei } from '@utils';
import { isSameHash } from '@utils/isSameAddress';

export const makeTxReceipt = (
tx: ITxHistoryApiResponse,
Expand Down Expand Up @@ -78,10 +77,19 @@ export const makeTxReceipt = (

export const merge = (apiTxs: ITxReceipt[], accountTxs: ITxReceipt[]): ITxReceipt[] => {
// Prioritize Account TX - needs to be more advanced?
const hashMap = accountTxs.reduce((acc, cur) => {
acc[cur.hash.toLowerCase()] = true
return acc
}, {} as { [key: string]: boolean })
const filteredApiTxs = apiTxs.filter(
(tx) => !accountTxs.find((a) => isSameHash(a.hash, tx.hash))
(tx) => !hashMap[tx.hash.toLowerCase()]
);
return filteredApiTxs.concat(accountTxs);
return Object.values(filteredApiTxs.concat(accountTxs).reduce((acc,curr) => {
if (!acc[curr.hash.toLowerCase()]) {
acc[curr.hash.toLowerCase()] = curr;
}
return acc
}, {} as { [key: string]: ITxReceipt }));
};

export const deriveTxType = (
Expand Down

0 comments on commit 2318960

Please sign in to comment.