Skip to content

Commit

Permalink
fix: patch zero balance when getBalance query times out (#6717)
Browse files Browse the repository at this point in the history
* fix: patch balance retrieval in AccountTrackerController

return an error in case of balance query timeout instead of the default zero balance

* fix for back balance retrieval

* fix return value

this was not the right fix previously...

* remove unused result variable

---------

Co-authored-by: sethkfman <[email protected]>
  • Loading branch information
NicolasMassart and sethkfman authored Jun 30, 2023
1 parent c91ec26 commit bdba864
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions patches/@metamask+assets-controllers+5.0.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.js b/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.js
index 130e3dc..912c84c 100644
index 130e3dc..2fd96bb 100644
--- a/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.js
+++ b/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.js
@@ -30,7 +30,7 @@ class AccountTrackerController extends base_controller_1.BaseController {
Expand All @@ -11,7 +11,7 @@ index 130e3dc..912c84c 100644
super(config, state);
this.mutex = new async_mutex_1.Mutex();
/**
@@ -38,16 +38,26 @@ class AccountTrackerController extends base_controller_1.BaseController {
@@ -38,16 +38,28 @@ class AccountTrackerController extends base_controller_1.BaseController {
*/
this.name = 'AccountTrackerController';
/**
Expand All @@ -29,6 +29,7 @@ index 130e3dc..912c84c 100644
+ if (!isMultiAccountBalancesEnabled) {
+ const selectedAddress = this.getSelectedAddress();
+ const balance = yield this.getBalanceFromChain(selectedAddress);
+ if (!balance) return;
+ accounts[selectedAddress] = { balance: (0, controller_utils_1.BNToHex)(balance) };
+ this.update({ accounts });
+ return;
Expand All @@ -39,11 +40,12 @@ index 130e3dc..912c84c 100644
- accounts[address] = { balance: (0, controller_utils_1.BNToHex)(balance) };
- }));
+ const balance = yield this.getBalanceFromChain(address);
+ if (!balance) continue;
+ accounts[address] = { balance: (0, controller_utils_1.BNToHex)(balance) };
}
this.update({ accounts });
});
@@ -57,6 +67,8 @@ class AccountTrackerController extends base_controller_1.BaseController {
@@ -57,6 +69,8 @@ class AccountTrackerController extends base_controller_1.BaseController {
this.defaultState = { accounts: {} };
this.initialize();
this.getIdentities = getIdentities;
Expand All @@ -52,7 +54,7 @@ index 130e3dc..912c84c 100644
onPreferencesStateChange(() => {
this.refresh();
});
@@ -106,6 +118,22 @@ class AccountTrackerController extends base_controller_1.BaseController {
@@ -106,6 +120,22 @@ class AccountTrackerController extends base_controller_1.BaseController {
}, this.config.interval);
});
}
Expand All @@ -65,7 +67,7 @@ index 130e3dc..912c84c 100644
+ */
+ getBalanceFromChain(address) {
+ return __awaiter(this, void 0, void 0, function* () {
+ let balance = '0x0';
+ let balance;
+ yield (0, controller_utils_1.safelyExecuteWithTimeout)(() => __awaiter(this, void 0, void 0, function* () {
+ balance = yield (0, controller_utils_1.query)(this.ethQuery, 'getBalance', [address]);
+ }));
Expand Down Expand Up @@ -109,7 +111,7 @@ index 332c87d..b634fde 100644
* Enumerate assets assigned to an owner.
*
diff --git a/node_modules/@metamask/assets-controllers/dist/Standards/ERC20Standard.js b/node_modules/@metamask/assets-controllers/dist/Standards/ERC20Standard.js
index 9ddbc28..ca00e3e 100644
index 9ddbc28..b8fb35a 100644
--- a/node_modules/@metamask/assets-controllers/dist/Standards/ERC20Standard.js
+++ b/node_modules/@metamask/assets-controllers/dist/Standards/ERC20Standard.js
@@ -13,7 +13,13 @@ exports.ERC20Standard = void 0;
Expand Down

0 comments on commit bdba864

Please sign in to comment.