Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: App slower when changing account and switching network (#9721)
## **Description** This PR reduces the number of api calls that happen when switching account and network, on cold and warm app starts. * Transactions are being fetched for all the accounts instead of just the selected one, that was fixed by adding a patch to the TransactionController to only fetch per account selected (36 fetches to eth_getTransactionReceipt and counted 40+ eth_getBlockByHash, to 0 since when we are switching network on an account that doesn't have transactions) Screenshot of main branch with eth_getTransactionReceipt requests: The selected account was not orangefox.eth https://etherscan.io/tx/0x7ce730e2e87520e179d4e351e5cfe80565c346f9ab7688a3391306422e01f0a9 <img src="https://github.com/MetaMask/metamask-mobile/assets/46944231/f4e2df99-20a2-4156-b16a-7fa26ed6af98" width=650 /> * Fixed a bug on Transaction controller where the getBlockByHash request was failing silently because it was missing one param. * ~~ENS fetches now only once we switch network and we change the selected account (This was looping by number of accounts and being retriggered, one 1 second, counted 15+ fetches to [ens contract](https://etherscan.io/address/0xa2c122be93b0074270ebee7f6b7292c7deb45047) , now it's just fetching once it switches network and for the selected account)~~ * Request parallelization of token balances. (This was not optimized on number of requests but on the parallelization of the requests to have a response quicker from all of them) * Update pooling of token balances from 10000 to 180000 miliseconds * Added a boolean to not let the updateBalances runs if there is an update in progress. (Probably change this to use mutex when implementing on core it's a good idea) A snapshot was updated on this PR! It seems that this snapshot was indeed wrong, and now it have the right mocked data. Check this transaction controller core branch with the changes: mobile-patch-performance-tx-controller-13-0-0 (Once this is approved, this changes need to be merged on the patch/mobile-transaction-controller-13-0-0 branch) Assets controller patch easy to ready, the core branch is this one: patch/mobile-assets-controllers-26-performance. (Once this is approved, this changes need to be merged on the patch/mobile-assets-controllers-26 branch) **Next steps** * Postpone transactions requests to views that will show transactions (exg: Asset View, Activity View) **Product Changes** * ~~ENS is now get by the selected account and not every account~~ This was addressed in other PR already * Transactions status is now updated only on the selected account (This still decrease the number of requests if the user has multiple accounts with multiple transactions) ## **Related issues** Fixes: #9250 #9249 ## **Manual testing steps** 1. 2. 3. ## **Screenshots/Recordings** ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask 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** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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.
- Loading branch information