Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/components/UI/Tokens/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ jest.mock('../../../core/Engine', () => ({
},
},
},
PreferencesController: {
state: {
tokenNetworkFilter: {
'0x00': true,
'0x01': true,
'0x02': true,
},
},
},
},
}));

Expand Down
8 changes: 8 additions & 0 deletions app/components/UI/Tokens/util/refreshEvmTokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ jest.mock('../../../../core/Engine', () => ({
},
},
},
PreferencesController: {
state: {
tokenNetworkFilter: {
'0x1': true,
'0x89': true,
},
},
},
},
}));

Expand Down
8 changes: 8 additions & 0 deletions app/components/UI/Tokens/util/refreshTokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ jest.mock('../../../../core/Engine', () => ({
},
},
},
PreferencesController: {
state: {
tokenNetworkFilter: {
'0x1': true,
'0x89': true,
},
},
},
},
}));

Expand Down
8 changes: 8 additions & 0 deletions app/components/UI/Tokens/util/tokenRefreshUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ jest.mock('../../../../core/Engine', () => ({
},
},
},
PreferencesController: {
state: {
tokenNetworkFilter: {
'0x1': true,
'0x2': true,
},
},
},
},
}));

Expand Down
36 changes: 25 additions & 11 deletions app/components/UI/Tokens/util/tokenRefreshUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,42 @@ export const performEvmRefresh = async (
TokenRatesController,
TokenBalancesController,
NetworkController,
PreferencesController,
} = Engine.context;

const networkClientIds = Object.values(
NetworkController.state.networkConfigurationsByChainId,
).map(
(network) =>
network?.rpcEndpoints?.[network.defaultRpcEndpointIndex]?.networkClientId,
);
const tokenListChains = PreferencesController.state.tokenNetworkFilter;
const networkConfigurations =
NetworkController.state.networkConfigurationsByChainId;

const chainIds = Object.keys(tokenListChains) as Hex[];
const networkClientIds = chainIds
.map((c) => {
const config = networkConfigurations[c];
if (!config) {
return undefined;
}

return config?.rpcEndpoints?.[config?.defaultRpcEndpointIndex]
?.networkClientId;
})
.filter((c: string | undefined): c is string => Boolean(c));

const actions = [
TokenDetectionController.detectTokens({
chainIds: Object.keys(evmNetworkConfigurationsByChainId) as Hex[],
chainIds,
}),
TokenBalancesController.updateBalances({
chainIds: Object.keys(evmNetworkConfigurationsByChainId) as Hex[],
chainIds,
}),
AccountTrackerController.refresh(networkClientIds),
CurrencyRateController.updateExchangeRate(nativeCurrencies),
TokenRatesController.updateExchangeRatesByChainId(
Object.values(evmNetworkConfigurationsByChainId).filter(
(n) => n.chainId && n.nativeCurrency,
),
chainIds
.filter((chainId) => {
const config = evmNetworkConfigurationsByChainId[chainId];
return config?.chainId && config?.nativeCurrency;
})
.map((c) => evmNetworkConfigurationsByChainId[c]),
),
];

