fix(accounts-controller): guard undefined scopes in multichain listing - #9877
Open
rajanpanth wants to merge 1 commit into
Open
fix(accounts-controller): guard undefined scopes in multichain listing#9877rajanpanth wants to merge 1 commit into
rajanpanth wants to merge 1 commit into
Conversation
…ltichainAccounts` `listMultichainAccounts(chainId)` filters accounts with `isScopeEqualToAny(chainId, account.scopes)`, which calls `scopes.some(...)`. `InternalAccount.scopes` is typed as required, but a legacy or partially migrated account can be persisted without it, so `account.scopes` can be `undefined` at runtime and throws a `TypeError`. Guard the filter with `Array.isArray(account.scopes)` before matching. An account without a valid `scopes` array declares no chain and is excluded from chain-filtered results instead of throwing; unfiltered `listMultichainAccounts()` is unchanged.
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.
Summary
Adds a guard for undefined
scopeswhen listing multichain accounts in the accounts controller flow.Why
Undefined scope payloads can surface in edge cases and currently trigger avoidable runtime failures.
Note
Low Risk
Narrow defensive change to account listing; well-formed accounts behave as before, with legacy entries silently excluded from chain-filtered lists.
Overview
Fixes a
TypeErrorwhenlistMultichainAccounts(chainId)runs against persisted internal accounts that lack ascopesarray (legacy or partial migration).Chain filtering now requires
Array.isArray(account.scopes)beforeisScopeEqualToAny. Accounts with missingscopesare omitted from scoped results instead of crashing the call. A regression test and changelog entry document the behavior (#41962).Reviewed by Cursor Bugbot for commit 43bdbf6. Bugbot is set up for automated code reviews on this repo. Configure here.