MetaMask / MetaMask/metamask-mobile

Extract handleAppStateChange in confirmation components into re-usable hook.

Open
#5,602 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-transactions team-confirmations-planning type-pinned type-tech-debt
Dominant language
TypeScript
Stars
3k
Forks
1.7k
Avg merge
1d 14h
Merged PRs (30d)
669

Description

### **Description**

`handleAppStateChange` takes care to cancel current transaction when app is no longer active.

The code includes registering listeners:
```
AppState.addEventListener('change', this.handleAppStateChange);
AppState.removeEventListener('change', this.handleAppStateChange);
```
And functions calls:

https://github.com/MetaMask/metamask-mobile/blob/bdb7f37c90e4fc923881a07fca38d4e77c73a579/app/components/Views/ApproveView/Approve/index.js#L372

https://github.com/MetaMask/metamask-mobile/blob/bdb7f37c90e4fc923881a07fca38d4e77c73a579/app/components/Views/Approval/index.js#L139

This can be extracted to a re-usable hook.

### **Acceptance Criteria**
The functionality to cancel transaction and close modal when app is not working should continue to work as expected on both screens.

### **References**
https://docs.google.com/document/d/19xKY4e07UThOa1jsDQA8pjsNLUBRn39EdUbaFpz3OR0/edit?usp=sharing

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing app/components/Views/ApproveView/Approve/index.js around the linked handleAppStateChange call with app/components/Views/Approval/index.js around its listener setup. Trace how each screen registers and removes the AppState listener, then verify that both screens still cancel the transaction and close the modal when the app is inactive.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.