fix: should not update balances when app is locked #7492
Merged
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 and why it needs to change
The
AccountTrackerControllerpreviously had inconsistent lock/unlock handling compared toTokenBalancesController:No lock state tracking: The controller had no way to track whether the keyring was locked, meaning it could attempt balance fetches even when the wallet was locked.
Refresh on unlock: When
KeyringController:unlockwas fired, it would immediately trigger a full balance refresh for all networks. This behavior was unnecessary since polling continues regardless of lock state.Refresh all networks on network add: When a new network was added via
NetworkController:networkAdded, the controller would refresh balances for all networks instead of just the newly added one.Solution
This PR aligns
AccountTrackerControllerwith the pattern already established inTokenBalancesController:Added
#isLockedproperty: Tracks whether the keyring is locked, initialized fromKeyringController:getStatein the constructor.Added
isActivegetter: Returnstruewhen the keyring is unlocked AND the user is onboarded. Balance fetching is skipped whenisActiveisfalse.Subscribe to
KeyringController:lock: Sets#isLocked = truewhen the keyring is locked.Updated
KeyringController:unlocksubscription: Now only sets#isLocked = falsewithout triggering an immediate refresh. Polling continues as normal and will fetch balances on the next interval.Optimized
NetworkController:networkAddedhandler: Now extracts thenetworkClientIdfrom the added network configuration and only refreshes balances for that specific network.Breaking changes
AccountTrackerControllermessenger must now allowKeyringController:getStateactionAccountTrackerControllermessenger must now allowKeyringController:lockeventReferences
TokenBalancesController(#isUnlockedproperty andisActivegetter)Checklist
Note
AccountTrackerController now tracks keyring lock state to gate balance updates, adds isActive, refreshes only the newly added network on networkAdded, and requires KeyringController:getState and :lock.
#isLocked(initialized viaKeyringController:getState) andisActivegetter; skip balance updates when inactive (locked or not onboarded).KeyringController:lock/unlockto update lock state; unlock no longer triggers immediate refresh.NetworkController:networkAdded, refresh balances only for the newly added network’snetworkClientId.KeyringController:getStateaction andKeyringController:lockevent in allowed actions/events.NetworkConfigurationand assertisActivetransitions.CHANGELOG.mdto document breaking changes and behavior tweaks.Written by Cursor Bugbot for commit 6c2de6a. This will update automatically on new commits. Configure here.