Closed
Conversation
There was a problem hiding this comment.
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.
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
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?
AccountsApiBalanceFetchernow accepts an optionalgetIsWebSocketActivegetter. When it returnstrue, the fetcher skips calling the Accounts API v4 and returns{ balances: [], unprocessedChainIds }so the controller falls back to RPC/WebSocket for balance data.TokenBalancesControllerpasses() => this.getIsWebSocketActive()when creating the fetcher.getIsWebSocketActive()no longer relies on a value set only in the constructor; it callsBackendWebSocketService:getConnectionInfoeach time and returns whether the state isCONNECTED, so the "skip API when WebSocket is up" behavior stays correct after the WebSocket connects or disconnects.BackendWebSocketServiceGetConnectionInfoActionis exported from the package index so consumers (e.g. assets-controllers, extension) can type thegetConnectionInfoaction 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
unprocessedChainIdsso 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
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.
TokenBalancesControllernow exposesgetIsWebSocketActive()(backed byBackendWebSocketService:getConnectionInfo) and passes it intoAccountsApiBalanceFetcher, which short-circuits API calls when the socket is connected.Adds unit coverage for the new WebSocket-state gating, and updates
core-backendexports to exposeBackendWebSocketServiceGetConnectionInfoActionfor typed consumers (plus changelog entries).Written by Cursor Bugbot for commit 48ac16a. This will update automatically on new commits. Configure here.