feat(account-tree-controller): re-introduce lastSelected metadata#8261
feat(account-tree-controller): re-introduce lastSelected metadata#8261
lastSelected metadata#8261Conversation
aa318fb to
ba6d99f
Compare
ba6d99f to
cc3d9fe
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| } | ||
| } | ||
| } | ||
| return candidate?.id ?? ''; |
There was a problem hiding this comment.
Persisted lastSelected ignored during init fallback path
Low Severity
In init(), #getDefaultSelectedAccountGroup(wallets) receives the original wallets object rather than state.accountTree.wallets (the Immer draft). Since #applyAccountGroupMetadata writes persisted lastSelected values through the draft (copy-on-write), these updates are not reflected in the original wallets reference. If #getDefaultAccountGroupId is reached as a fallback, all groups appear to have lastSelected: 0, making the new lastSelected-based ranking ineffective during init and falling back to the EVM tiebreaker instead.
Additional Locations (1)
| state.accountTree.wallets[walletId].groups[ | ||
| groupId | ||
| ].metadata.lastSelected = now; | ||
| } |
There was a problem hiding this comment.
Duplicated lastSelected update logic across two methods
Low Severity
The block that guards accountGroupsMetadata[groupId], captures Date.now(), and writes lastSelected to both persisted metadata and the tree is copy-pasted identically in setSelectedAccountGroup and #handleSelectedAccountChange. Extracting this into a shared private helper would reduce the risk of future inconsistent updates between the two call sites.


Explanation
Some logic still relies on this metadata on accounts. Since we want to deprecate the
AccountsControllerat some point, we need to reintroduce this concept, but at the group level this time.References
N/A
Checklist
Note
Medium Risk
Medium risk because it changes how the controller persists/derives the default
selectedAccountGroup, which can affect account selection after removals or restarts if timestamps or metadata restoration behave unexpectedly.Overview
Adds a
lastSelectedtimestamp to account-group metadata, persisting it inaccountGroupsMetadata(local-only) and restoring it during tree initialization.Updates selection flows (
setSelectedAccountGroupandAccountsController:selectedAccountChange) to stampDate.now()into both persisted metadata and the in-tree group node, and changes default-group fallback logic to prefer the most recently selected non-empty group (with an EVM-account tiebreaker). Tests and rule-generated defaults are updated to includelastSelected: 0and to cover the new fallback/restore behavior.Written by Cursor Bugbot for commit cc3d9fe. This will update automatically on new commits. Configure here.