-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(runway): cherry-pick fix: freeze during swap with approval (#11165
) ## **Description** The freeze was ultimately caused by a render loop inside `RootRPCMethodsUI` caused by the `TransactionController:unapprovedTransactionAdded` listener. More specifically: 1. When swaps are detected, the transaction is automatically approved via the `autoSign` function. 2. This registers a listener to send a completed metric once the transaction is confirmed. 3. This is triggered by adding the transaction ID to a queue via the `addTransactionMetaIdForListening` function. 4. This function updates React state, but was also using that same state as a dependency, meaning the callback was updated on every usage. 5. This function was a dependency of `autoSign` which was in turn a dependency of `onUnapprovedTransaction` which was the only dependency for a `useEffect` that re-created the `TransactionController:unapprovedTransactionAdded` listener. 6. The `ControllerMessenger` processes listeners using an iterator rather than a static list meaning each new listener was automatically ran which in turn created another listener and resulted in a very high CPU render loop. The core fix was to update the `addTransactionMetaIdForListening` to update the state using the callback override meaning it did not require the state dependency. However during testing it was discovered that this swaps completed metric was not functioning since the `swapsTransaction` state was being incorrectly populated with the `TransactionController` instance due to a legacy function argument that was not fully removed. This has been addressed, and all swaps transactions updates have been abstracted via a new `swaps-transactions` utility file. ## **Related issues** Fixes: [#11085](#11085) ## **Manual testing steps** Full swaps regression, including: - Swaps with approvals. - Smart swaps. - Metric support. - Multiple sequential swaps (with and without approvals). ## **Screenshots/Recordings** ### **Before** ### **After** ## **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. --------- Co-authored-by: sethkfman <10342624+sethkfman@users.noreply.github.com>
- Loading branch information
1 parent
9d4715c
commit 45674a9
Showing
8 changed files
with
219 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.