MetaMask / MetaMask/metamask-mobile
Extract handleAppStateChange in confirmation components into re-usable hook.
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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