Skip to content

Commit 3b0d0fa

Browse files
authored
fix: cp-7.54.0 use navigation.dispatch to properly navigate to asset page (MetaMask#18461)
<!-- 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** The 'i' button in the asset row behaves inconsistently depending on the entry point: - When accessed from the main action menu, it works as expected. - When accessed from the token details page, it does not work. This PR fixes this issue by replacing `navigation.navigate` with `navigation.dispatch`, which allows the new asset overlay to properly render as new instead of returning to the previous asset. <!-- 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? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: fixed asset page navigation from bridge Scenario: user clicks "i" icon from bridge destination token selector Given in swap page accessed from asset page When user clicks "i" icon Then asset page opens for that asset ``` ## **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** - [ ] 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). - [ ] 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 - [ ] 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 f729a9e commit 3b0d0fa

2 files changed

Lines changed: 31 additions & 14 deletions

File tree

app/components/UI/Bridge/components/BridgeDestTokenSelector/BridgeDestTokenSelector.test.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import { BridgeViewMode } from '../../types';
1515

1616
const mockNavigate = jest.fn();
1717
const mockGoBack = jest.fn();
18+
const mockDispatch = jest.fn();
1819

1920
jest.mock('@react-navigation/native', () => ({
2021
...jest.requireActual('@react-navigation/native'),
2122
useNavigation: () => ({
2223
navigate: mockNavigate,
2324
goBack: mockGoBack,
25+
dispatch: mockDispatch,
2426
}),
2527
}));
2628

@@ -164,19 +166,25 @@ describe('BridgeDestTokenSelector', () => {
164166
// Press the info button
165167
fireEvent.press(infoButton);
166168

167-
// Verify navigation to Asset screen with the correct token params
168-
expect(mockNavigate).toHaveBeenCalledWith(
169-
'Asset',
169+
// Verify navigation to Asset screen with the correct token params via dispatch
170+
expect(mockDispatch).toHaveBeenCalledWith(
170171
expect.objectContaining({
171-
address: ethToken2Address,
172-
balance: '2.0',
173-
balanceFiat: '$200000',
174-
chainId: '0x1',
175-
decimals: 18,
176-
image: 'https://token2.com/logo.png',
177-
name: 'Hello Token',
178-
symbol: 'HELLO',
179-
tokenFiatAmount: 200000,
172+
type: 'NAVIGATE',
173+
payload: expect.objectContaining({
174+
name: 'Asset',
175+
key: expect.stringMatching(/^Asset-.*-\d+$/), // Should match pattern "Asset-{address}-{chainId}-{timestamp}"
176+
params: expect.objectContaining({
177+
address: ethToken2Address,
178+
balance: '2.0',
179+
balanceFiat: '$200000',
180+
chainId: '0x1',
181+
decimals: 18,
182+
image: 'https://token2.com/logo.png',
183+
name: 'Hello Token',
184+
symbol: 'HELLO',
185+
tokenFiatAmount: 200000,
186+
}),
187+
}),
180188
}),
181189
);
182190
});

app/components/UI/Bridge/components/BridgeDestTokenSelector/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,17 @@ export const BridgeDestTokenSelector: React.FC = () => {
6868
}
6969

7070
// Open the asset details screen as a bottom sheet
71-
const handleInfoButtonPress = () =>
72-
navigation.navigate('Asset', { ...item });
71+
// Use dispatch with unique key to force new modal instance
72+
const handleInfoButtonPress = () => {
73+
navigation.dispatch({
74+
type: 'NAVIGATE',
75+
payload: {
76+
name: 'Asset',
77+
key: `Asset-${item.address}-${item.chainId}-${Date.now()}`,
78+
params: { ...item },
79+
},
80+
});
81+
};
7382

7483
// If the user hasn't added the network, it won't be in the networkConfigurations object
7584
// So we use the PopularList to get the network name

0 commit comments

Comments
 (0)