feat: converted PreferencesController to typescript
Description
As a prerequisite for migrating PreferencesController to BaseController v2, and to support the TypeScript migration effort for the extension, we want to convert PreferencesController to TypeScript.
Related issues
Fixes: #25923
Manual testing steps
- Go to this page...
Screenshots/Recordings
Before
After
Pre-merge author checklist
- [ ] I've followed MetaMask Contributor Docs and MetaMask Extension Coding Standards.
- [ ] 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 format if applicable
- [ ] 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.
Codecov Report
Attention: Patch coverage is 65.51724% with 20 lines in your changes missing coverage. Please review.
Project coverage is 70.13%. Comparing base (
d6d43eb) to head (16b085d). Report is 27 commits behind head on develop.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| app/scripts/controllers/preferences-controller.ts | 65.52% | 20 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #26710 +/- ##
========================================
Coverage 70.13% 70.13%
========================================
Files 1425 1425
Lines 49669 49673 +4
Branches 13895 13897 +2
========================================
+ Hits 34833 34836 +3
- Misses 14836 14837 +1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Builds ready [f23b286]
- 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 (72 ± 10 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 69 | 172 | 98 | 24 | 11 |
| domContentLoaded | 44 | 126 | 66 | 23 | 11 | ||
| load | 51 | 127 | 72 | 21 | 10 | ||
| domInteractive | 10 | 64 | 26 | 13 | 6 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 610 Bytes (0.02%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [0416ba9]
- 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 (1901 ± 109 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 219 | 2560 | 1755 | 536 | 258 |
| domContentLoaded | 1667 | 2453 | 1878 | 202 | 97 | ||
| load | 1701 | 2638 | 1901 | 227 | 109 | ||
| domInteractive | 14 | 107 | 36 | 19 | 9 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 626 Bytes (0.02%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [975f53d]
- 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 (1803 ± 113 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 222 | 2307 | 1731 | 412 | 198 |
| domContentLoaded | 1486 | 2297 | 1773 | 229 | 110 | ||
| load | 1489 | 2310 | 1803 | 234 | 113 | ||
| domInteractive | 23 | 67 | 36 | 14 | 7 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 694 Bytes (0.02%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [f718267]
- 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 (1563 ± 95 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 227 | 2362 | 1440 | 441 | 212 |
| domContentLoaded | 1379 | 2275 | 1550 | 180 | 86 | ||
| load | 1386 | 2368 | 1563 | 197 | 95 | ||
| domInteractive | 21 | 60 | 29 | 10 | 5 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 626 Bytes (0.02%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [fc8725d]
- 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 (2146 ± 105 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 240 | 2526 | 1848 | 682 | 328 |
| domContentLoaded | 1716 | 2526 | 2115 | 221 | 106 | ||
| load | 1731 | 2542 | 2146 | 219 | 105 | ||
| domInteractive | 20 | 106 | 43 | 20 | 10 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 626 Bytes (0.02%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [3999010]
- 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 (1733 ± 54 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 234 | 1995 | 1584 | 463 | 222 |
| domContentLoaded | 1565 | 1958 | 1712 | 106 | 51 | ||
| load | 1575 | 1970 | 1733 | 113 | 54 | ||
| domInteractive | 12 | 87 | 39 | 19 | 9 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 626 Bytes (0.02%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Nit:
We can also update the Controller initialisation in metamask-controller.js to add setSelectedAccount and remove provider from the constructor
const preferencesMessenger = this.controllerMessenger.getRestricted({
name: 'PreferencesController',
allowedActions: [
'AccountsController:setSelectedAccount',
'AccountsController:getAccountByAddress',
'AccountsController:setAccountName',
'AccountsController:setSelectedAccount',
],
allowedEvents: ['AccountsController:stateChange'],
});
this.preferencesController = new PreferencesController({
initState: initState.PreferencesController,
initLangCode: opts.initLangCode,
messenger: preferencesMessenger,
networkConfigurations: this.networkController.state.networkConfigurations,
});
'AccountsController:setSelectedAccount',
It is a small change, we can include, but it is not inline with the task of this PR. I would prefer to create a separate ticket on this and make this change.
Builds ready [38995d2]
- 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 (1826 ± 64 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 239 | 2074 | 1657 | 481 | 231 |
| domContentLoaded | 1593 | 2102 | 1810 | 134 | 65 | ||
| load | 1597 | 2108 | 1826 | 134 | 64 | ||
| domInteractive | 18 | 72 | 36 | 16 | 8 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 457 Bytes (0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [68871a1]
- 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 (1807 ± 92 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 257 | 2512 | 1655 | 497 | 238 |
| domContentLoaded | 1611 | 2442 | 1783 | 185 | 89 | ||
| load | 1640 | 2514 | 1807 | 191 | 92 | ||
| domInteractive | 15 | 73 | 34 | 15 | 7 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 457 Bytes (0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [bb1431f]
- 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 (2058 ± 178 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 277 | 3087 | 2002 | 561 | 269 |
| domContentLoaded | 1547 | 2885 | 2032 | 367 | 176 | ||
| load | 1557 | 2891 | 2058 | 371 | 178 | ||
| domInteractive | 14 | 97 | 40 | 25 | 12 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 457 Bytes (0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [10a6083]
- 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 (1854 ± 204 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 233 | 3306 | 1730 | 668 | 321 |
| domContentLoaded | 1550 | 3002 | 1830 | 396 | 190 | ||
| load | 1555 | 3152 | 1854 | 425 | 204 | ||
| domInteractive | 13 | 207 | 47 | 44 | 21 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 457 Bytes (0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Quality Gate passed
Issues
6 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Builds ready [16b085d]
- 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 (1565 ± 55 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 129 | 1885 | 1430 | 430 | 207 |
| domContentLoaded | 1418 | 1782 | 1542 | 99 | 48 | ||
| load | 1426 | 1899 | 1565 | 114 | 55 | ||
| domInteractive | 18 | 58 | 25 | 8 | 4 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 457 Bytes (0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)