Skip to content

fix: handle Perps withdraw batch initialization errors cp-7.78.0#30299

Merged
dan437 merged 7 commits into
mainfrom
perps-withdraw-loading
May 19, 2026
Merged

fix: handle Perps withdraw batch initialization errors cp-7.78.0#30299
dan437 merged 7 commits into
mainfrom
perps-withdraw-loading

Conversation

@dan437

@dan437 dan437 commented May 18, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a Perps Withdraw loading state where users could get stuck on the confirmation skeleton if transaction batch initialization failed before an approval request was created.

The withdraw flow intentionally navigates to Confirmations early and shows a skeleton loader while the transaction batch is created. This PR adds the same failure escape hatch used by similar mobile flows: if addTransactionBatch fails, the app navigates back from the confirmation loader and shows the existing withdrawal failed toast.

Changelog

CHANGELOG entry: Fixed a bug that caused Perps Withdraw to stay stuck on a loading screen when withdrawal initialization failed

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/CONF-1392

Manual testing steps

Feature: Perps Withdraw error handling

  Scenario: user sees an error instead of a stuck loading screen
    Given the user is on the Perps home screen
    And Perps withdraw to any token is enabled
    And withdrawal transaction batch initialization fails

    When user taps Withdraw
    Then the confirmation skeleton is dismissed
    And the user is returned to the previous Perps screen
    And a withdrawal failed toast is shown

Screenshots/Recordings

Before

Users could remain stuck on the confirmation skeleton loader.

After

The app navigates back and shows the withdrawal failed toast.

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
  • I've tested with a power user scenario
  • I've instrumented key operations with Sentry traces for production performance metrics

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.

Note

Medium Risk
Changes Perps withdraw confirmation flow to handle addTransactionBatch failures by navigating back and showing a retry action, which affects user navigation and error handling paths. Risk is moderate due to potential edge cases around retry loops and toast/navigation state.

Overview
Prevents Perps withdraw from getting stuck on the confirmation skeleton by catching addTransactionBatch failures in usePerpsWithdrawConfirmation, navigating back, and showing a new retryable withdrawalStartFailed toast that re-attempts initialization.

Adds the withdrawalStartFailed(onRetry) toast option (styled as an error with a "Try again" link) plus new i18n strings, and updates/extends unit tests and mocks to cover the failure + retry behavior and error normalization.

Reviewed by Cursor Bugbot for commit a7ae72a. Bugbot is set up for automated code reviews on this repo. Configure here.

@dan437 dan437 requested a review from a team as a code owner May 18, 2026 09:54
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbotv2 metamaskbotv2 Bot added the team-confirmations Push issues to confirmations team label May 18, 2026
@dan437 dan437 force-pushed the perps-withdraw-loading branch from b4fe8bb to 2c8fd60 Compare May 18, 2026 13:45
@github-actions github-actions Bot added size-M and removed size-S labels May 18, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.38%. Comparing base (5624ab0) to head (2c8fd60).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...nts/UI/Perps/hooks/usePerpsWithdrawConfirmation.ts 27.27% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #30299       +/-   ##
===========================================
- Coverage   81.98%   47.38%   -34.60%     
===========================================
  Files        5447     5443        -4     
  Lines      145537   145287      -250     
  Branches    33248    33210       -38     
===========================================
- Hits       119312    68847    -50465     
- Misses      18094    70088    +51994     
+ Partials     8131     6352     -1779     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dan437 dan437 force-pushed the perps-withdraw-loading branch from 6aee337 to 6911b55 Compare May 19, 2026 08:39
Comment thread app/components/UI/Perps/hooks/usePerpsToasts.tsx
@dan437 dan437 force-pushed the perps-withdraw-loading branch from 1bd38c3 to ec6ca72 Compare May 19, 2026 10:21

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ec6ca72. Configure here.

Comment thread app/components/UI/Perps/hooks/usePerpsToasts.tsx Outdated
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
@dan437 dan437 requested a review from a team as a code owner May 19, 2026 11:33
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are focused on the Perps withdrawal flow:

  1. usePerpsToasts.tsx: Adds a new withdrawalStartFailed toast option with a retry button for when a Perps withdrawal fails to start. Also adds theme.colors.accent04.normal to the dependency array.

  2. usePerpsWithdrawConfirmation.ts: Wraps the addTransactionBatch call in a try/catch block. On error: navigates back (via useNavigation().goBack()), shows the new withdrawalStartFailed toast with a retry callback, and re-throws the error. This improves UX by gracefully handling withdrawal initiation failures.

  3. locales/en.json: Adds two new strings for the new toast: toast_start_error_description ("Your withdrawal wasn't started.") and try_again ("Try again").

  4. Test files: Unit tests updated to mock the new withdrawalStartFailed option and useNavigation mock.

  5. confirmations-developer-options.test.tsx: Updated to mock useNavigation since usePerpsWithdrawConfirmation now uses it.

Tag selection rationale:

  • SmokePerps: Directly affected - the Perps withdrawal flow now has error handling with a retry toast. The usePerpsWithdrawConfirmation hook is used in PerpsMarketBalanceActions and usePerpsHomeActions, which are core Perps UI components.
  • SmokeWalletPlatform: Required per SmokePerps tag description - "When selecting SmokePerps, also select SmokeWalletPlatform (Trending section)". Perps is a section inside the Trending tab.
  • SmokeConfirmations: Required per SmokePerps tag description - "When selecting SmokePerps, also select SmokeConfirmations (Add Funds deposits are on-chain transactions)". The withdrawal flow navigates to a confirmation screen, and the error handling now includes navigation.goBack() which could affect the confirmation flow.

The changes are well-scoped to Perps withdrawal error handling and don't touch core infrastructure, Engine, or other unrelated flows.

Performance Test Selection:
The changes are focused on error handling in the Perps withdrawal flow - adding a try/catch block and a toast notification for failures. These are not performance-sensitive changes (no rendering loops, no list components, no data loading changes, no startup/initialization changes). The new toast is only shown on error paths. No performance test tags are warranted.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@dan437 dan437 enabled auto-merge May 19, 2026 12:23
@dan437 dan437 added this pull request to the merge queue May 19, 2026
Merged via the queue into main with commit b5b803d May 19, 2026
186 of 198 checks passed
@dan437 dan437 deleted the perps-withdraw-loading branch May 19, 2026 12:45
@github-actions github-actions Bot locked and limited conversation to collaborators May 19, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.79.0 Issue or pull request that will be included in release 7.79.0 label May 19, 2026
@dan437 dan437 changed the title fix: handle Perps withdraw batch initialization errors fix: handle Perps withdraw batch initialization errors cp-7.78.0 May 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.79.0 Issue or pull request that will be included in release 7.79.0 size-M team-confirmations Push issues to confirmations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants