fix: preferences controller state sync
Description
This PR syncs the state of accounts between the AccountsController and PreferencesController to keep them in sync.
The PreferencesController now mirrors the accounts from the AccountsController's InternalAccounts state. This ensures the PreferencesController always reflects the accurate account state.
Any write operations like setting the selected account or label are passed through to the AccountsController:
-
setSelectedAddresscallssetSelectedAccounton the AccountsController -
setAccountLabelcallssetAccountNameon the AccountsController
To get the selected account, the PreferencesController retrieves it from the AccountsController instead of internal state.
This allows the AccountsController to be the source of truth, while any write operations called on the PreferencesController are delegated to the AccountsController.
Related issues
Fixes:
Manual testing steps
- Go to this page...
Screenshots/Recordings
Pre-merge author checklist
- [x] I’ve followed MetaMask Coding Standards.
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using JSDoc format if applicable
- [x] I’ve applied the right labels on the PR (see labeling guidelines). 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.
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.
@metamaskbot update-policies
Policies updated
Builds ready [3081d96]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (1227 ± 617 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 72 | 196 | 122 | 45 | 21 |
| domContentLoaded | 9 | 73 | 19 | 14 | 7 | ||
| load | 59 | 2992 | 1227 | 1285 | 617 | ||
| domInteractive | 9 | 73 | 19 | 14 | 7 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -719 Bytes (-0.02%)
- ui: 0 Bytes (0.00%)
- common: 182 Bytes (0.00%)
Codecov Report
Attention: Patch coverage is 76.74419% with 10 lines in your changes missing coverage. Please review.
Project coverage is 65.70%. Comparing base (
a85b6cf) to head (c3cb9a5).
| Files | Patch % | Lines |
|---|---|---|
| app/scripts/controllers/preferences.js | 76.92% | 9 Missing :warning: |
| app/scripts/metamask-controller.js | 75.00% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #24678 +/- ##
===========================================
- Coverage 65.73% 65.70% -0.03%
===========================================
Files 1369 1369
Lines 54417 54366 -51
Branches 14161 14149 -12
===========================================
- Hits 35766 35718 -48
+ Misses 18651 18648 -3
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Builds ready [a8ceada]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (857 ± 565 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 72 | 187 | 115 | 36 | 17 |
| domContentLoaded | 10 | 36 | 18 | 8 | 4 | ||
| load | 60 | 2878 | 857 | 1177 | 565 | ||
| domInteractive | 10 | 36 | 18 | 8 | 4 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -719 Bytes (-0.02%)
- ui: 0 Bytes (0.00%)
- common: 182 Bytes (0.00%)
Builds ready [080a35d]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (985 ± 542 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 59 | 194 | 101 | 34 | 16 |
| domContentLoaded | 9 | 38 | 15 | 8 | 4 | ||
| load | 48 | 2605 | 985 | 1129 | 542 | ||
| domInteractive | 9 | 38 | 15 | 8 | 4 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -719 Bytes (-0.02%)
- ui: 0 Bytes (0.00%)
- common: 182 Bytes (0.00%)
Builds ready [850ab48]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (140 ± 174 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 69 | 122 | 89 | 13 | 6 |
| domContentLoaded | 9 | 25 | 12 | 4 | 2 | ||
| load | 45 | 1721 | 140 | 363 | 174 | ||
| domInteractive | 9 | 25 | 12 | 4 | 2 |
@metamaskbot update-policies
Policies updated
Builds ready [cf567b3]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (150 ± 197 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 76 | 113 | 90 | 9 | 5 |
| domContentLoaded | 8 | 14 | 11 | 2 | 1 | ||
| load | 42 | 1941 | 150 | 411 | 197 | ||
| domInteractive | 8 | 14 | 11 | 2 | 1 |
Builds ready [c3cb9a5]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (45 ± 2 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 65 | 89 | 78 | 7 | 3 |
| domContentLoaded | 8 | 11 | 9 | 1 | 0 | ||
| load | 41 | 53 | 45 | 3 | 2 | ||
| domInteractive | 8 | 11 | 9 | 1 | 0 |