fix: use correct accountTreeController API in sortMultichainAccountsByLastSelected#40927
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
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.
Builds ready [1bff459]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
a5e5f5f to
ce30e24
Compare
Builds ready [ce30e24]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
…tsByLastSelected` ## **Description** Commit 7ca825d (`chore: integrate MultichainAccountService changes (#38265)`) replaced `this.multichainAccountService.getAccountContext()` with `this.accountTreeController.getAccountContext()` in `sortMultichainAccountsByLastSelected`, but the two methods return different shapes: - `multichainAccountService.getAccountContext()` returned an object with a `group` property exposing a `.get({ scopes })` method to retrieve accounts by scope. - `accountTreeController.getAccountContext()` returns `{ walletId, groupId, sortOrder }` — there is no `group` property. As a result, `context?.group?.get({ scopes: [EthScope.Eoa] })` always evaluated to `undefined`, causing `getLastSelected()` to always return `undefined` for every address. The sort became a no-op (`0 - 0 = 0`), meaning the wrong account (or none) was emitted on page reload for non-EVM networks. This broke `notifyNonEVMAccountChangedForCurrentAccount` for both Tron and Solana, as well as `_getSelectedMultichainAccountAddress` which also relies on `sortMultichainAccountsByLastSelected`. The fix adapts the code to the new `accountTreeController` API: 1. Retrieve the `groupId` from `getAccountContext(account.id)` 2. Fetch the group object via `getAccountGroupObject(groupId)` 3. Iterate the group's accounts to find the EVM EOA account (the only one carrying `metadata.lastSelected`) ## **Changelog** CHANGELOG entry: Fixed non-EVM account changed notifications not selecting the correct account on page reload for Tron and Solana Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ce30e24 to
bf5e0ae
Compare
|
Builds ready [bf5e0ae]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
| if (!group) { | ||
| return undefined; | ||
| } | ||
| // Find the EVM EOA account in this group, as it's the only one with lastSelected |
There was a problem hiding this comment.
😅 we should probably add this property to the group rather than just one address/account on the group no? cc @gantunesr




Description
Commit 7ca825d (
chore: integrate MultichainAccountService changes (#38265)) replacedthis.multichainAccountService.getAccountContext()withthis.accountTreeController.getAccountContext()insortMultichainAccountsByLastSelected, but the two methods return different shapes:multichainAccountService.getAccountContext()returned an object with agroupproperty exposing a.get({ scopes })method to retrieve accounts by scope.accountTreeController.getAccountContext()returns{ walletId, groupId, sortOrder }— there is nogroupproperty.As a result,
context?.group?.get({ scopes: [EthScope.Eoa] })always evaluated toundefined, causinggetLastSelected()to always returnundefinedfor every address. The sort became a no-op (0 - 0 = 0), meaning the wrong account (or none) was emitted on page reload for non-EVM networks.This broke
notifyNonEVMAccountChangedForCurrentAccountfor both Tron and Solana, as well as_getSelectedMultichainAccountAddresswhich also relies onsortMultichainAccountsByLastSelected.The fix adapts the code to the new
accountTreeControllerAPI:groupIdfromgetAccountContext(account.id)getAccountGroupObject(groupId)metadata.lastSelected)Changelog
CHANGELOG entry: Fixed non-EVM account changed notifications not selecting the correct account on page reload for Tron and Solana
Description
Changelog
CHANGELOG entry:
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches multichain account selection/sorting logic used on reload; incorrect grouping or type detection could still misorder accounts across networks, but the change is localized and covered by updated unit tests.
Overview
Fixes
sortMultichainAccountsByLastSelectedto work with the currentaccountTreeController.getAccountContextreturn shape by resolvinggroupIdto a group viagetAccountGroupObjectand then derivinglastSelectedfrom the group’s EVM EOA account.Updates/expands the unit tests to mock the new controller interactions (
getAccountGroupObject,accountsController.getAccount) and adds coverage for missing context/group scenarios so non-EVM account selection is correctly prioritized on reload.Written by Cursor Bugbot for commit bf5e0ae. This will update automatically on new commits. Configure here.