Fix: assets controller startup empty accounts#8412
Merged
Conversation
… to AccountTreeController state
45dcaf9 to
bba7020
Compare
Prithpal-Sooriya
approved these changes
Apr 10, 2026
| // when init() calls this.update(). #start() is idempotent so | ||
| // repeated fires are safe. | ||
| this.messenger.subscribe('AccountTreeController:stateChange', () => { | ||
| this.#updateActive(); |
Contributor
There was a problem hiding this comment.
Can we use the state change selector (3rd param of the subscribe func)
Contributor
There was a problem hiding this comment.
Not a blocker, we'll receive a new event by accounts team which should remove the need for this state change event
Contributor
Author
There was a problem hiding this comment.
yes it's just a temp solution for now
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Current state: On returning users (those with persisted accounts),
AssetsController.#start()was called at keyring unlock time beforeAccountTreeController.init()had completed building the account tree. At that point,#selectedAccountsreturned an empty array, so no subscriptions were set up and no asset fetch was triggered. The controller would then sit idle because:AccountTreeController:selectedAccountGroupChangeonly fires when the selected group changes — on returning users the persisted group is unchanged, so this event is skipped.AccountTreeController:accountTreeChangeis not published byinit()— it only fires when accounts are added/removed after initialization.This meant asset balances, metadata, and prices were never loaded until the user manually switched accounts or networks.
Solution: Two changes working together:
Subscribe to
AccountTreeController:stateChange— the base-controller event that is guaranteed to fire wheninit()callsthis.update()to build the tree. When this fires,#updateActive()is called, which calls#start()now that accounts are available.Make
#start()idempotent — it now returns early if accounts/chains are not yet available (so the initial unlock call is a safe no-op), and also returns early if subscriptions are already active (so multiple subsequentstateChangefirings — e.g. from snap accounts being added — don't trigger redundant fetches).This follows the same pattern used by
DeFiPositionsController, which also gets accounts lazily fromAccountTreeControllerrather than eagerly at unlock time.References
Checklist
Note
Medium Risk
Touches
AssetsControllerstartup/lifecycle logic and subscription gating, which could change when/ how often asset fetches run if the new idempotency checks miss an edge case.Overview
Fixes a startup race where
AssetsControllercould remain idle for returning users by additionally reacting toAccountTreeController:stateChangeand re-evaluating active tracking once the account tree is initialized.Makes
#start()idempotent by returning early when no accounts/chains are available and when subscriptions are already active, preventing duplicate subscriptions/fetches from repeated events; adds a regression test for the unlock-then-tree-init flow and documents the fix in the assets-controller changelog.Reviewed by Cursor Bugbot for commit d5ad3c3. Bugbot is set up for automated code reviews on this repo. Configure here.