Skip to content

Commit ff8604f

Browse files
authored
chore(runway): cherry-pick fix: fix default swap destination token when source is USDC (#15627)
- fix: cp-7.47.0 fix default swap destination token when source is USDC (#15611) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** General default destination token for swaps is USDC, but if the source token is USDC then the destination should be the network's native gas token. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to Solana account 2. Select USDC from balances page 3. Click "Swap" button within asset page 4. See SOL is default destination token ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. [0f97c52](0f97c52)
2 parents 51a1de3 + a8924ca commit ff8604f

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737

3838
### Fixed
3939

40+
- fix(bridge): fix default swap destination token when source is USDC ([#15611](https://github.com/MetaMask/metamask-mobile/pull/15611))
4041
- fix(multi-srp): display multichain accounts in SRP list ([#14724](https://github.com/MetaMask/metamask-mobile/pull/14724))
4142
- fix(confirmations): remove transaction simulations from wallet initiated send flow ([#14994](https://github.com/MetaMask/metamask-mobile/pull/14994))
4243
- fix(bridge): add auto slippage option and improve slippage selection UI ([#15159](https://github.com/MetaMask/metamask-mobile/pull/15159))

app/components/UI/Bridge/hooks/useInitialDestToken/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { selectChainId } from '../../../../../selectors/networkController';
55
import { RouteProp, useRoute } from '@react-navigation/native';
66
import { BridgeRouteParams } from '../../Views/BridgeView';
77
import { BridgeViewMode, BridgeToken } from '../../types';
8+
import { getNativeSourceToken } from '../useInitialSourceToken';
89

910
// Need to pass in the initial source token to avoid a race condition with useInitialSourceToken
1011
// Can't just use selectSourceToken because of race condition
@@ -18,7 +19,13 @@ export const useInitialDestToken = (initialSourceToken?: BridgeToken) => {
1819

1920
if (destToken) return;
2021

21-
const defaultDestToken = DefaultSwapDestTokens[chainId];
22+
let defaultDestToken = DefaultSwapDestTokens[chainId];
23+
24+
// If the initial source token is the same as the default dest token, set the default dest token to the native token
25+
if (initialSourceToken?.address === defaultDestToken?.address) {
26+
defaultDestToken = getNativeSourceToken(chainId);
27+
}
28+
2229
if (
2330
isSwap &&
2431
defaultDestToken &&

app/components/UI/Bridge/hooks/useInitialDestToken/useInitialDestToken.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ jest.mock('../../../../../selectors/networkController', () => {
3333
};
3434
});
3535

36+
jest.mock('../useInitialSourceToken', () => ({
37+
getNativeSourceToken: jest.fn().mockReturnValue({
38+
address: '0x456',
39+
symbol: 'NATIVE',
40+
decimals: 18,
41+
name: 'Native Token',
42+
chainId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
43+
}),
44+
}));
45+
3646
describe('useInitialDestToken', () => {
3747
const mockSourceToken: BridgeToken = {
3848
address: '0x123',
@@ -109,6 +119,12 @@ describe('useInitialDestToken', () => {
109119
state: initialState,
110120
});
111121

112-
expect(setDestToken).not.toHaveBeenCalled();
122+
expect(setDestToken).toHaveBeenCalledWith({
123+
address: '0x456',
124+
symbol: 'NATIVE',
125+
decimals: 18,
126+
name: 'Native Token',
127+
chainId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
128+
});
113129
});
114130
});

0 commit comments

Comments
 (0)