From 1abf63ebd997a14cba20c2b4765e7b637133d311 Mon Sep 17 00:00:00 2001 From: tommasini <46944231+tommasini@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:21:26 +0000 Subject: [PATCH] fix: ethQuery is not defined when refresh is called (#8625) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** We were experiencing `undefined is not an object (evaluating 'inputBn.toString')` this warning multiple times when opening the app, because `this.ethQuery` it was not defined yet at the `AccountTrackerController` when . It was added a condition to only update the balance if it was possible to get balance from chain. Core PR: https://github.com/MetaMask/core/pull/3933 ## **Related issues** Fixes: ## **Manual testing steps** 1. Open the app 2. Shouldn't have the warning `undefined is not an object (evaluating 'inputBn.toString')` 3. ## **Screenshots/Recordings** ### **Before** ### **After** e Smoke E2E test builds: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/a075edf7-676e-4d24-8b0d-014890863b6d Regression E2E test builds: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/30f56c4e-3811-432c-83f0-139ea5b16ff5 ## **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 clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [x] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] 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. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [x] 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. --- .../@metamask+assets-controllers+9.2.0.patch | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/patches/@metamask+assets-controllers+9.2.0.patch b/patches/@metamask+assets-controllers+9.2.0.patch index 376767578ed..5c86c564a4a 100644 --- a/patches/@metamask+assets-controllers+9.2.0.patch +++ b/patches/@metamask+assets-controllers+9.2.0.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.d.ts b/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.d.ts -index ad327da..56a1ae3 100644 +index ad327da..8df74ba 100644 --- a/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.d.ts +++ b/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.d.ts @@ -1,6 +1,7 @@ @@ -47,7 +47,7 @@ index ad327da..56a1ae3 100644 /** * Sets a new provider. diff --git a/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.js b/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.js -index 18802c9..002f27c 100644 +index 18802c9..4b0d158 100644 --- a/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.js +++ b/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.js @@ -18,6 +18,7 @@ const async_mutex_1 = require("async-mutex"); @@ -71,7 +71,7 @@ index 18802c9..002f27c 100644 super(config, state); this.mutex = new async_mutex_1.Mutex(); /** -@@ -46,23 +48,36 @@ class AccountTrackerController extends base_controller_1.BaseController { +@@ -46,23 +48,38 @@ class AccountTrackerController extends base_controller_1.BaseController { * If multi-account is enabled, updates balances for all accounts. */ this.refresh = () => __awaiter(this, void 0, void 0, function* () { @@ -86,12 +86,16 @@ index 18802c9..002f27c 100644 ? Object.keys(accounts) : [this.getSelectedAddress()]; for (const address of accountsToUpdate) { -+ const hexBalance = yield this.getBalanceFromChain(address); - accounts[address] = { +- accounts[address] = { - balance: (0, controller_utils_1.BNToHex)(yield this.getBalanceFromChain(address)), -+ balance: (0, controller_utils_1.BNToHex)(hexBalance), - }; -+ accountsForChain[address] = { balance: (0, controller_utils_1.BNToHex)(hexBalance) }; +- }; ++ const hexBalance = yield this.getBalanceFromChain(address); ++ if(hexBalance){ ++ accounts[address] = { ++ balance: (0, controller_utils_1.BNToHex)(hexBalance), ++ }; ++ accountsForChain[address] = { balance: (0, controller_utils_1.BNToHex)(hexBalance) }; ++ } } - this.update({ accounts }); + this.update({ @@ -112,7 +116,7 @@ index 18802c9..002f27c 100644 this.initialize(); this.getIdentities = getIdentities; this.getSelectedAddress = getSelectedAddress; -@@ -70,21 +85,41 @@ class AccountTrackerController extends base_controller_1.BaseController { +@@ -70,21 +87,41 @@ class AccountTrackerController extends base_controller_1.BaseController { onPreferencesStateChange(() => { this.refresh(); });