From 9ba153e7e7ad28ddf0801c2a2485bd3e3fe8942b Mon Sep 17 00:00:00 2001 From: Micaela Estabillo Date: Thu, 13 Jun 2024 17:15:22 -0600 Subject: [PATCH] fix: show correct fiat amount in activity --- .../tests/swap-send/swap-send-erc20.spec.ts | 2 +- .../e2e/tests/swap-send/swap-send-eth.spec.ts | 6 ++-- ui/hooks/useSwappedTokenValue.js | 30 ++++++++++++++----- ui/hooks/useTransactionDisplayData.js | 3 +- ui/hooks/useTransactionDisplayData.test.js | 6 ++-- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/test/e2e/tests/swap-send/swap-send-erc20.spec.ts b/test/e2e/tests/swap-send/swap-send-erc20.spec.ts index 7b58ef728a5b..10b18592f42b 100644 --- a/test/e2e/tests/swap-send/swap-send-erc20.spec.ts +++ b/test/e2e/tests/swap-send/swap-send-erc20.spec.ts @@ -105,7 +105,7 @@ describe('Swap-Send ERC20', function () { 'Send TST as ETH', 'Confirmed', '-10 TST', - '-$0.00', + '', ); driver.summarizeErrorsAndExceptions(); diff --git a/test/e2e/tests/swap-send/swap-send-eth.spec.ts b/test/e2e/tests/swap-send/swap-send-eth.spec.ts index 4622a2000e24..244693d513a2 100644 --- a/test/e2e/tests/swap-send/swap-send-eth.spec.ts +++ b/test/e2e/tests/swap-send/swap-send-eth.spec.ts @@ -71,18 +71,20 @@ describe('Swap-Send ETH', function () { '≈ $38.84', ); + // TODO assert swap api request payload + await swapSendPage.submitSwap(); await swapSendPage.verifyHistoryEntry( 'Send ETH as TST', 'Pending', '-1 ETH', - '-$3,010.00', + '', ); await swapSendPage.verifyHistoryEntry( 'Send ETH as TST', 'Confirmed', '-1 ETH', - '-$3,010.00', + '', ); driver.summarizeErrorsAndExceptions(); diff --git a/ui/hooks/useSwappedTokenValue.js b/ui/hooks/useSwappedTokenValue.js index 5171d3c86822..c7007346d7c0 100644 --- a/ui/hooks/useSwappedTokenValue.js +++ b/ui/hooks/useSwappedTokenValue.js @@ -37,12 +37,13 @@ export function useSwappedTokenValue(transactionGroup, currentAsset) { const chainId = useSelector(getCurrentChainId); const isViewingReceivedTokenFromSwap = - currentAsset?.symbol === primaryTransaction.destinationTokenSymbol || - (isSwapsDefaultTokenAddress(currentAsset.address, chainId) && - isSwapsDefaultTokenSymbol( - primaryTransaction.destinationTokenSymbol, - chainId, - )); + type === TransactionType.swap && + (currentAsset?.symbol === primaryTransaction.destinationTokenSymbol || + (isSwapsDefaultTokenAddress(currentAsset.address, chainId) && + isSwapsDefaultTokenSymbol( + primaryTransaction.destinationTokenSymbol, + chainId, + ))); const swapTokenValue = [TransactionType.swap].includes(type) && isViewingReceivedTokenFromSwap @@ -68,8 +69,21 @@ export function useSwappedTokenValue(transactionGroup, currentAsset) { swapTokenValue || '', symbol, ); - const swapTokenFiatAmount = - swapTokenValue && isViewingReceivedTokenFromSwap && _swapTokenFiatAmount; + const _swapAndSendTokenFiatAmount = useTokenFiatAmount( + primaryTransaction.sourceTokenAddress, + swapTokenValue, + primaryTransaction.sourceTokenSymbol, + ); + + let swapTokenFiatAmount; + if (swapTokenValue) { + if (isViewingReceivedTokenFromSwap) { + swapTokenFiatAmount = _swapTokenFiatAmount; + } else if (type === TransactionType.swapAndSend) { + swapTokenFiatAmount = _swapAndSendTokenFiatAmount; + } + } + return { swapTokenValue, swapTokenFiatAmount, diff --git a/ui/hooks/useTransactionDisplayData.js b/ui/hooks/useTransactionDisplayData.js index 019a9ec13fa2..4b551b318b62 100644 --- a/ui/hooks/useTransactionDisplayData.js +++ b/ui/hooks/useTransactionDisplayData.js @@ -394,7 +394,8 @@ export function useTransactionDisplayData(transactionGroup) { recipientAddress, secondaryCurrency: (isTokenCategory && !tokenFiatAmount) || - (type === TransactionType.swap && !swapTokenFiatAmount) + ([TransactionType.swap, TransactionType.swapAndSend].includes(type) && + !swapTokenFiatAmount) ? undefined : secondaryCurrency, displayedStatusKey, diff --git a/ui/hooks/useTransactionDisplayData.test.js b/ui/hooks/useTransactionDisplayData.test.js index 7ec7bbe41f13..5008e9898d24 100644 --- a/ui/hooks/useTransactionDisplayData.test.js +++ b/ui/hooks/useTransactionDisplayData.test.js @@ -174,7 +174,7 @@ const expectedResults = [ primaryCurrency: '-33.425656732428330864 BAT', senderAddress: '0x0a985a957b490f4d05bef05bc7ec556dd8535946', recipientAddress: '0xc6f6ca03d790168758285264bcbf7fb30d27322b', - secondaryCurrency: '-0', + secondaryCurrency: undefined, isPending: false, displayedStatusKey: TransactionStatus.confirmed, }, @@ -187,7 +187,7 @@ const expectedResults = [ primaryCurrency: '-5 USDC', senderAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838', recipientAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838', - secondaryCurrency: '-0', + secondaryCurrency: undefined, isPending: false, displayedStatusKey: TransactionStatus.confirmed, }, @@ -200,7 +200,7 @@ const expectedResults = [ primaryCurrency: '-0.05 BNB', senderAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838', recipientAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838', - secondaryCurrency: '-0.05', + secondaryCurrency: undefined, isPending: false, displayedStatusKey: TransactionStatus.confirmed, },