metamask-extension icon indicating copy to clipboard operation
metamask-extension copied to clipboard

chore: add wallet state injection and `yarn start:with-state` script

Open seaona opened this issue 1 year ago • 8 comments

Description

With this PR, we add a new script that you can use to build the wallet in dev mode with a preloaded state.

Default Functionality:

  • Run yarn start:with-state - should load a wallet with the SRP and password set in the metamaskrc file, with several controllers data (contacts, transactions, notifications...) defined in the fixtures-config file.

Custom Functionality:

  • Changing the params on the fixtures-config.js file and running again the script, will set each fixture data dynamically (ie withAddressBook, will load xyz contacts, etc)
  • Pasting your own wallet state into the fixtures-state.json and then running the script, will load the file state (and not generate the dynamic fixtures) instead of using the config file
  • These changes will be gitignored

Open in GitHub Codespaces

Future Work:

This sets the base for adding and customizing more wallet state. We can expand this as much as we want. Here are the listed possible future tasks:

  • [ ] Add accounts --> next priority

These is left to interested parties to do (if there is a need):

  • [ ] Add unapproved transactions
  • [ ] Add different kind of transactions (Send Token, Send NFT, Send Legacy etc)
  • [ ] Add unapproved signatures
  • [ ] Add read notifications
  • [ ] Add different kind of notifications (send, received..)

Related issues

Fixes:

Manual testing steps

Check main functionality:

  1. Add a PASSWORD and a TEST_SRP to your metamaskrc file
  2. Run yarn start:with-state
  3. Upload a fresh MM -- see all the fixtures data is loaded

=============================== Check config file:

  1. Go to the fixtures-config.js file
  2. Change some values
  3. Run yarn start:with-state
  4. Upload a fresh MM and open it -- see the changes applied accordingly

=============================== Check json state file:

  1. Go to the fixtures-state.json file
  2. Paste a wallet state (you can export one by pasting this into the console copy(await stateHooks.metamaskGetState()))
  3. Run yarn start:with-state
  4. Upload a fresh MM -- see your wallet json state is applied

Screenshots/Recordings

https://github.com/user-attachments/assets/3ab6035d-8576-4399-8963-867d39e251f6

Pre-merge author checklist

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.

seaona avatar Jul 30 '24 11:07 seaona

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.

github-actions[bot] avatar Jul 30 '24 11:07 github-actions[bot]

Codecov Report

Attention: Patch coverage is 0% with 128 lines in your changes missing coverage. Please review.

Project coverage is 69.90%. Comparing base (c462fb8) to head (46bd784).

Files with missing lines Patch % Lines
app/scripts/fixtures/generate-wallet-state.js 0.00% 86 Missing :warning:
app/scripts/fixtures/with-address-book.js 0.00% 15 Missing :warning:
app/scripts/fixtures/with-unread-notifications.js 0.00% 10 Missing :warning:
...pp/scripts/fixtures/with-confirmed-transactions.js 0.00% 9 Missing :warning:
app/scripts/background.js 0.00% 3 Missing :warning:
app/scripts/fixtures/with-erc20-tokens.js 0.00% 2 Missing :warning:
app/scripts/fixtures/with-app-state.js 0.00% 1 Missing :warning:
app/scripts/fixtures/with-networks.js 0.00% 1 Missing :warning:
app/scripts/fixtures/with-preferences.js 0.00% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26222      +/-   ##
===========================================
- Coverage    70.02%   69.90%   -0.12%     
===========================================
  Files         1443     1450       +7     
  Lines        50162    50249      +87     
  Branches     14039    14046       +7     
===========================================
  Hits         35124    35124              
- Misses       15038    15125      +87     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 30 '24 13:07 codecov[bot]

Builds ready [dabdb0f]
Page Load Metrics (231 ± 230 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint783411145526
domContentLoaded96326147
load511668231478230
domInteractive96326147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 349.72 KiB (10.11%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

metamaskbot avatar Jul 30 '24 13:07 metamaskbot

Builds ready [3ffe5c6]
Page Load Metrics (155 ± 182 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint662351013718
domContentLoaded9169293617
load391796155379182
domInteractive9169293617
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 409.85 KiB (11.85%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

metamaskbot avatar Jul 31 '24 10:07 metamaskbot

Builds ready [14c8f4c]
Page Load Metrics (89 ± 9 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint771481152010
domContentLoaded5012486209
load5712889189
domInteractive126731136
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 380.52 KiB (9.74%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

metamaskbot avatar Aug 19 '24 10:08 metamaskbot

Builds ready [e793540]
Page Load Metrics (74 ± 9 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint601291002010
domContentLoaded39112702010
load4611274189
domInteractive86726147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 381.08 KiB (9.75%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

metamaskbot avatar Aug 19 '24 15:08 metamaskbot

Builds ready [3e9ddff]
Page Load Metrics (75 ± 8 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint81148102157
domContentLoaded5113070189
load5813075178
domInteractive187429136
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 285.71 KiB (7.90%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

metamaskbot avatar Aug 27 '24 11:08 metamaskbot

Builds ready [dd598ba]
Page Load Metrics (67 ± 7 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6613189178
domContentLoaded3910664168
load4510667157
domInteractive9312352
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 285.6 KiB (7.90%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

metamaskbot avatar Sep 03 '24 12:09 metamaskbot

Hi @seaona , i tested on your branch, i encountered a issue that the ERC20 tokens are not displayed, not sure what's the problem, could you have a look? Thanks !

https://github.com/user-attachments/assets/9d7d9e28-15f1-4228-995e-c13dc6d56380

chloeYue avatar Sep 06 '24 12:09 chloeYue

Hi @seaona , i tested on your branch, i encountered a issue that the ERC20 tokens are not displayed, not sure what's the problem, could you have a look? Thanks !

whoaa nice catch :heart_eyes: thank you @chloeYue ! the logic for substituting the account address was not correct, so it was appearing only in mine since the address was hardcoded. Now it should be fixed

seaona avatar Sep 09 '24 09:09 seaona

Builds ready [27c2962]
Page Load Metrics (1739 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15312084174213766
domContentLoaded15222077172313665
load15312086173913565
domInteractive169137188
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 289.18 KiB (8.48%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

metamaskbot avatar Sep 09 '24 10:09 metamaskbot

Test ok on latest commit, ERC20 tokens are displayed:

Screenshot 2024-09-11 at 15 00 57

chloeYue avatar Sep 11 '24 13:09 chloeYue

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots

See analysis details on SonarCloud

sonarqubecloud[bot] avatar Sep 17 '24 21:09 sonarqubecloud[bot]

Builds ready [46bd784]
Page Load Metrics (1742 ± 86 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint23420691529564271
domContentLoaded14472048172517383
load14552059174218086
domInteractive1495392311
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 274.33 KiB (7.75%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

metamaskbot avatar Sep 17 '24 21:09 metamaskbot

Test OK on the latest branch status !

chloeYue avatar Sep 18 '24 15:09 chloeYue

Missing release label release-12.5.0 on PR. Adding release label release-12.5.0 on PR and removing other release labels(release-12.6.0), as PR was added to branch 12.5.0 when release was cut.

metamaskbot avatar Sep 29 '24 17:09 metamaskbot