fix(assets-controller): skip redundant Accounts API refetch when WebSocket already confirmed the transaction - #9940
Open
juanmigdr wants to merge 4 commits into
Open
fix(assets-controller): skip redundant Accounts API refetch when WebSocket already confirmed the transaction#9940juanmigdr wants to merge 4 commits into
juanmigdr wants to merge 4 commits into
Conversation
…ocket already confirmed the transaction When a transaction is confirmed, AssetsController forces an Accounts API balance refetch even if AccountActivityService's WebSocket already delivered the same balance update for that chain. Now it waits briefly for a matching transactionUpdated event before falling back to the API call, handling both possible arrival orders of the two signals.
juanmigdr
temporarily deployed
to
default-branch
August 24, 2026 15:25 — with
GitHub Actions
Inactive
…king in changelog Hosts with restricted messengers (e.g. the mobile app) must delegate AccountActivityService:transactionUpdated for AssetsController to see it, so this is a breaking change to the messenger contract, not just an internal behavior tweak.
Replace informal inline comments with clearer, consistent wording.
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
AssetsControllerruns a forced Accounts API balance refetch every time a transaction is confirmed, even whenAccountActivityService's WebSocket already delivered the same balance update for that chain. That's an unnecessary HTTP call whenever the WebSocket connection is healthy.This change makes
AssetsControllercheck whether the transaction's chain is WS-active, and if so, wait briefly for a matchingAccountActivityService:transactionUpdatedevent (correlated by transaction hash) before forcing the API refetch. If the WebSocket confirms in time, the API call is skipped; if it doesn't (WS down, message dropped, etc.), the API call still happens as a fallback, so behavior is unchanged when the WebSocket isn't available.One thing worth calling out for reviewers:
transactionConfirmedand the WebSocket'stransactionUpdatedpush are two independent signals that can arrive in either order — the WebSocket message frequently arrives beforetransactionConfirmedfires. The implementation accounts for this by tracking whichever one arrives first per transaction, so it works correctly regardless of ordering.Breaking change:
AssetsControllernow subscribes toAccountActivityService:transactionUpdated. Any host that restricts which events flow through theAssetsControllermessenger (e.g. via a scoped delegation list) must add this event, orAssetsControllerwill never see it and will always fall back to the API call.References
Checklist
Note
Medium Risk
Changes post-confirmation balance refresh timing and adds a breaking messenger subscription; stale balances are possible only if WS falsely signals confirmation and the API fallback is skipped, but timeout fallback preserves prior behavior when WS is unreliable.
Overview
After a transaction confirms, AssetsController no longer always forces an Accounts API balance refetch. When the chain is WebSocket-active and the confirmation includes a hash, it waits up to 1.5s for a matching
AccountActivityService:transactionUpdatedevent; if that arrives first (including when WS fires beforetransactionConfirmed), the HTTP refetch is skipped.If the chain is not WS-active, the hash is missing, or the WS signal never matches in time, behavior is unchanged:
getAssetsstill runs withforceUpdate: true. Coordination uses a per-transaction map with cleanup ondestroy.Breaking: the controller now subscribes to
AccountActivityService:transactionUpdated; hosts that scope messenger events must delegate it or the optimization never applies.Reviewed by Cursor Bugbot for commit a516b09. Bugbot is set up for automated code reviews on this repo. Configure here.