fix(assets-controllers): refetch snap balances after vault unlock when fetch was skipped while locked#8579
fix(assets-controllers): refetch snap balances after vault unlock when fetch was skipped while locked#8579
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9b21bf2. Configure here.
| for (const account of this.#listAccounts()) { | ||
| const hasBalance = | ||
| this.state.balances[account.id] && | ||
| Object.keys(this.state.balances[account.id]).length > 0; |
There was a problem hiding this comment.
Unlock handler skips accounts with existing partial balances
Medium Severity
The hasBalance check only triggers updateBalance for accounts with a completely empty balance map. Since balances state is persisted (persist: true), an account can have existing balance entries from a prior session while new assets get added via accountAssetListUpdated while locked. On unlock, the account already has entries so hasBalance is true, and the newly-added assets never get their balances fetched — the exact scenario this PR aims to fix, but only partially addressed.
Reviewed by Cursor Bugbot for commit 9b21bf2. Configure here.


Explanation
KeyringController:stateChangeinMultichainBalancesController.updateBalancefor any snap-backed (non-EVM) account that still has no cached balance entries.Problem
MultichainAssetsController:accountAssetListUpdatedtriggers balance fetches only whenKeyringController:getState().isUnlockedis true. If that event fires while the vault is locked, the fetch is skipped and never retried after unlock, so the UI can show empty multichain token rows despite assets inMultichainAssetsControllerstate.Consumer note
Extension (and any other consumer) must allow
KeyringController:stateChangeon theMultichainBalancesControllerrestricted messenger; otherwise this subscription will not receive events.References
Checklist
Note
Medium Risk
Adds a new
KeyringController:stateChangesubscription and triggers balance refetches on unlock, which can change runtime behavior and requires consumers to allow an additional messenger event.Overview
Ensures
MultichainBalancesControllerretries fetching balances after a vault unlock by subscribing toKeyringController:stateChangeand, on a locked→unlocked transition, callingupdateBalancefor non-EVM accounts that still have no cached balances.Updates the controller’s allowed messenger events (and test messenger delegation) to include
KeyringController:stateChange, and documents the fix in theassets-controllerschangelog.Reviewed by Cursor Bugbot for commit 9b21bf2. Bugbot is set up for automated code reviews on this repo. Configure here.