Skip to content

Commit 414c75f

Browse files
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

‎test/e2e/page-objects/flows/bridge.flow.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const verifySubmittedSwapTransaction = async ({
3131
expectedDetailsDestAmount?: string;
3232
expectedActivityAmount?: string;
3333
}) => {
34+
await new BridgeQuotePage(driver).goBackAfterSubmit();
3435
const homePage = new HomePage(driver);
3536
await homePage.goToActivityList();
3637

‎test/e2e/page-objects/pages/bridge/quote-page.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,14 @@ class BridgeQuotePage {
572572
await this.driver.clickElement(this.backButton);
573573
};
574574

575+
/**
576+
* Waits for the submitted swap to clear the amount, then leaves Swaps.
577+
*/
578+
goBackAfterSubmit = async () => {
579+
await this.driver.waitForSelector(`${this.sourceAmount}[value=""]`);
580+
await this.goBack();
581+
};
582+
575583
/**
576584
* Opens an asset picker, giving the prepare page time to send its pending
577585
* quote parameter update first. Only needed by tests that assert on

‎test/e2e/page-objects/pages/swap/swap-page.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ class SwapPage {
147147
private readonly transactionStatusHeader =
148148
'[data-testid="swap-smart-transaction-status-header"]';
149149

150-
private readonly viewActivityButton = {
151-
tag: 'button',
152-
text: 'View activity',
153-
};
154-
155150
constructor(driver: Driver) {
156151
this.driver = driver;
157152
}
@@ -267,10 +262,6 @@ class SwapPage {
267262
await this.driver.clickElement(this.moreQuotesButton);
268263
}
269264

270-
async clickViewActivity(): Promise<void> {
271-
await this.driver.clickElementSafe(this.viewActivityButton);
272-
}
273-
274265
async closeQuotes(): Promise<void> {
275266
await this.driver.clickElementAndWaitToDisappear(this.closeQuotesButton);
276267
}
@@ -356,6 +347,10 @@ class SwapPage {
356347
return element.getAttribute('value');
357348
}
358349

350+
async goBackAfterSubmit(): Promise<void> {
351+
await new BridgeQuotePage(this.driver).goBackAfterSubmit();
352+
}
353+
359354
async reviewQuote(options: SwapReviewOptions) {
360355
await this.driver.waitForSelector(this.submitSwapButton);
361356
const fromAmount = await this.driver.findElement(this.reviewFromAmount);

‎test/e2e/tests/bridge/bridge-negative-cases.spec.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe('Bridge functionality', function (this: Suite) {
164164

165165
await bridgePage.submitQuote();
166166
await bridgePage.approveModalIfPresent();
167-
await driver.clickElementSafe({ text: 'View activity' });
167+
await bridgePage.goBackAfterSubmit();
168168
await homePage.goToActivityList();
169169

170170
const activityTab = new ActivityTab(driver);
@@ -206,6 +206,7 @@ describe('Bridge functionality', function (this: Suite) {
206206

207207
const bridgePage = await enterBridgeQuote(driver);
208208
await bridgePage.submitQuoteAndDismiss();
209+
await bridgePage.goBackAfterSubmit();
209210
await homePage.goToActivityList();
210211

211212
const activityTab = new ActivityTab(driver);
@@ -247,6 +248,7 @@ describe('Bridge functionality', function (this: Suite) {
247248

248249
const bridgePage = await enterBridgeQuote(driver);
249250
await bridgePage.submitQuoteAndDismiss();
251+
await bridgePage.goBackAfterSubmit();
250252
await homePage.goToActivityList();
251253

252254
const activityTab = new ActivityTab(driver);

‎test/e2e/tests/bridge/constants.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,7 @@ export const EXPECTED_INPUT_CHANGES = {
29612961
],
29622962
resetPage: [
29632963
{
2964-
token_source: 'eip155:1/slip44:60',
2964+
chain_source: 'eip155:1',
29652965
},
29662966
{
29672967
chain_destination: 'eip155:1',

‎test/e2e/tests/bridge/swap-gasless.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('Gasless swap tests', function (this: Suite) {
3535

3636
await bridgePage.submitQuoteAndDismiss();
3737

38+
await bridgePage.goBackAfterSubmit();
3839
await homePage.goToActivityList();
3940
const activityTab = new ActivityTab(driver);
4041
await activityTab.checkCompletedBridgeTransactionActivity(1);
@@ -70,6 +71,7 @@ describe('Gasless swap tests', function (this: Suite) {
7071

7172
await bridgePage.submitQuoteAndDismiss();
7273

74+
await bridgePage.goBackAfterSubmit();
7375
await homePage.goToActivityList();
7476
const activityTab = new ActivityTab(driver);
7577
await activityTab.checkCompletedBridgeTransactionActivity(2);
@@ -110,6 +112,7 @@ describe('Gasless swap tests', function (this: Suite) {
110112

111113
await bridgePage.submitQuoteAndDismiss();
112114

115+
await bridgePage.goBackAfterSubmit();
113116
await homePage.goToActivityList();
114117
const activityTab = new ActivityTab(driver);
115118
await activityTab.checkCompletedBridgeTransactionActivity(1);

‎test/e2e/tests/btc/btc-swap.spec.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ describe('BTC Account - Swap (Bridge)', function (this: Suite) {
280280
await bridgePage.checkExpectedNetworkFeeIsDisplayed();
281281
await bridgePage.submitQuote();
282282

283+
await bridgePage.goBackAfterSubmit();
283284
await homePage.goToActivityList();
284285
const activityTab = new ActivityTab(driver);
285286
await activityTab.checkCompletedBridgeTransactionActivity(2);
@@ -331,6 +332,7 @@ describe('BTC Account - Swap (Bridge)', function (this: Suite) {
331332
await bridgePage.checkExpectedNetworkFeeIsDisplayed();
332333
await bridgePage.submitQuote();
333334

335+
await bridgePage.goBackAfterSubmit();
334336
await homePage.goToActivityList();
335337
const activityTab = new ActivityTab(driver);
336338
await activityTab.checkCompletedBridgeTransactionActivity(2);

‎test/e2e/tests/hardware-wallets/ledger/ledger-swap.spec.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('Ledger Swap', function (this: Suite) {
5151
await hardwareWalletSignaturesPage.checkPageIsLoaded();
5252
await hardwareWalletSignaturesPage.waitForPageToClose();
5353

54+
await bridgePage.goBackAfterSubmit();
5455
await homePage.checkPageIsLoaded();
5556
await homePage.goToActivityList();
5657

‎test/e2e/tests/smart-transactions/smart-transactions.spec.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ describe('Smart Transactions', function () {
169169
await swapPage.submitSwap();
170170

171171
await swapPage.waitForSmartTransactionToComplete();
172-
await swapPage.clickViewActivity();
172+
await swapPage.goBackAfterSubmit();
173173

174174
await homePage.checkPageIsLoaded();
175+
const txToastNotification = new TxToastNotification(driver);
176+
await txToastNotification.checkTxConfirmedToast();
177+
await txToastNotification.closeToastNotification();
175178
await homePage.goToActivityList();
176179

177180
const activityTab = new ActivityTab(driver);
@@ -202,9 +205,12 @@ describe('Smart Transactions', function () {
202205
await swapPage.submitSwap();
203206

204207
await swapPage.waitForSmartTransactionToComplete();
205-
await swapPage.clickViewActivity();
208+
await swapPage.goBackAfterSubmit();
206209

207210
await homePage.checkPageIsLoaded();
211+
const txToastNotification = new TxToastNotification(driver);
212+
await txToastNotification.checkTxConfirmedToast();
213+
await txToastNotification.closeToastNotification();
208214
await homePage.goToActivityList();
209215

210216
const activityTab = new ActivityTab(driver);

‎test/e2e/tests/solana/swap.spec.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ describe('Swap on Solana', function () {
596596
swapFromAmount: '1',
597597
});
598598

599+
await swapPage.goBackAfterSubmit();
599600
await homePage.goToActivityList();
600601
const activityTab = new ActivityTab(driver);
601602
await activityTab.checkCompletedBridgeTransactionActivity(1);
@@ -645,6 +646,7 @@ describe('Swap on Solana', function () {
645646
swapFromAmount: '1',
646647
});
647648

649+
await swapPage.goBackAfterSubmit();
648650
await homePage.goToActivityList();
649651
const activityTab = new ActivityTab(driver);
650652
await activityTab.checkWaitForTransactionStatus('confirmed');
@@ -694,6 +696,7 @@ describe('Swap on Solana', function () {
694696
swapFromAmount: '0.00005',
695697
});
696698

699+
await swapPage.goBackAfterSubmit();
697700
await homePage.goToActivityList();
698701
const activityTab = new ActivityTab(driver);
699702
await activityTab.checkWaitForTransactionStatus('confirmed');
@@ -789,7 +792,7 @@ describe('Swap on Solana', function () {
789792
swapFromAmount: '1',
790793
});
791794

792-
// After failure, the bridge navigates to home/activity with the failed tx
795+
await swapPage.goBackAfterSubmit();
793796
await homePage.goToActivityList();
794797
const activityTab = new ActivityTab(driver);
795798
await activityTab.checkFailedTxNumberDisplayedInActivity(1);

0 commit comments

Comments
 (0)