Commit 7b4433e
authored
fix: reject pending confirmations when app locks (#26905)
<!--
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**
If the user is on a send confirmation and the app goes idle until the
device and MetaMask lock, after unlocking they no longer see that
confirmation. If they then start a **new** send, the UI can show the
**previous** confirmation instead of the new one, because the old
approval was never rejected and remains first in the pending list.
**Solution**
When the app locks, reject all pending approvals by calling
`ApprovalController.clear(providerErrors.userRejectedRequest())` in the
lock saga, before navigating to the lock screen. That way there are no
stale confirmations after unlock, and any new send shows the correct
confirmation.
**Changes**
- **`app/store/sagas/index.ts`**: In `appLockStateMachine`, after
handling `LOCKED_APP`, clear pending approvals via
`Engine.context.ApprovalController.clear(...)` inside try/catch, then
navigate to `LOCK_SCREEN`. Log and ignore errors so navigation still
runs.
- **`app/store/sagas/sagas.test.ts`**: Add `ApprovalController` with
`clear` to the Engine mock; add tests that clear is called with
`userRejectedRequest()` when the app locks and that navigation to
`LOCK_SCREEN` still happens when `clear` throws.
-
<!--
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 issue of confirmation not rejecting when app
locks
## **Related issues**
Fixes: #26320
## **Manual testing steps**
```gherkin
Feature: Transaction Confirmation Persistence After Lock
Scenario: Stale confirmation displayed after device lock timeout and new transaction
Given the user has MetaMask open and unlocked on the home screen
# First transaction
When user initiates a send transaction
And user reaches the confirmation screen
# Lock timeout
And user allows the phone to idle until device and MetaMask lock
And user unlocks the phone
And user unlocks MetaMask
Then the confirmation screen should no longer be open
# Second transaction - bug occurs
When user initiates a different send transaction
And user reaches the confirmation screen
Then the confirmation shown should be for the previous transaction instead of the current one
```
## **Screenshots/Recordings**
[reject-approval-app-locks.webm](https://github.com/user-attachments/assets/ed331559-bf7a-452b-8688-7014dd4bff34)
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **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 approval/confirmation lifecycle by clearing all pending
approvals on app lock, which could inadvertently reject legitimate
in-flight requests if triggered unexpectedly. Guarded with try/catch and
covered by new saga tests, but behavior impacts transaction
confirmations.
>
> **Overview**
> Prevents stale transaction/permission confirmations after unlocking by
clearing any pending approvals when `UserActionType.LOCKED_APP` fires,
rejecting them with `providerErrors.userRejectedRequest()` before
navigating to `Routes.LOCK_SCREEN`.
>
> Updates saga tests to mock `ApprovalController.clear` and assert it is
invoked on lock, and that navigation to the lock screen still occurs
even if clearing approvals throws.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
2f1c2d3. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 5eeba88 commit 7b4433e
2 files changed
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
112 | 126 | | |
113 | 127 | | |
114 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
| |||
344 | 348 | | |
345 | 349 | | |
346 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
347 | 354 | | |
348 | 355 | | |
349 | 356 | | |
| 357 | + | |
350 | 358 | | |
351 | 359 | | |
352 | 360 | | |
| |||
359 | 367 | | |
360 | 368 | | |
361 | 369 | | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
362 | 393 | | |
363 | 394 | | |
364 | 395 | | |
| |||
0 commit comments