Commit fc85dc0
authored
fix: use StackActions.push to navigate to trending token details (#27707)
## **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?
-->
**Problem**
When the user navigates to a token's details page and then opens Swap
from there, the navigation stack looks like:
```
[Home → Asset(TokenA) → Bridge]
```
Tapping a trending token inside the Swap/Bridge screen calls
`navigation.navigate('Asset', tokenBParams)`. React Navigation's
`navigate` traverses the stack looking for an existing matching route —
it finds the already-present `Asset(TokenA)` screen and navigates
**back** to it, dismissing the Bridge screen. The user ends up on the
original token's details page instead of the tapped trending token's
details page.
**Fix**
Replace `navigation.navigate('Asset', ...)` with
`navigation.dispatch(StackActions.push('Asset', ...))` in
`TrendingTokenRowItem`. `StackActions.push` always creates a **new**
screen instance regardless of what is already on the stack, so the
navigation flows correctly forward to the tapped token. When `push` is
dispatched from a nested navigator that does not register `'Asset'`
(e.g. `BridgeScreenStack` or `ExploreHome`), React Navigation bubbles
the action up to the root modal stack which does register it — matching
the behaviour already used in `BridgeTokenSelector` for the same reason.
Tests are updated to assert that `navigation.dispatch` is called with
the correct `StackActions.push` action and that `navigation.navigate` is
no longer called.
## **Changelog**
CHANGELOG entry: Fixed tapping a trending token from the Swap screen
dismissing Swap instead of opening the token details page
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/SWAPS-4271
## **Manual testing steps**
```gherkin
Feature: Trending token navigation from Swap screen
Background:
Given I am logged into MetaMask Mobile
And I have at least one token in my wallet
Scenario: user navigates to a trending token from Swap opened via token details page
Given I am on a token details page (e.g. mUSD)
And I can see the "Swap" action button
When user taps "Swap"
Then the Swap screen opens
And I can see a list of trending tokens
When user taps on a trending token (e.g. Sigma)
Then the Sigma token details page opens
And the Swap screen is no longer visible
Scenario: user navigates to a trending token from Swap opened directly (not from token details)
Given I am on the Wallet home screen
When user opens the Swap screen directly
And user taps on a trending token (e.g. Everlyn Token)
Then the Everlyn Token details page opens
Scenario: user navigates to a trending token from the Explore tab
Given I am on the Explore tab
When user taps on a trending token
Then the token details page for that token opens
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
Tapping a trending token from Swap (opened via token details page)
dismisses Swap and returns to the original token details page.
### **After**
Tapping a trending token from Swap navigates forward to the tapped
token's details page.
## **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.
<!-- Generated with the help of the pr-description AI skill -->
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes navigation behavior for trending token taps by forcing a new
`Asset` screen onto the stack; risk is mainly UX/regression if the
action doesn’t bubble correctly in some navigators.
>
> **Overview**
> Fixes trending-token taps to **always open a new token details
screen** by replacing `navigation.navigate('Asset', ...)` with
`navigation.dispatch(StackActions.push('Asset', ...))` in
`TrendingTokenRowItem`.
>
> Updates `TrendingTokenRowItem` tests to mock `dispatch` and assert
`StackActions.push` is used (and `navigate` is not), including cases
where a popular network must be added first or navigation is suppressed
on failure.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e2f50ab. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 4d25a94 commit fc85dc0
2 files changed
Lines changed: 104 additions & 80 deletions
File tree
- app/components/UI/Trending/components/TrendingTokenRowItem
Lines changed: 99 additions & 78 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| |||
798 | 801 | | |
799 | 802 | | |
800 | 803 | | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
816 | 822 | | |
817 | 823 | | |
818 | 824 | | |
| |||
858 | 864 | | |
859 | 865 | | |
860 | 866 | | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
875 | | - | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
876 | 885 | | |
877 | 886 | | |
878 | 887 | | |
| |||
918 | 927 | | |
919 | 928 | | |
920 | 929 | | |
921 | | - | |
922 | | - | |
923 | | - | |
924 | | - | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
934 | | - | |
935 | | - | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
936 | 948 | | |
937 | 949 | | |
938 | 950 | | |
| |||
995 | 1007 | | |
996 | 1008 | | |
997 | 1009 | | |
998 | | - | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
999 | 1014 | | |
1000 | 1015 | | |
1001 | 1016 | | |
| |||
1054 | 1069 | | |
1055 | 1070 | | |
1056 | 1071 | | |
1057 | | - | |
| 1072 | + | |
1058 | 1073 | | |
1059 | 1074 | | |
1060 | 1075 | | |
| |||
1077 | 1092 | | |
1078 | 1093 | | |
1079 | 1094 | | |
1080 | | - | |
| 1095 | + | |
1081 | 1096 | | |
1082 | 1097 | | |
1083 | 1098 | | |
| |||
1128 | 1143 | | |
1129 | 1144 | | |
1130 | 1145 | | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
1146 | 1164 | | |
1147 | 1165 | | |
1148 | 1166 | | |
| |||
1194 | 1212 | | |
1195 | 1213 | | |
1196 | 1214 | | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
1200 | | - | |
1201 | | - | |
1202 | | - | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
1206 | | - | |
1207 | | - | |
1208 | | - | |
1209 | | - | |
1210 | | - | |
1211 | | - | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
1212 | 1233 | | |
1213 | 1234 | | |
1214 | 1235 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
253 | 256 | | |
254 | 257 | | |
255 | 258 | | |
| |||
0 commit comments