Skip to content

Commit

Permalink
chore: update state once per update
Browse files Browse the repository at this point in the history
  • Loading branch information
danroc committed Jun 12, 2024
1 parent df93878 commit d823bf5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/scripts/lib/accounts/BalancesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
} from '@metamask/base-controller';
import {
BtcAccountType,
InternalAccount,
KeyringClient,
type Balance,
type CaipAssetType,
type InternalAccount,
} from '@metamask/keyring-api';
import type { HandleSnapRequest } from '@metamask/snaps-controllers';
import type { SnapId } from '@metamask/snaps-sdk';
Expand Down Expand Up @@ -182,24 +182,24 @@ export class BalancesController extends BaseController<
*/
async updateBalances() {
const accounts = await this.#listAccounts();
const partialState: BalancesControllerState = { balances: {} };

for (const account of accounts) {
if (account.metadata.snap) {
const balances = await this.#getBalances(
partialState.balances[account.id] = await this.#getBalances(
account.id,
account.metadata.snap.id,
isBtcMainnet(account.address)
? BTC_MAINNET_ASSETS
: BTC_TESTNET_ASSETS,
);

this.update((state: Draft<BalancesControllerState>) => {
state.balances[account.id] = {
...state.balances[account.id],
...balances,
};
});
}
}

this.update((state: Draft<BalancesControllerState>) => ({
...state,
...partialState,
}));
}

/**
Expand Down

0 comments on commit d823bf5

Please sign in to comment.