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
4 changes: 4 additions & 0 deletions packages/assets-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fetch balances when switching account groups, enabling RPC-only networks, or after a new account is added to the account tree ([#9388](https://github.com/MetaMask/core/pull/9388))

## [10.0.1]

### Changed
Expand Down
22 changes: 18 additions & 4 deletions packages/assets-controller/src/AssetsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,25 +1329,38 @@ export class AssetsController extends BaseController<
currentCount: currentIds.size,
});

const newAccounts = accounts.filter(
(account) => !this.#lastKnownAccountIds.has(account.id),
);

this.#lastKnownAccountIds = currentIds;
this.#ensureNativeBalancesDefaultZero();
this.#ensureDefaultTrackedAssetsSeeded();
this.#runAccountTreeRefresh(accounts).catch((error) => {
this.#runAccountTreeRefresh(accounts, newAccounts).catch((error) => {
log('Failed to refresh assets after tree change', error);
});
} else {
this.#start();
}
}

async #runAccountTreeRefresh(accounts: InternalAccount[]): Promise<void> {
async #runAccountTreeRefresh(
accounts: InternalAccount[],
newAccounts: InternalAccount[] = [],
): Promise<void> {
const releaseLock = await this.#accountRefreshMutex.acquire();
try {
await this.getAssets(accounts, {
chainIds: [...this.#enabledChains],
forceUpdate: true,
});
this.#subscribeAssets();
if (newAccounts.length > 0) {
await this.getAssets(newAccounts, {
chainIds: [...this.#enabledChains],
forceUpdate: true,
});
Comment thread
salimtb marked this conversation as resolved.
}
} catch (error) {
log('Failed to fetch assets after tree change', error);
this.#subscribeAssets();
Expand Down Expand Up @@ -3364,8 +3377,9 @@ export class AssetsController extends BaseController<
this.#subscribeAssets();

// Do one-time fetch for newly enabled chains; merge so we keep existing chain balances
if (addedChains.length > 0 && this.#getSelectedAccounts().length > 0) {
await this.getAssets(this.#getSelectedAccounts(), {
const accounts = this.#getSelectedAccounts();
if (addedChains.length > 0 && accounts.length > 0) {
await this.getAssets(accounts, {
chainIds: addedChains,
forceUpdate: true,
updateMode: 'merge',
Expand Down