diff --git a/src/features/Dashboard/components/RecentTransactionList.tsx b/src/features/Dashboard/components/RecentTransactionList.tsx index 64956f3ed18..8f93fb7c1e7 100644 --- a/src/features/Dashboard/components/RecentTransactionList.tsx +++ b/src/features/Dashboard/components/RecentTransactionList.tsx @@ -37,7 +37,7 @@ interface Props { export interface ITxTypeConfigObj { icon(): any; - label(asset: Asset): string; + label(assetTxTypeDesignation: string): string; } const SAssetIcon = styled(AssetIcon)` @@ -66,7 +66,7 @@ const SCombinedCircle = (asset: Asset) => { ); }; -const makeTxIcon = (txConfig: ITxTypeConfigObj, asset: Asset) => { +const makeTxIcon = (txConfig: ITxTypeConfigObj, asset?: Asset) => { const greyscaleIcon = asset && <>{SCombinedCircle(asset)}; const baseIcon = ( @@ -95,7 +95,10 @@ export default function RecentTransactionList({ accountsList, className = '' }: .map(({ txType, ...tx }) => ({ ...tx, txType: txType as TxType })), [txHistory, accountsList.length] ); - + const accountsMap = accountsList.reduce((acc, cur) => { + acc[cur.address.toLowerCase()] = true + return acc; + }, {} as {[key: string]: boolean} ); const pending = accountTxs.filter(txIsPending); const completed = accountTxs.filter(txIsSuccessful); const failed = accountTxs.filter(txIsFailed); @@ -137,30 +140,25 @@ export default function RecentTransactionList({ accountsList, className = '' }: } as IFullTxHistoryValueTransfer); } const entryConfig = constructTxTypeConfig(txTypeMetas[txType] || { type: txType }); - const sentValueTransfers = valueTransfers.filter((t) => isSameAddress(t.from, from)) - const receivedValueTransfers = valueTransfers.filter((t) => isSameAddress(t.to, from)) - const firstbase = bigify('0') - const secondbase = bigify('0') - const sentFiatValue = receivedValueTransfers.reduce((acc, cur) => { - acc.plus(convertToFiat( + const sentValueTransfers = valueTransfers.filter((t) => accountsMap[t.from.toLowerCase()]); + const receivedValueTransfers = valueTransfers.filter((t) => accountsMap[t.to.toLowerCase()]) + const receivedFiatValue = receivedValueTransfers.reduce((acc, cur) => { + return acc.plus(convertToFiat( cur.amount, getAssetRate(cur.asset) )) - return acc - }, firstbase) - const receivedFiatValue = sentValueTransfers.reduce((acc, cur) => { - acc.plus(convertToFiat( + }, bigify('0')) + const sentFiatValue = sentValueTransfers.reduce((acc, cur) => { + return acc.plus(convertToFiat( cur.amount, getAssetRate(cur.asset) )) - return acc - }, secondbase) - /* todo: change from first transfer to include multi-transactions */ + }, bigify('0')) return [ , @@ -194,7 +192,7 @@ export default function RecentTransactionList({ accountsList, className = '' }: fiat={{ symbol: getFiat(settings).symbol, ticker: getFiat(settings).ticker, - amount: receivedFiatValue.toFixed(2) + amount: sentFiatValue.toFixed(2) }} />} , @@ -214,7 +212,7 @@ export default function RecentTransactionList({ accountsList, className = '' }: fiat={{ symbol: getFiat(settings).symbol, ticker: getFiat(settings).ticker, - amount: sentFiatValue.toFixed(2) + amount: receivedFiatValue.toFixed(2) }} />} , diff --git a/src/features/Dashboard/components/helpers.test.ts b/src/features/Dashboard/components/helpers.test.ts index c56b44d917f..fe5bc3244c6 100644 --- a/src/features/Dashboard/components/helpers.test.ts +++ b/src/features/Dashboard/components/helpers.test.ts @@ -12,14 +12,14 @@ describe('constructTxTypeConfig', () => { const expectedLabel = translateRaw('RECENT_TX_LIST_LABEL_CONTRACT_INTERACT', { $ticker: fAssets[0].ticker }); - expect(result.label(fAssets[0])).toEqual(expectedLabel); + expect(result.label(fAssets[0].ticker)).toEqual(expectedLabel); }); test('correctly handles action to determine derived tx label', () => { const type = 'EXCHANGE'; const protocol = 'UNISWAP_V1'; const result = constructTxTypeConfig({ type, protocol }); const expectedLabel = 'Uniswap v1: Assets Swapped'; - expect(result.label(fAssets[0])).toBe(expectedLabel); + expect(result.label(fAssets[0].ticker)).toBe(expectedLabel); }); test('correctly handles action to determine icon type', () => { diff --git a/src/features/Dashboard/components/helpers.ts b/src/features/Dashboard/components/helpers.ts index e83281cdec3..9ac8d0d96b2 100644 --- a/src/features/Dashboard/components/helpers.ts +++ b/src/features/Dashboard/components/helpers.ts @@ -8,47 +8,47 @@ import outbound from '@assets/images/transactions/outbound.svg'; import swap from '@assets/images/transactions/swap.svg'; import transfer from '@assets/images/transactions/transfer.svg'; import { translateRaw } from '@translations'; -import { Asset, ITxTypeMeta } from '@types'; +import { ITxTypeMeta } from '@types'; import { ITxHistoryType } from '../types'; import { ITxTypeConfigObj } from './RecentTransactionList'; export const constructTxTypeConfig = ({ type, protocol }: ITxTypeMeta): ITxTypeConfigObj => ({ - label: (asset: Asset) => { + label: (assetTxTypeDesignation: string) => { switch (type) { default: return protocol ? translateRaw('RECENT_TX_LIST_PLATFORM_INTERACTION', { - $platform: translateRaw(protocol, { $ticker: asset.ticker }), - $action: translateRaw(`PLATFORM_${type}`, { $ticker: asset.ticker }) + $platform: translateRaw(protocol, { $ticker: assetTxTypeDesignation }), + $action: translateRaw(`PLATFORM_${type}`, { $ticker: assetTxTypeDesignation }) }) - : translateRaw(`PLATFORM_${type}`, { $ticker: asset.ticker }); + : translateRaw(`PLATFORM_${type}`, { $ticker: assetTxTypeDesignation }); case 'GENERIC_CONTRACT_CALL' as ITxHistoryType: case ITxHistoryType.CONTRACT_INTERACT: return translateRaw('RECENT_TX_LIST_LABEL_CONTRACT_INTERACT', { - $ticker: asset.ticker || translateRaw('UNKNOWN') + $ticker: assetTxTypeDesignation || translateRaw('UNKNOWN') }); case ITxHistoryType.INBOUND: return translateRaw('RECENT_TX_LIST_LABEL_RECEIVED', { - $ticker: asset.ticker || translateRaw('UNKNOWN') + $ticker: assetTxTypeDesignation || translateRaw('UNKNOWN') }); case ITxHistoryType.OUTBOUND: return translateRaw('RECENT_TX_LIST_LABEL_SENT', { - $ticker: asset.ticker || translateRaw('UNKNOWN') + $ticker: assetTxTypeDesignation || translateRaw('UNKNOWN') }); case ITxHistoryType.TRANSFER: return translateRaw('RECENT_TX_LIST_LABEL_TRANSFERRED', { - $ticker: asset.ticker || translateRaw('UNKNOWN') + $ticker: assetTxTypeDesignation || translateRaw('UNKNOWN') }); case ITxHistoryType.REP_TOKEN_MIGRATION: case ITxHistoryType.GOLEM_TOKEN_MIGRATION: case ITxHistoryType.ANT_TOKEN_MIGRATION: return protocol ? translateRaw('RECENT_TX_LIST_PLATFORM_INTERACTION', { - $platform: translateRaw(protocol, { $ticker: asset.ticker }), - $action: translateRaw(`PLATFORM_MIGRATION`, { $ticker: asset.ticker }) + $platform: translateRaw(protocol, { $ticker: assetTxTypeDesignation }), + $action: translateRaw(`PLATFORM_MIGRATION`, { $ticker: assetTxTypeDesignation }) }) - : translateRaw(`PLATFORM_MIGRATION`, { $ticker: asset.ticker }); + : translateRaw(`PLATFORM_MIGRATION`, { $ticker: assetTxTypeDesignation }); case ITxHistoryType.PURCHASE_MEMBERSHIP: return translateRaw('PLATFORM_MEMBERSHIP_PURCHASED'); } diff --git a/src/translations/lang/en.json b/src/translations/lang/en.json index 67d3b9c5e7f..a98b04dcb79 100644 --- a/src/translations/lang/en.json +++ b/src/translations/lang/en.json @@ -1049,6 +1049,7 @@ "HW_SIGN_ADDRESS_MISMATCH": "This transaction was signed by the incorrect account on your hardware wallet. Please be sure you are connected to $address in order to proceed.", "SELECT_A_MIGRATION": "Select a migration", "TOKEN_MIGRATION_HEADER": "Migrate Tokens", - "TX_DEPLOY_ADDRESS_LABEL": "Transaction deployed the following contract" + "TX_DEPLOY_ADDRESS_LABEL": "Transaction deployed the following contract", + "ASSETS": "Assets" } }