Skip to content

Fix: stop v4 balances calls when ws is up#8065

Closed
salimtb wants to merge 6 commits intomainfrom
fix/fix-v4-calls
Closed

Fix: stop v4 balances calls when ws is up#8065
salimtb wants to merge 6 commits intomainfrom
fix/fix-v4-calls

Conversation

@salimtb
Copy link
Contributor

@salimtb salimtb commented Feb 27, 2026

Explanation

What is the current state of things and why does it need to change?

When the Backend WebSocket is connected, balance updates are already pushed in real time. The extension was still polling the Accounts API v4 on every interval, which is redundant and adds avoidable load when the WebSocket is active.

What is the solution your changes offer and how does it work?

  • assets-controllers: AccountsApiBalanceFetcher now accepts an optional getIsWebSocketActive getter. When it returns true, the fetcher skips calling the Accounts API v4 and returns { balances: [], unprocessedChainIds } so the controller falls back to RPC/WebSocket for balance data. TokenBalancesController passes () => this.getIsWebSocketActive() when creating the fetcher. getIsWebSocketActive() no longer relies on a value set only in the constructor; it calls BackendWebSocketService:getConnectionInfo each time and returns whether the state is CONNECTED, so the "skip API when WebSocket is up" behavior stays correct after the WebSocket connects or disconnects.
  • core-backend: BackendWebSocketServiceGetConnectionInfoAction is exported from the package index so consumers (e.g. assets-controllers, extension) can type the getConnectionInfo action when registering or calling it.

Are there any changes whose purpose might not be obvious to those unfamiliar with the domain?

When the fetcher skips the API it returns unprocessedChainIds so the balance pipeline still treats those chains as unprocessed and can fill them via RPC or other sources instead of assuming the API handled them.

If your primary goal was to update one package but you found you had to update another one along the way, why did you do so?

Exporting the action type from core-backend was needed so dependent packages can type BackendWebSocketService:getConnectionInfo (e.g. for messenger action handlers or tests) without reaching into internal method-action-types.

If you had to upgrade a dependency, why did you do so?

N/A — no dependency upgrades in this PR.


References

Add "Fixes #XXXX" or "Related to #XXXX" if applicable.


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

Medium Risk
Changes balance-fetching behavior by bypassing Accounts API v4 calls when the backend WebSocket reports CONNECTED, which could lead to stale/missing balances if WebSocket state or coverage is incorrect. Touches core polling/fallback logic but is guarded and covered by new unit tests.

Overview
Prevents redundant Accounts API v4 balance polling when real-time updates are available via the backend WebSocket.

TokenBalancesController now exposes getIsWebSocketActive() (backed by BackendWebSocketService:getConnectionInfo) and passes it into AccountsApiBalanceFetcher, which short-circuits API calls when the socket is connected.

Adds unit coverage for the new WebSocket-state gating, and updates core-backend exports to expose BackendWebSocketServiceGetConnectionInfoAction for typed consumers (plus changelog entries).

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

@salimtb salimtb changed the title Fix/fix v4 calls Fix: stop v4 balances calls when ws is up Feb 27, 2026
@salimtb salimtb marked this pull request as ready for review February 27, 2026 14:56
@salimtb salimtb requested review from a team as code owners February 27, 2026 14:56
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@salimtb salimtb closed this Mar 2, 2026
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.

1 participant