Skip to content

Commit 8bcaa40

Browse files
fix: not switching networks when selecting source token (#14712)
<!-- 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** <!-- 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? --> Fixes an issue where Bridge would not switch networks when selecting a source token with a different network properly. ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to Bridge 2. Select a source token from a different chain than your current chain 3. Should switch networks and set source token properly. ## **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 - [ ] I’ve included tests if applicable - [ ] 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.
1 parent 71b9084 commit 8bcaa40

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727

2828
- feat(bridge): Handle Solana vs EVM swap and bridge routing ([#14614](https://github.com/MetaMask/metamask-mobile/pull/14614))
2929

30+
### Fixed
31+
32+
- fix(bridge): fix not switching networks when selecting source token ([#14712](https://github.com/MetaMask/metamask-mobile/pull/14712))
33+
3034
## [7.44.0]
3135

3236
### Added

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRoute, RouteProp } from '@react-navigation/native';
22
import { setSourceToken } from '../../../../../core/redux/slices/bridge';
33
import { useDispatch, useSelector } from 'react-redux';
4-
import { useEffect } from 'react';
4+
import { useEffect, useRef } from 'react';
55
import { BridgeToken, BridgeViewMode } from '../../types';
66
import { selectEvmNetworkConfigurationsByChainId } from '../../../../../selectors/networkController';
77
import { useSwitchNetworks } from '../../../../Views/NetworkSelector/useSwitchNetworks';
@@ -40,6 +40,7 @@ export const useInitialSourceToken = () => {
4040
const evmNetworkConfigurations = useSelector(
4141
selectEvmNetworkConfigurationsByChainId,
4242
);
43+
const hasSetInitialSourceToken = useRef(false);
4344

4445
const {
4546
chainId: selectedChainId,
@@ -60,6 +61,8 @@ export const useInitialSourceToken = () => {
6061
const initialSourceToken = route.params?.token;
6162

6263
useEffect(() => {
64+
if (hasSetInitialSourceToken.current) return;
65+
6366
// Will default to the native token of the current chain if no token is provided
6467
if (!initialSourceToken) {
6568
dispatch(setSourceToken(getNativeSourceToken(selectedChainId)));
@@ -90,6 +93,8 @@ export const useInitialSourceToken = () => {
9093
evmNetworkConfigurations[initialSourceToken.chainId as Hex],
9194
);
9295
}
96+
97+
hasSetInitialSourceToken.current = true;
9398
}, [
9499
dispatch,
95100
initialSourceToken,

0 commit comments

Comments
 (0)