Skip to content

Conversation

@salimtb
Copy link
Contributor

@salimtb salimtb commented Dec 15, 2025

Explanation

Current state and why it needs to change

The AccountTrackerController previously had inconsistent lock/unlock handling compared to TokenBalancesController:

  1. 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.

  2. Refresh on unlock: When KeyringController:unlock was fired, it would immediately trigger a full balance refresh for all networks. This behavior was unnecessary since polling continues regardless of lock state.

  3. 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 AccountTrackerController with the pattern already established in TokenBalancesController:

  1. Added #isLocked property: Tracks whether the keyring is locked, initialized from KeyringController:getState in the constructor.

  2. Added isActive getter: Returns true when the keyring is unlocked AND the user is onboarded. Balance fetching is skipped when isActive is false.

  3. Subscribe to KeyringController:lock: Sets #isLocked = true when the keyring is locked.

  4. Updated KeyringController:unlock subscription: Now only sets #isLocked = false without triggering an immediate refresh. Polling continues as normal and will fetch balances on the next interval.

  5. Optimized NetworkController:networkAdded handler: Now extracts the networkClientId from the added network configuration and only refreshes balances for that specific network.

Breaking changes

  • AccountTrackerController messenger must now allow KeyringController:getState action
  • AccountTrackerController messenger must now allow KeyringController:lock event

References

  • Similar pattern exists in TokenBalancesController (#isUnlocked property and isActive getter)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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.

  • AccountTrackerController
    • Lock state & activity gating:
      • Add #isLocked (initialized via KeyringController:getState) and isActive getter; skip balance updates when inactive (locked or not onboarded).
      • Subscribe to KeyringController:lock/unlock to update lock state; unlock no longer triggers immediate refresh.
    • Network addition behavior:
      • On NetworkController:networkAdded, refresh balances only for the newly added network’s networkClientId.
    • Messenger contract (BREAKING):
      • Requires KeyringController:getState action and KeyringController:lock event in allowed actions/events.
    • Tests & docs:
      • Update tests to publish full NetworkConfiguration and assert isActive transitions.
      • Update CHANGELOG.md to document breaking changes and behavior tweaks.

Written by Cursor Bugbot for commit 6c2de6a. This will update automatically on new commits. Configure here.

@salimtb salimtb marked this pull request as ready for review December 15, 2025 11:53
@salimtb salimtb requested review from a team as code owners December 15, 2025 11:53
@salimtb salimtb added this pull request to the merge queue Dec 15, 2025
@salimtb salimtb removed this pull request from the merge queue due to a manual request Dec 15, 2025
@salimtb salimtb enabled auto-merge December 15, 2025 13:05
@salimtb salimtb added this pull request to the merge queue Dec 15, 2025
Merged via the queue into main with commit 30c8a38 Dec 15, 2025
285 checks passed
@salimtb salimtb deleted the fix/not-call-account-refresh-balance-when-locked branch December 15, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants