Repository navigation
Commit 414c75f
authored
fix(swaps): stay in swaps after transaction submission (#47591)
<!--
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**
After submitting any swap or bridge, users were sent back to the Home
page. They now stay in Swaps, with the token pair kept and the amount
cleared so the submitted quote can't be resubmitted.
Each submit path is handled where it happens:
- **Software wallets** (`useSubmitBridgeTransaction`): there's no
navigation. On success the amount is cleared and the user stays on the
Swaps page. A failed submit leaves the page and amount untouched.
- **Hardware wallets** (`useHwSwapNavigation`): the signing page is
opened on top of Swaps. After signing, the hook clears the amount,
resets the bridge controller and goes back one history entry. The reset
must happen before going back, because the remounted Swaps page restores
the amount from the controller's active quote. The token pair is
unaffected, since it lives in the Redux bridge slice rather than the
controller.
Transaction Shield:
- Swaps opened from Transaction Shield return to Transaction Shield
after submitting, for both software and hardware wallets.
- This is a fix for hardware wallets. On `main` they went Home, because
the signing page's URL dropped the `isFromTransactionShield` param.
`navigateToHwSigningPage` now carries that param over, so post-signing
navigation returns to Shield.
Unchanged behaviour:
- Hardware wallet sends (`sendBundle`) still go Home.
- If the hardware wallet signing page is the first history entry, it
falls back to Home as before.
- Post-trade toasts (EVM and Solana) are unaffected.
Analytics side effect:
- No metrics code changed, but which `Input Changed` events fire changes
for users who leave Swaps with Back after submitting. Back resets the
bridge controller, which it always has. When Swaps is reopened, the
source token is already the default (native), so a `chain_source` event
fires instead of `token_source`. The e2e expectation in
`test/e2e/tests/bridge/constants.ts` (`resetPage`) is updated to match.
Test changes:
- Unit tests for both hooks now expect users to stay in Swaps and check
that the amount is cleared. They also cover: hardware wallet sends going
Home; Transaction Shield returns for both software and hardware wallets;
a failed submit keeping the amount; and the hardware wallet controller
reset happening before navigating back.
- The swap and bridge e2e tests assumed users land on Home after
submitting. A new `goBackAfterSubmit()` page-object step waits for the
amount to clear, which confirms the new behaviour, then presses Back to
reach Home before the Activity checks. It is called from the shared
`verifySubmittedSwapTransaction` flow and from the specs that submit
directly: gasless, bridge failure cases, BTC, Solana, smart transactions
and Ledger. The "View activity" clicks and `clickViewActivity` were
removed because that status page is no longer shown.
## **Changelog**
CHANGELOG entry: Users now stay on the Swaps page after submitting a
swap or bridge, instead of being sent to the Home page
## **Related issues**
Fixes:
[SWAPS-5212](https://consensyssoftware.atlassian.net/browse/SWAPS-5212)
## **Manual testing steps**
1. Run the extension and open the popup.
2. Start a swap on an EVM network (e.g. Mainnet or Linea), enter an
amount, and submit.
3. Verify you stay on the Swaps page, the same token pair is selected,
and the amount is empty.
4. Verify the "Transaction submitted" toast appears and changes to
"Transaction confirmed".
5. Press Back and verify you leave Swaps (no duplicate Swaps entry).
6. Repeat steps 2–5 with a Solana swap.
7. Repeat steps 2–5 with a Ledger account, signing on the device.
8. With the Ledger account, send a token and verify you land on the Home
page after signing.
9. Open Swaps from Transaction Shield, submit a swap, and verify you are
returned to Transaction Shield.
10. Repeat step 9 with the Ledger account and verify you are returned to
Transaction Shield after signing.
<!--
## **Screenshots/Recordings**
### **Before**
### **After**
-->
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/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
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/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.
[SWAPS-5212]:
https://consensyssoftware.atlassian.net/browse/SWAPS-5212?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches core swap submission navigation for software and hardware
wallets plus Transaction Shield routing, so regressions could strand
users on wrong screens; mitigated by broad unit/e2e updates but still
warrants careful QA.
>
> **Overview**
> **Navigation + submission flow tweaks**
> - Software swap/bridge submissions now avoid bouncing to Home unless
the flow originated from Transaction Shield; successful submits stay on
Swaps while clearing the source amount, failed submits leave the page
untouched, and Transaction Shield launches still replace-route back to
Shield.
> - `navigateToHwSigningPage` threads the `isFromTransactionShield`
query param through hardware wallet signing URLs, and hardware-wallet
post-signing navigation differentiates send-bundle, Shield, and standard
histories (resetting the bridge controller or popping history as needed
while clearing amounts).
>
> **Tests & tooling**
> - Page-object helpers add `goBackAfterSubmit` and update bridge/swap
e2e suites (gasless, BTC, Solana, smart transactions, ledger, negative
cases, shared flows) to wait for a cleared amount before backing out,
assert smart-tx toasts, refresh analytics expectations, and drop the
obsolete “View activity” path.
> - Unit tests expand for `useBridgeNavigation`,
`useSubmitBridgeTransaction`, and `useHwSwapNavigation` to cover the new
navigation matrix.
>
> This is a behavior change across swap submission UX and
hardware-wallet routing; mostly covered by updated unit/e2e tests but
regression risk remains if any edge navigation path is missing coverage.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c79cf8d. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 79b3eb9 commit 414c75f
17 files changed
Lines changed: 258 additions & 76 deletions
File tree
- test/e2e
- page-objects
- flows
- pages
- bridge
- swap
- tests
- bridge
- btc
- hardware-wallets/ledger
- smart-transactions
- solana
- ui
- hooks
- bridge
- hardware-wallets
- pages/hardware-wallets/swap/hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
572 | 572 | | |
573 | 573 | | |
574 | 574 | | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
575 | 583 | | |
576 | 584 | | |
577 | 585 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | 150 | | |
156 | 151 | | |
157 | 152 | | |
| |||
267 | 262 | | |
268 | 263 | | |
269 | 264 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | 265 | | |
275 | 266 | | |
276 | 267 | | |
| |||
356 | 347 | | |
357 | 348 | | |
358 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
359 | 354 | | |
360 | 355 | | |
361 | 356 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
| |||
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
| 251 | + | |
250 | 252 | | |
251 | 253 | | |
252 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2961 | 2961 | | |
2962 | 2962 | | |
2963 | 2963 | | |
2964 | | - | |
| 2964 | + | |
2965 | 2965 | | |
2966 | 2966 | | |
2967 | 2967 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
110 | 112 | | |
111 | 113 | | |
112 | 114 | | |
| 115 | + | |
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
| 283 | + | |
283 | 284 | | |
284 | 285 | | |
285 | 286 | | |
| |||
331 | 332 | | |
332 | 333 | | |
333 | 334 | | |
| 335 | + | |
334 | 336 | | |
335 | 337 | | |
336 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
175 | 178 | | |
176 | 179 | | |
177 | 180 | | |
| |||
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
205 | | - | |
| 208 | + | |
206 | 209 | | |
207 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
208 | 214 | | |
209 | 215 | | |
210 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
| 599 | + | |
599 | 600 | | |
600 | 601 | | |
601 | 602 | | |
| |||
645 | 646 | | |
646 | 647 | | |
647 | 648 | | |
| 649 | + | |
648 | 650 | | |
649 | 651 | | |
650 | 652 | | |
| |||
694 | 696 | | |
695 | 697 | | |
696 | 698 | | |
| 699 | + | |
697 | 700 | | |
698 | 701 | | |
699 | 702 | | |
| |||
789 | 792 | | |
790 | 793 | | |
791 | 794 | | |
792 | | - | |
| 795 | + | |
793 | 796 | | |
794 | 797 | | |
795 | 798 | | |
| |||
0 commit comments