Skip to content

feat: Clear stuck pending perps withdraws from app state cp-7.62.0#24449

Merged
gambinish merged 14 commits intomainfrom
feat/migrate-previous-pending-txns
Jan 15, 2026
Merged

feat: Clear stuck pending perps withdraws from app state cp-7.62.0#24449
gambinish merged 14 commits intomainfrom
feat/migrate-previous-pending-txns

Conversation

@gambinish
Copy link
Copy Markdown
Member

@gambinish gambinish commented Jan 12, 2026

Description

This PR addresses multiple scenarios where Perps withdrawal requests could get stuck in a "pending" or "bridging" state, causing stuck loading indicators in the UI.

Problem

  1. Users upgrading to a new app version may have stuck pending withdrawals from before the withdrawal flow fixes
  2. The updatedWithdrawalIdsRef in useWithdrawalRequests was not cleared on account switch, potentially causing stale updates if withdrawal IDs overlap across accounts
  3. Users had no way to manually clear stuck pending transactions

Solution

  1. Migration 110: Automatically clears pending/bridging withdrawal requests during app upgrade, preserving completed/failed ones for transaction history
  2. Account switch cleanup: Added effect to clear the updatedWithdrawalIdsRef when selectedAddress changes
  3. Reset Account integration: Added clearPendingTransactionRequests() method to PerpsController, exposed via usePerpsFirstTimeUser hook, and integrated into the Reset Account flow in Advanced Settings

Changelog

CHANGELOG entry: Fixed stuck pending withdrawal indicators in Perps trading by clearing stale transaction requests on app upgrade and account switch

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2365

Manual testing steps

Feature: Clear stuck pending Perps withdrawals

  Scenario: User upgrades app with stuck pending withdrawals
    Given user has pending withdrawal requests stuck from previous app version

    When user upgrades to new app version
    Then pending/bridging withdrawal requests are cleared
    And completed/failed withdrawal requests are preserved

  Scenario: User switches accounts with pending withdrawals
    Given user has account A with pending withdrawals
    And user switches to account B

    When user views Perps withdrawal status
    Then account B withdrawals are processed correctly
    And account A withdrawal IDs don't interfere with account B

  Scenario: User manually resets account
    Given user has stuck pending Perps transactions
    And user navigates to Settings > Advanced

    When user taps "Reset Account" and confirms
    Then pending/bridging Perps transactions are cleared
    And Perps first-time user state is reset

Screenshots/Recordings

Before

After

Pre-merge author checklist

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

Fix stuck Perps transaction indicators and improve state hygiene

  • New controller API & UI integration: Adds PerpsController.clearPendingTransactionRequests (and action type) to remove pending/bridging entries from withdrawalRequests and depositRequests, and reset withdrawalProgress. Exposed via usePerpsFirstTimeUser (clearPendingTransactionRequests) and invoked from ResetAccountModal alongside resetFirstTimeUserState.
  • State migration: Introduces migration 112 to automatically clear persisted Perps withdrawalRequests with pending/bridging statuses and reset withdrawalProgress, preserving completed/failed. Comprehensive tests included.
  • Hook & logging improvements: useWithdrawalRequests now filters by selected account with useStableArray, clears updatedWithdrawalIdsRef on account switch, and logs only meaningful events (initialized/status-changed/completed) instead of verbose dumps. Updated tests accordingly.
  • Controller & hooks tests: Adds unit tests for clearPendingTransactionRequests; updates usePerpsFirstTimeUser tests to cover new method and undefined controller handling.

Written by Cursor Bugbot for commit d14cb75. This will update automatically on new commits. Configure here.

@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.

@metamaskbot metamaskbot added the team-perps Perps team label Jan 12, 2026
@gambinish gambinish marked this pull request as ready for review January 12, 2026 20:18
@gambinish gambinish requested review from a team as code owners January 12, 2026 20:18
@gambinish gambinish moved this to Needs dev review in PR review queue Jan 12, 2026
abretonc7s
abretonc7s previously approved these changes Jan 13, 2026
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

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

LGTM

PatrykLucka
PatrykLucka previously approved these changes Jan 13, 2026
@gambinish gambinish enabled auto-merge January 13, 2026 16:46
@gambinish gambinish disabled auto-merge January 13, 2026 16:47
@gambinish gambinish dismissed stale reviews from PatrykLucka and abretonc7s via f2d9a2a January 15, 2026 00:15
@github-actions github-actions bot added size-XL and removed size-L labels Jan 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

The changes are focused on Perps functionality:

  1. PerpsController.ts (marked CRITICAL due to "Controller" keyword): Adds a new clearPendingTransactionRequests() method that filters out pending/bridging withdrawal and deposit requests. This is a new feature addition that doesn't modify existing behavior.

  2. usePerpsFirstTimeUser.ts and useWithdrawalRequests.ts: Hook updates to expose the new clearing functionality and improve logging efficiency. These are internal improvements.

  3. ResetAccountModal.tsx: Integrates the new Perps clearing functionality into the Reset Account feature. This is a minor integration point.

  4. Migration 112: New state migration to clear stuck pending withdrawal requests for users upgrading. This is a one-time cleanup migration.

  5. Test files: Comprehensive unit tests for all new functionality.

The E2E tests in e2e/specs/perps/ use the SmokePerps tag and test Perps functionality including deposits, positions, and withdrawals. Since the changes affect withdrawal request handling and the Perps controller state, running SmokePerps tests will verify the core Perps functionality still works correctly.

The Reset Account modal change is a minor addition that calls the new Perps method, but there are no E2E tests specifically for Reset Account functionality (the settings E2E tests don't cover this feature).

Risk is medium because:

  • The changes add new functionality rather than modifying existing behavior
  • The migration is defensive (preserves completed/failed requests, handles missing state gracefully)
  • Unit tests are comprehensive
  • The PerpsController is marked critical but the changes are additive

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

LGTM

@gambinish gambinish changed the title feat: Clear stuck pending perps withdraws from app state feat: Clear stuck pending perps withdraws from app state cp-7.62.0 Jan 15, 2026
@gambinish gambinish enabled auto-merge January 15, 2026 22:07
@Matt561 Matt561 self-requested a review January 15, 2026 22:32
@gambinish gambinish added this pull request to the merge queue Jan 15, 2026
@github-project-automation github-project-automation bot moved this from Needs dev review to Review finalised - Ready to be merged in PR review queue Jan 15, 2026
Merged via the queue into main with commit 2b417ee Jan 15, 2026
88 of 89 checks passed
@gambinish gambinish deleted the feat/migrate-previous-pending-txns branch January 15, 2026 22:51
@github-project-automation github-project-automation bot moved this from Review finalised - Ready to be merged to Merged, Closed or Archived in PR review queue Jan 15, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Jan 15, 2026
@metamaskbot metamaskbot added the release-7.63.0 Issue or pull request that will be included in release 7.63.0 label Jan 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.63.0 Issue or pull request that will be included in release 7.63.0 size-XL team-perps Perps team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants