Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix granted permissions when adding an existing network via wallet_addEthereumChain #29837

Merged
merged 29 commits into from
Jan 31, 2025

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Jan 21, 2025

Description

Fixes bug with the automatically permittedChains permission grant when triggered via wallet_addEthereumChain in certain scenarios. See ticket for details.

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3814

Manual testing steps

  1. Add a new network to the dapp via wallet_addEthereumChain
  2. After approval, the dapp should also have endowment:permitted-chains permission for the recently added chain via wallet_getPermissions
  3. switch the dapp to a different chain via the wallet UI
  4. revoke dapp permissions via the wallet UI
  5. Add a new network to the dapp via wallet_addEthereumChain using a DIFFERENT rpc endpoint, but for the same chainId added in step 1
  6. After approval, the dapp should also have endowment:permitted-chains permission for the recently added chain via wallet_getPermissions
  7. switch the dapp to a different chain via the wallet UI
  8. revoke dapp permissions via the wallet UI
  9. Add a new network to the dapp via wallet_addEthereumChain using the SAME rpc endpoint in step 1 (i.e. repeat step 1 exactly)
  10. You should get an approval for chain switch, NOT network adding. Approve it.
  11. After approval, the dapp should also have endowment:permitted-chains permission for the recently added chain via wallet_getPermissions

Screenshots/Recordings

Before

After

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.

Copy link
Contributor

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.

@jiexi jiexi changed the title fix grant permissions add ethereum chain fix: fix granted permissions when adding an existing network via wallet_addEthereumChain Jan 21, 2025
@jiexi jiexi marked this pull request as ready for review January 21, 2025 23:40
@metamaskbot
Copy link
Collaborator

Builds ready [9097ee2]
Page Load Metrics (2286 ± 92 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint28624521405901432
domContentLoaded19112604225318288
load19262703228619192
domInteractive29130672713
backgroundConnect8114352814
firstReactRender27115682713
getState684232311
initialActions00000
loadScripts14582034171415776
setupStore873222311
uiStartup236233782731294141
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 94 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [fcc79fc]
Page Load Metrics (1893 ± 92 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint27521011723460221
domContentLoaded16042361187119393
load16162372189319292
domInteractive25124462914
backgroundConnect55019147
firstReactRender1689452713
getState56721209
initialActions01000
loadScripts12011749140213967
setupStore56113157
uiStartup175328762241300144
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -417 Bytes (-0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [11f009f]
Page Load Metrics (1794 ± 92 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15302238179218991
domContentLoaded15222219176619292
load15392241179419292
domInteractive2595472110
backgroundConnect95624168
firstReactRender1594532713
getState66414157
initialActions01000
loadScripts11441734133416579
setupStore65714167
uiStartup171825462052227109
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -417 Bytes (-0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

jiexi added 3 commits January 22, 2025 14:37
…s-add-ethereum-chain' into jl/mmp-3814/fix-grant-permissions-add-ethereum-chain
…s-add-ethereum-chain' into jl/mmp-3814/fix-grant-permissions-add-ethereum-chain
);
});

it('automatically switches to the chain when the rpc endpoint being added already exists for the chain', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will just highlight the case that (I think) we're missing here, which I've manually tested is, if the rpcEndpoint exists but is not currently the selected rpcEndpoint,, but the chain is selected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing test case here: #29885

@metamaskbot
Copy link
Collaborator

Builds ready [6b5c973]
Page Load Metrics (1598 ± 58 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint13821850159912259
domContentLoaded13761838158011756
load13811848159812058
domInteractive248536168
backgroundConnect57220199
firstReactRender1680452512
getState45712157
initialActions01000
loadScripts9771347116110148
setupStore54812147
uiStartup15372212183515575
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 7 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@jiexi
Copy link
Contributor Author

jiexi commented Jan 23, 2025

This PR depends on #29864

Above PR has been merged and brought into this branch

@metamaskbot
Copy link
Collaborator

Builds ready [b1b2f8e]
Page Load Metrics (1872 ± 108 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31424871790404194
domContentLoaded159024021837209100
load160024871872225108
domInteractive26123412311
backgroundConnect983352412
firstReactRender1682422412
getState46517168
initialActions01000
loadScripts11261862135818388
setupStore64814136
uiStartup183829192128261125
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -28 Bytes (-0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Add missing test case
Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@metamaskbot
Copy link
Collaborator

Builds ready [a686e2b]
Page Load Metrics (1681 ± 74 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14492137168416881
domContentLoaded14382033165515373
load14522052168115574
domInteractive217835168
backgroundConnect76824199
firstReactRender1693482813
getState470182010
initialActions01000
loadScripts10181491121412359
setupStore68511178
uiStartup16512397196020297
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -28 Bytes (-0.00%)
  • ui: 0 Bytes (0.00%)
  • common: -40.17 KiB (-0.44%)

@adonesky1 adonesky1 enabled auto-merge January 23, 2025 22:00
@metamaskbot
Copy link
Collaborator

Builds ready [060a6cd]
Page Load Metrics (1752 ± 77 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint23021011613464223
domContentLoaded15072068172315876
load15172080175216177
domInteractive258941189
backgroundConnect1092362613
firstReactRender16103463014
getState578212210
initialActions01000
loadScripts10591565126213565
setupStore889202211
uiStartup170628342057280134
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -22 Bytes (-0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@adonesky1 adonesky1 added this pull request to the merge queue Jan 31, 2025
Merged via the queue into main with commit 9dae762 Jan 31, 2025
70 checks passed
@adonesky1 adonesky1 deleted the jl/mmp-3814/fix-grant-permissions-add-ethereum-chain branch January 31, 2025 14:20
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2025
@metamaskbot metamaskbot added the release-12.13.0 Issue or pull request that will be included in release 12.13.0 label Jan 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.13.0 Issue or pull request that will be included in release 12.13.0 team-wallet-api-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants