Skip to content

Commit

Permalink
fix: ethQuery is not defined when refresh is called (#8625)
Browse files Browse the repository at this point in the history
## **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: MetaMask/core#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**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **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.
  • Loading branch information
tommasini authored Feb 27, 2024
1 parent 7ef00e1 commit 1abf63e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions patches/@metamask+assets-controllers+9.2.0.patch
Original file line number Diff line number Diff line change
@@ -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 @@
Expand Down Expand Up @@ -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");
Expand All @@ -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* () {
Expand All @@ -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({
Expand All @@ -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();
});
Expand Down

0 comments on commit 1abf63e

Please sign in to comment.