Skip to content

Commit 624763a

Browse files
authored
fix: swap+send bugs in Version v12.0.0 release (#25307)
1 parent 8b764fa commit 624763a

File tree

10 files changed

+1468
-23
lines changed

10 files changed

+1468
-23
lines changed

test/data/transaction-data.json

+1,388
Large diffs are not rendered by default.

test/e2e/tests/swap-send/swap-send-erc20.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Swap-Send ERC20', function () {
2121
getSwapSendFixtures(
2222
this.test?.fullTitle(),
2323
SWAP_SEND_QUOTES_RESPONSE_TST_ETH,
24+
'?sourceAmount=100000&sourceToken=0x581c3C1A2A4EBDE2A0Df29B5cf4c116E42945947&destinationToken=0x0000000000000000000000000000000000000000&sender=0x5cfe73b6021e818b776b421b1c4db2474086a7e1&recipient=0xc427D562164062a23a5cFf596A4a3208e72Acd28&slippage=2',
2425
),
2526
async ({
2627
driver,
@@ -104,7 +105,7 @@ describe('Swap-Send ERC20', function () {
104105
'Send TST as ETH',
105106
'Confirmed',
106107
'-10 TST',
107-
'-$0.00',
108+
'',
108109
);
109110

110111
driver.summarizeErrorsAndExceptions();

test/e2e/tests/swap-send/swap-send-eth.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,20 @@ describe('Swap-Send ETH', function () {
7171
'≈ $38.84',
7272
);
7373

74+
// TODO assert swap api request payload
75+
7476
await swapSendPage.submitSwap();
7577
await swapSendPage.verifyHistoryEntry(
7678
'Send ETH as TST',
7779
'Pending',
7880
'-1 ETH',
79-
'-$3,010.00',
81+
'',
8082
);
8183
await swapSendPage.verifyHistoryEntry(
8284
'Send ETH as TST',
8385
'Confirmed',
8486
'-1 ETH',
85-
'-$3,010.00',
87+
'',
8688
);
8789

8890
driver.summarizeErrorsAndExceptions();

test/e2e/tests/swap-send/swap-send-test-utils.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,11 @@ export class SwapSendPage {
245245
}
246246

247247
export const mockSwapsApi =
248-
(quotes = SWAP_SEND_QUOTES_RESPONSE_ETH_TST) =>
248+
(quotes: typeof SWAP_SEND_QUOTES_RESPONSE_ETH_TST, query: string) =>
249249
async (mockServer: Mockttp) => {
250-
return await mockServer
250+
await mockServer
251251
.forGet(`${SWAPS_API_V2_BASE_URL}/v2/networks/1337/quotes`)
252+
.withExactQuery(query)
252253
.always()
253254
.thenCallback(() => {
254255
return {
@@ -261,6 +262,7 @@ export const mockSwapsApi =
261262
export const getSwapSendFixtures = (
262263
title?: string,
263264
swapsQuotes = SWAP_SEND_QUOTES_RESPONSE_ETH_TST,
265+
swapsQuery = '?sourceAmount=1000000000000000000&sourceToken=0x0000000000000000000000000000000000000000&destinationToken=0x581c3C1A2A4EBDE2A0Df29B5cf4c116E42945947&sender=0x5cfe73b6021e818b776b421b1c4db2474086a7e1&recipient=0xc427D562164062a23a5cFf596A4a3208e72Acd28&slippage=2',
264266
) => {
265267
const ETH_CONVERSION_RATE_USD = 3010;
266268
return {
@@ -296,7 +298,7 @@ export const getSwapSendFixtures = (
296298
.build(),
297299
smartContract: SMART_CONTRACTS.HST,
298300
ethConversionInUsd: ETH_CONVERSION_RATE_USD,
299-
testSpecificMock: mockSwapsApi(swapsQuotes),
301+
testSpecificMock: mockSwapsApi(swapsQuotes, swapsQuery),
300302
ganacheOptions: generateGanacheOptions({ hardfork: 'london' }),
301303
title,
302304
};

ui/components/multichain/asset-picker-amount/index.scss

+10-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
.unit-input__inputs {
3737
// primary (i.e., input) and secondary (i.e., subtext) input sections
3838
& > div {
39-
max-width: 125px;
39+
max-width: 138px;
4040
white-space: nowrap;
4141
text-overflow: ellipsis;
4242
}
@@ -51,7 +51,15 @@
5151

5252
text-overflow: ellipsis;
5353
overflow: hidden;
54-
display: inline;
54+
flex-wrap: nowrap;
55+
56+
& > span.currency-display-component__text {
57+
width: max-content;
58+
}
59+
60+
& > span.currency-display-component__suffix {
61+
width: max-content;
62+
}
5563
}
5664

5765
// secondary field elements (e.g., value, symbols)

ui/components/multichain/pages/send/components/recipient-content.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
getUseExternalServices,
2626
} from '../../../../../selectors';
2727
import type { Quote } from '../../../../../ducks/send/swap-and-send-utils';
28+
import { isEqualCaseInsensitive } from '../../../../../../shared/modules/string-utils';
2829
import { SendHexData, SendPageRow, QuoteCard } from '.';
2930

3031
export const SendPageRecipientContent = ({
@@ -59,8 +60,10 @@ export const SendPageRecipientContent = ({
5960

6061
const isLoadingInitialQuotes = !bestQuote && isSwapQuoteLoading;
6162

62-
const isBasicSend =
63-
receiveAsset.details?.address === sendAsset.details?.address;
63+
const isBasicSend = isEqualCaseInsensitive(
64+
receiveAsset.details?.address ?? '',
65+
sendAsset.details?.address ?? '',
66+
);
6467

6568
const amount = isBasicSend
6669
? sendAmount

ui/components/ui/unit-input/unit-input.component.js

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export default class UnitInput extends PureComponent {
9595
}
9696

9797
this.props.onBlur && this.props.onBlur(value);
98+
this.unitInput.scrollTo && this.unitInput.scrollTo(0, 0);
9899
};
99100

100101
handleChange = (event) => {

ui/hooks/useSwappedTokenValue.js

+23-10
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ export function useSwappedTokenValue(transactionGroup, currentAsset) {
3737
const chainId = useSelector(getCurrentChainId);
3838

3939
const isViewingReceivedTokenFromSwap =
40-
currentAsset?.symbol === primaryTransaction.destinationTokenSymbol ||
41-
(isSwapsDefaultTokenAddress(currentAsset.address, chainId) &&
42-
isSwapsDefaultTokenSymbol(
43-
primaryTransaction.destinationTokenSymbol,
44-
chainId,
45-
));
40+
type === TransactionType.swap &&
41+
(currentAsset?.symbol === primaryTransaction.destinationTokenSymbol ||
42+
(isSwapsDefaultTokenAddress(currentAsset.address, chainId) &&
43+
isSwapsDefaultTokenSymbol(
44+
primaryTransaction.destinationTokenSymbol,
45+
chainId,
46+
)));
4647

4748
const swapTokenValue =
48-
[TransactionType.swap, TransactionType.swapAndSend].includes(type) &&
49-
isViewingReceivedTokenFromSwap
49+
[TransactionType.swap].includes(type) && isViewingReceivedTokenFromSwap
5050
? getSwapsTokensReceivedFromTxMeta(
5151
primaryTransaction.destinationTokenSymbol,
5252
initialTransaction,
@@ -69,8 +69,21 @@ export function useSwappedTokenValue(transactionGroup, currentAsset) {
6969
swapTokenValue || '',
7070
symbol,
7171
);
72-
const swapTokenFiatAmount =
73-
swapTokenValue && isViewingReceivedTokenFromSwap && _swapTokenFiatAmount;
72+
const _swapAndSendTokenFiatAmount = useTokenFiatAmount(
73+
primaryTransaction.sourceTokenAddress,
74+
swapTokenValue,
75+
primaryTransaction.sourceTokenSymbol,
76+
);
77+
78+
let swapTokenFiatAmount;
79+
if (swapTokenValue) {
80+
if (isViewingReceivedTokenFromSwap) {
81+
swapTokenFiatAmount = _swapTokenFiatAmount;
82+
} else if (type === TransactionType.swapAndSend) {
83+
swapTokenFiatAmount = _swapAndSendTokenFiatAmount;
84+
}
85+
}
86+
7487
return {
7588
swapTokenValue,
7689
swapTokenFiatAmount,

ui/hooks/useTransactionDisplayData.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ export function useTransactionDisplayData(transactionGroup) {
394394
recipientAddress,
395395
secondaryCurrency:
396396
(isTokenCategory && !tokenFiatAmount) ||
397-
(type === TransactionType.swap && !swapTokenFiatAmount)
397+
([TransactionType.swap, TransactionType.swapAndSend].includes(type) &&
398+
!swapTokenFiatAmount)
398399
? undefined
399400
: secondaryCurrency,
400401
displayedStatusKey,

ui/hooks/useTransactionDisplayData.test.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,36 @@ const expectedResults = [
171171
subtitle: 'metamask',
172172
subtitleContainsOrigin: true,
173173
date: formatDateWithYearContext(1585088013000),
174-
primaryCurrency: '-0 BAT',
174+
primaryCurrency: '-33.425656732428330864 BAT',
175175
senderAddress: '0x0a985a957b490f4d05bef05bc7ec556dd8535946',
176176
recipientAddress: '0xc6f6ca03d790168758285264bcbf7fb30d27322b',
177-
secondaryCurrency: '-0 ETH',
177+
secondaryCurrency: undefined,
178+
isPending: false,
179+
displayedStatusKey: TransactionStatus.confirmed,
180+
},
181+
{
182+
title: 'Send USDC as DAI',
183+
category: TransactionType.swapAndSend,
184+
subtitle: 'metamask',
185+
subtitleContainsOrigin: true,
186+
date: formatDateWithYearContext(1585088013000),
187+
primaryCurrency: '-5 USDC',
188+
senderAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838',
189+
recipientAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838',
190+
secondaryCurrency: undefined,
191+
isPending: false,
192+
displayedStatusKey: TransactionStatus.confirmed,
193+
},
194+
{
195+
title: 'Send BNB as USDC',
196+
category: TransactionType.swapAndSend,
197+
subtitle: 'metamask',
198+
subtitleContainsOrigin: true,
199+
date: formatDateWithYearContext(1585088013000),
200+
primaryCurrency: '-0.05 BNB',
201+
senderAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838',
202+
recipientAddress: '0x141d32a89a1e0a5ef360034a2f60a4b917c18838',
203+
secondaryCurrency: undefined,
178204
isPending: false,
179205
displayedStatusKey: TransactionStatus.confirmed,
180206
},

0 commit comments

Comments
 (0)