Commit 344f947
fix: fix MM Connect account switching via homepage account selector (#22163)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
Fixes a bug with account switching for MM Connect where changing the
account selector value from the homepage did not result in the dapp
receiving an accountsChanged event. This was because when the app cold
started, there was no BackgroundBridge instantiated for any MMC
connections unless there were pending messages from the relay (for
performance reasons), and because the homepage account selector was no
longer updating the PreferencesController state because the
PreferencesController.selectedAddress is deprecated.
To fix this, BackgroundBridge is now always instantiated on app start up
for all MMC connections. This is suboptimal, but can be rectified later
with TTL enforcement. BackgroundBridge now reads AccountsController for
selected account state. This is also technically deprecated state, but
it's out of the scope of what we are trying to achieve to fully migrate
the BackgroundBridge to read the selected account group instead.
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: null
No changelog necessary as MM Connect has not been publicly released to
users yet.
## **Related issues**
Fixes:
## **Manual testing steps**
1. Using the [EVM MMC test
dapp](MetaMask/connect-monorepo#21) in the
Native Browser
2. Connect 2 accounts
3. See which account is listed first in the test dapp
4. Go back to the wallet and change the account in the main wallet view
to the other permitted account
5. Return to the native browser
6. See that the newly selected account is listed first in the test dapp
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [ ] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Ensure MMC/remote account changes emit by eagerly initializing the RPC
bridge and reading selected account from AccountsController instead of
PreferencesController.
>
> - **BackgroundBridge**:
> - Subscribe to `AccountsController:selectedAccountChange` and
unsubscribe on disconnect.
> - Replace `PreferencesController.selectedAddress` with
`AccountsController.getSelectedAccount().address` for `selectedAddress`
in `getState` and change detection in `onStateUpdate`.
> - For WalletConnect/remote, emit `accountsChanged` when the
AccountsController-selected address differs; update `addressSent`
accordingly.
> - **SDKConnectV2**:
> - `rpc-bridge-adapter`: call `ensureInitialized()` in constructor to
instantiate `BackgroundBridge` on startup, enabling timely event
delivery.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
bbd4de4. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: ffmcgee <joao.carlos@consensys.net>
Co-authored-by: Alex Donesky <adonesky@gmail.com>1 parent d42d736 commit 344f947
File tree
2 files changed
+21
-8
lines changed- app/core
- BackgroundBridge
- SDKConnectV2/adapters
2 files changed
+21
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
190 | 195 | | |
191 | 196 | | |
192 | 197 | | |
| |||
423 | 428 | | |
424 | 429 | | |
425 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
426 | 434 | | |
427 | 435 | | |
428 | | - | |
429 | | - | |
| 436 | + | |
| 437 | + | |
430 | 438 | | |
431 | | - | |
432 | | - | |
| 439 | + | |
| 440 | + | |
433 | 441 | | |
434 | 442 | | |
435 | 443 | | |
| |||
480 | 488 | | |
481 | 489 | | |
482 | 490 | | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
483 | 495 | | |
484 | 496 | | |
485 | 497 | | |
| |||
1133 | 1145 | | |
1134 | 1146 | | |
1135 | 1147 | | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
1139 | 1151 | | |
1140 | 1152 | | |
1141 | 1153 | | |
1142 | 1154 | | |
1143 | | - | |
| 1155 | + | |
1144 | 1156 | | |
1145 | 1157 | | |
1146 | 1158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
0 commit comments