Skip to content

Commit d881cec

Browse files
authored
fix: MUSD-456 prevent mUSD stale approval cleanup from rejecting active confirmations (MetaMask#27155)
<!-- 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** The `useMusdConversionStaleApprovalCleanup` hook was rejecting pending mUSD approvals whenever the app returned from background — including when the user simply tapped an in-app "terms apply" link that opened the browser. This caused the confirmation screen to enter a stuck loading state. This PR adds a screen-aware guard with deeplink detection so the hook can distinguish between: - Returning from an in-app link (browser round-trip) → preserves the approval - Incoming deeplink that navigates the user away → rejects the approval - Not on a confirmation screen → rejects immediately (existing behavior) Detection uses React Native's Linking url event listener, which fires for incoming deeplinks but not for returns from `Linking.openURL()`. <!-- 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? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: fixed mUSD conversion confirmation no longer gets stuck when tapping external links that briefly background the app. ## **Related issues** Fixes: [MUSD-456: Opening "terms apply" link on Max and Custom convert rejects the transaction and navigates back](https://consensyssoftware.atlassian.net/browse/MUSD-456) ## **Manual testing steps** ```gherkin Feature: mUSD conversion stale approval cleanup Scenario: user taps external link on confirmation screen and returns Given user is on the mUSD conversion confirmation screen with a pending approval When user taps the "terms apply" link and returns from the browser Then the pending approval is preserved and the confirmation screen remains functional Scenario: user returns to app via deeplink while on confirmation screen Given user is on the mUSD conversion confirmation screen with a pending approval When the app is reopened via an incoming deeplink Then the stale pending approval is rejected and the user is not stuck in a disabled state Scenario: user returns from background when not on confirmation screen Given user has a pending mUSD conversion approval and is not on a confirmation screen When the app returns from background Then the stale pending approval is rejected immediately ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> https://github.com/user-attachments/assets/3898d1c2-54d4-420d-ae11-9ebc47a80ef6 ### **After** <!-- [screenshots/recordings] --> https://github.com/user-attachments/assets/7197fac6-ef08-4089-b02b-7316fe922992 ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes the conditions under which pending mUSD approvals are auto-rejected and adds deeplink detection based on `Linking` events, which could affect approval lifecycle/navigation if misclassified. Scope is limited and covered by expanded unit tests. > > **Overview** > Prevents `useMusdConversionStaleApprovalCleanup` from auto-rejecting pending mUSD approvals when the user is *actively in the confirmation flow* (e.g. `REDESIGNED_CONFIRMATIONS` / `TOOLTIP_MODAL`) and the app returns from background without an incoming deeplink. > > Adds `Linking` `url` event tracking to distinguish true deeplink resumes (reject approvals and optionally `goBack` from the orphaned confirmation screen) from browser round-trips, refactors rejection into a helper, and significantly expands tests to cover listener lifecycle, screen-aware guarding, deeplink flag reset behavior, and post-rejection navigation. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 032186e. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent c6e4302 commit d881cec

2 files changed

Lines changed: 432 additions & 158 deletions

File tree

0 commit comments

Comments
 (0)