Skip to content

Commit

Permalink
fix: show correct fiat amount in activity
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelae committed Jun 14, 2024
1 parent b3166bb commit 9ba153e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test/e2e/tests/swap-send/swap-send-erc20.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Swap-Send ERC20', function () {
'Send TST as ETH',
'Confirmed',
'-10 TST',
'-$0.00',
'',
);

driver.summarizeErrorsAndExceptions();
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/tests/swap-send/swap-send-eth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 22 additions & 8 deletions ui/hooks/useSwappedTokenValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion ui/hooks/useTransactionDisplayData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions ui/hooks/useTransactionDisplayData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const expectedResults = [
primaryCurrency: '-33.425656732428330864 BAT',
senderAddress: '0x0a985a957b490f4d05bef05bc7ec556dd8535946',
recipientAddress: '0xc6f6ca03d790168758285264bcbf7fb30d27322b',
secondaryCurrency: '-0',
secondaryCurrency: undefined,
isPending: false,
displayedStatusKey: TransactionStatus.confirmed,
},
Expand All @@ -187,7 +187,7 @@ const expectedResults = [
primaryCurrency: '-5 USDC',
senderAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838',
recipientAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838',
secondaryCurrency: '-0',
secondaryCurrency: undefined,
isPending: false,
displayedStatusKey: TransactionStatus.confirmed,
},
Expand All @@ -200,7 +200,7 @@ const expectedResults = [
primaryCurrency: '-0.05 BNB',
senderAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838',
recipientAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838',
secondaryCurrency: '-0.05',
secondaryCurrency: undefined,
isPending: false,
displayedStatusKey: TransactionStatus.confirmed,
},
Expand Down

0 comments on commit 9ba153e

Please sign in to comment.