Skip to content

Commit

Permalink
fix for asset ticker vs sent&received mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
blurpesec committed Jan 6, 2022
1 parent 2318960 commit 224d9ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
38 changes: 18 additions & 20 deletions src/features/Dashboard/components/RecentTransactionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface Props {

export interface ITxTypeConfigObj {
icon(): any;
label(asset: Asset): string;
label(assetTxTypeDesignation: string): string;
}

const SAssetIcon = styled(AssetIcon)`
Expand Down Expand Up @@ -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 = (
<Box mr="16px" position="relative">
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 [
<TransactionLabel
key={0}
image={makeTxIcon(entryConfig, baseAsset)}
label={entryConfig.label(baseAsset)}
image={makeTxIcon(entryConfig, valueTransfers.length == 1 ? valueTransfers[0]?.asset : undefined)}
label={entryConfig.label(valueTransfers.length == 1 ? valueTransfers[0]?.asset.ticker : translateRaw('ASSETS'))}
stage={status}
date={timestamp}
/>,
Expand Down Expand Up @@ -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)
}}
/>}
</Box>,
Expand All @@ -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)
}}
/>}
</Box>,
Expand Down
4 changes: 2 additions & 2 deletions src/features/Dashboard/components/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
24 changes: 12 additions & 12 deletions src/features/Dashboard/components/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
3 changes: 2 additions & 1 deletion src/translations/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@
"SIGN_TX_GRIDPLUS_DESCRIPTION": "Follow the on-screen instructions on your GridPlus to sign your transaction.",
"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"
"TOKEN_MIGRATION_HEADER": "Migrate Tokens",
"ASSETS": "Assets"
}
}

0 comments on commit 224d9ad

Please sign in to comment.