Expand Down
13 changes: 7 additions & 6 deletions app/components/Views/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,14 @@ const Wallet = ({
requestAnimationFrame(async () => {
const { AccountTrackerController } = Engine.context;

Object.values(evmNetworkConfigurations).forEach(
({ defaultRpcEndpointIndex, rpcEndpoints }) => {
AccountTrackerController.refresh([
const networkClientIDs = Object.values(evmNetworkConfigurations)
.map(
({ defaultRpcEndpointIndex, rpcEndpoints }) =>
rpcEndpoints[defaultRpcEndpointIndex].networkClientId,
]);
},
);
)
.filter((c) => Boolean(c));

AccountTrackerController.refresh(networkClientIDs);
});
},
/* eslint-disable-next-line */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
diff --git a/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.cjs b/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.cjs
index 9749434..fed49f4 100644
--- a/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.cjs
+++ b/node_modules/@metamask/assets-controllers/dist/AccountTrackerController.cjs
@@ -148,27 +148,33 @@ class AccountTrackerController extends (0, polling_controller_1.StaticIntervalPo
this.syncAccounts(chainIds);
// Create an array of promises for each networkClientId
const updatePromises = networkClientIds.map(async (networkClientId) => {
- const { chainId, ethQuery, provider } = __classPrivateFieldGet(this, _AccountTrackerController_instances, "m", _AccountTrackerController_getCorrectNetworkClient).call(this, networkClientId);
+ const { chainId, ethQuery, provider, blockTracker } = __classPrivateFieldGet(this, _AccountTrackerController_instances, "m", _AccountTrackerController_getCorrectNetworkClient).call(this, networkClientId);
const { accountsByChainId } = this.state;
const { isMultiAccountBalancesEnabled } = this.messagingSystem.call('PreferencesController:getState');
const accountsToUpdate = isMultiAccountBalancesEnabled
? Object.keys(accountsByChainId[chainId])
: [(0, controller_utils_1.toChecksumHexAddress)(selectedAccount.address)];
const accountsForChain = { ...accountsByChainId[chainId] };
+ // Force fresh block data before multicall
+ // TODO: This is a temporary fix to ensure that the block number is up to date.
+ // We should remove this once we have a better solution for this on the block tracker controller.
+ await (0, controller_utils_1.safelyExecuteWithTimeout)(() => blockTracker?.checkForLatestBlock?.());
const stakedBalancesPromise = __classPrivateFieldGet(this, _AccountTrackerController_includeStakedAssets, "f")
? __classPrivateFieldGet(this, _AccountTrackerController_getStakedBalanceForChain, "f").call(this, accountsToUpdate, networkClientId)
: Promise.resolve({});
if ((0, utils_1.hasProperty)(AssetsContractController_1.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID, chainId)) {
const contractAddress = AssetsContractController_1.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID[chainId];
const contract = new contracts_1.Contract(contractAddress, single_call_balance_checker_abi_1.default, new providers_1.Web3Provider(provider));
- const nativeBalances = await contract.balances(accountsToUpdate, [
+ const nativeBalances = await (0, controller_utils_1.safelyExecuteWithTimeout)(() => contract.balances(accountsToUpdate, [
'0x0000000000000000000000000000000000000000',
- ]);
- accountsToUpdate.forEach((address, index) => {
- accountsForChain[address] = {
- balance: nativeBalances[index].toHexString(),
- };
- });
+ ]), false, 3000);
+ if (nativeBalances) {
+ accountsToUpdate.forEach((address, index) => {
+ accountsForChain[address] = {
+ balance: nativeBalances[index].toHexString(),
+ };
+ });
+ }
}
else {
// Process accounts in batches using reduceInBatchesSerially
@@ -191,8 +197,8 @@ class AccountTrackerController extends (0, polling_controller_1.StaticIntervalPo
},
});
}
- const stakedBalanceResult = (await stakedBalancesPromise);
- Object.entries(stakedBalanceResult).forEach(([address, balance]) => {
+ const stakedBalanceResult = await (0, controller_utils_1.safelyExecuteWithTimeout)(async () => (await stakedBalancesPromise));
+ Object.entries(stakedBalanceResult ?? {}).forEach(([address, balance]) => {
accountsForChain[address] = {
...accountsForChain[address],
stakedBalance: balance,
@@ -269,11 +275,12 @@ _AccountTrackerController_refreshMutex = new WeakMap(), _AccountTrackerControlle
const selectedNetworkClientId = networkClientId ??
this.messagingSystem.call('NetworkController:getState')
.selectedNetworkClientId;
- const { configuration: { chainId }, provider, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
+ const { configuration: { chainId }, provider, blockTracker, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
return {
chainId,
provider,
ethQuery: new eth_query_1.default(provider),
+ blockTracker,
};
}, _AccountTrackerController_getNetworkClientIds = function _AccountTrackerController_getNetworkClientIds() {
const { networkConfigurationsByChainId } = this.messagingSystem.call('NetworkController:getState');
diff --git a/node_modules/@metamask/assets-controllers/dist/NftController.cjs b/node_modules/@metamask/assets-controllers/dist/NftController.cjs
index 3e7b205..00ad856 100644
--- a/node_modules/@metamask/assets-controllers/dist/NftController.cjs
Expand Down Expand Up @@ -150,7 +221,7 @@ index 3e7b205..00ad856 100644
}
}
diff --git a/node_modules/@metamask/assets-controllers/dist/NftController.d.cts b/node_modules/@metamask/assets-controllers/dist/NftController.d.cts
index e16e91f..3168b35 100644
index 4a81bbc..6cd5476 100644
--- a/node_modules/@metamask/assets-controllers/dist/NftController.d.cts
+++ b/node_modules/@metamask/assets-controllers/dist/NftController.d.cts
@@ -110,6 +110,7 @@ export type NftMetadata = {
Expand Down
Loading