Skip to content

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Aug 13, 2024

Explanation

This removes some checks in the SelectedNetworkController which disallow a Snap from using their own network, and default to the globally selected network. After this change, Snaps will be able to select their own network just like websites.

References

Related to MetaMask/MetaMask-planning#2938.

Changelog

@metamask/selected-network-controller

  • CHANGED: Allow Snaps to change own network

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@Mrtenz
Copy link
Member Author

Mrtenz commented Aug 13, 2024

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.0.0-preview-55328a6",
  "@metamask-previews/address-book-controller": "5.0.0-preview-55328a6",
  "@metamask-previews/announcement-controller": "7.0.0-preview-55328a6",
  "@metamask-previews/approval-controller": "7.0.2-preview-55328a6",
  "@metamask-previews/assets-controllers": "37.0.0-preview-55328a6",
  "@metamask-previews/base-controller": "6.0.2-preview-55328a6",
  "@metamask-previews/build-utils": "3.0.0-preview-55328a6",
  "@metamask-previews/chain-controller": "0.1.1-preview-55328a6",
  "@metamask-previews/composable-controller": "7.0.0-preview-55328a6",
  "@metamask-previews/controller-utils": "11.0.2-preview-55328a6",
  "@metamask-previews/ens-controller": "13.0.1-preview-55328a6",
  "@metamask-previews/eth-json-rpc-provider": "4.1.2-preview-55328a6",
  "@metamask-previews/gas-fee-controller": "19.0.1-preview-55328a6",
  "@metamask-previews/json-rpc-engine": "9.0.2-preview-55328a6",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.2-preview-55328a6",
  "@metamask-previews/keyring-controller": "17.1.2-preview-55328a6",
  "@metamask-previews/logging-controller": "5.0.0-preview-55328a6",
  "@metamask-previews/message-manager": "10.0.2-preview-55328a6",
  "@metamask-previews/name-controller": "8.0.0-preview-55328a6",
  "@metamask-previews/network-controller": "20.1.0-preview-55328a6",
  "@metamask-previews/notification-controller": "6.0.0-preview-55328a6",
  "@metamask-previews/notification-services-controller": "0.2.1-preview-55328a6",
  "@metamask-previews/permission-controller": "11.0.0-preview-55328a6",
  "@metamask-previews/permission-log-controller": "3.0.0-preview-55328a6",
  "@metamask-previews/phishing-controller": "10.1.1-preview-55328a6",
  "@metamask-previews/polling-controller": "9.0.1-preview-55328a6",
  "@metamask-previews/preferences-controller": "13.0.1-preview-55328a6",
  "@metamask-previews/profile-sync-controller": "0.2.1-preview-55328a6",
  "@metamask-previews/queued-request-controller": "4.0.0-preview-55328a6",
  "@metamask-previews/rate-limit-controller": "6.0.0-preview-55328a6",
  "@metamask-previews/selected-network-controller": "17.0.0-preview-55328a6",
  "@metamask-previews/signature-controller": "18.0.1-preview-55328a6",
  "@metamask-previews/transaction-controller": "35.1.0-preview-55328a6",
  "@metamask-previews/user-operation-controller": "14.0.1-preview-55328a6"
}

adonesky1 added a commit to MetaMask/metamask-extension that referenced this pull request Aug 23, 2024
adonesky1 added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 24, 2024
adonesky1 added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 27, 2024
adonesky1 added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 28, 2024
adonesky1 added a commit to MetaMask/metamask-mobile that referenced this pull request Sep 4, 2024
adonesky1 added a commit to MetaMask/metamask-mobile that referenced this pull request Sep 11, 2024
@Mrtenz Mrtenz force-pushed the mrtenz/snap-networks branch from 55328a6 to 207cfd8 Compare January 15, 2025 12:05
@Mrtenz
Copy link
Member Author

Mrtenz commented Jan 15, 2025

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "21.0.0-preview-207cfd8",
  "@metamask-previews/address-book-controller": "6.0.2-preview-207cfd8",
  "@metamask-previews/announcement-controller": "7.0.2-preview-207cfd8",
  "@metamask-previews/approval-controller": "7.1.2-preview-207cfd8",
  "@metamask-previews/assets-controllers": "46.0.0-preview-207cfd8",
  "@metamask-previews/base-controller": "7.1.1-preview-207cfd8",
  "@metamask-previews/build-utils": "3.0.2-preview-207cfd8",
  "@metamask-previews/composable-controller": "10.0.0-preview-207cfd8",
  "@metamask-previews/controller-utils": "11.4.5-preview-207cfd8",
  "@metamask-previews/ens-controller": "15.0.1-preview-207cfd8",
  "@metamask-previews/eth-json-rpc-provider": "4.1.7-preview-207cfd8",
  "@metamask-previews/gas-fee-controller": "22.0.2-preview-207cfd8",
  "@metamask-previews/json-rpc-engine": "10.0.2-preview-207cfd8",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.6-preview-207cfd8",
  "@metamask-previews/keyring-controller": "19.0.3-preview-207cfd8",
  "@metamask-previews/logging-controller": "6.0.3-preview-207cfd8",
  "@metamask-previews/message-manager": "11.0.3-preview-207cfd8",
  "@metamask-previews/multichain": "2.0.0-preview-207cfd8",
  "@metamask-previews/name-controller": "8.0.2-preview-207cfd8",
  "@metamask-previews/network-controller": "22.1.1-preview-207cfd8",
  "@metamask-previews/notification-services-controller": "0.16.0-preview-207cfd8",
  "@metamask-previews/permission-controller": "11.0.5-preview-207cfd8",
  "@metamask-previews/permission-log-controller": "3.0.2-preview-207cfd8",
  "@metamask-previews/phishing-controller": "12.3.1-preview-207cfd8",
  "@metamask-previews/polling-controller": "12.0.2-preview-207cfd8",
  "@metamask-previews/preferences-controller": "15.0.1-preview-207cfd8",
  "@metamask-previews/profile-sync-controller": "4.1.0-preview-207cfd8",
  "@metamask-previews/queued-request-controller": "8.0.2-preview-207cfd8",
  "@metamask-previews/rate-limit-controller": "6.0.2-preview-207cfd8",
  "@metamask-previews/remote-feature-flag-controller": "1.3.0-preview-207cfd8",
  "@metamask-previews/selected-network-controller": "20.0.2-preview-207cfd8",
  "@metamask-previews/signature-controller": "23.2.0-preview-207cfd8",
  "@metamask-previews/transaction-controller": "43.0.0-preview-207cfd8",
  "@metamask-previews/user-operation-controller": "22.0.0-preview-207cfd8"
}

@Mrtenz Mrtenz force-pushed the mrtenz/snap-networks branch from 207cfd8 to 12ba192 Compare February 12, 2025 10:12
@Mrtenz
Copy link
Member Author

Mrtenz commented Feb 12, 2025

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "23.0.1-preview-12ba192",
  "@metamask-previews/address-book-controller": "6.0.3-preview-12ba192",
  "@metamask-previews/announcement-controller": "7.0.3-preview-12ba192",
  "@metamask-previews/approval-controller": "7.1.3-preview-12ba192",
  "@metamask-previews/assets-controllers": "49.0.0-preview-12ba192",
  "@metamask-previews/base-controller": "8.0.0-preview-12ba192",
  "@metamask-previews/build-utils": "3.0.3-preview-12ba192",
  "@metamask-previews/composable-controller": "11.0.0-preview-12ba192",
  "@metamask-previews/controller-utils": "11.5.0-preview-12ba192",
  "@metamask-previews/earn-controller": "0.2.1-preview-12ba192",
  "@metamask-previews/ens-controller": "15.0.2-preview-12ba192",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-12ba192",
  "@metamask-previews/gas-fee-controller": "22.0.3-preview-12ba192",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-12ba192",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-12ba192",
  "@metamask-previews/keyring-controller": "19.0.7-preview-12ba192",
  "@metamask-previews/logging-controller": "6.0.4-preview-12ba192",
  "@metamask-previews/message-manager": "12.0.1-preview-12ba192",
  "@metamask-previews/multichain": "2.1.1-preview-12ba192",
  "@metamask-previews/multichain-transactions-controller": "0.3.0-preview-12ba192",
  "@metamask-previews/name-controller": "8.0.3-preview-12ba192",
  "@metamask-previews/network-controller": "22.2.1-preview-12ba192",
  "@metamask-previews/notification-services-controller": "0.20.1-preview-12ba192",
  "@metamask-previews/permission-controller": "11.0.6-preview-12ba192",
  "@metamask-previews/permission-log-controller": "3.0.3-preview-12ba192",
  "@metamask-previews/phishing-controller": "12.3.2-preview-12ba192",
  "@metamask-previews/polling-controller": "12.0.3-preview-12ba192",
  "@metamask-previews/preferences-controller": "15.0.2-preview-12ba192",
  "@metamask-previews/profile-sync-controller": "7.0.1-preview-12ba192",
  "@metamask-previews/queued-request-controller": "9.0.1-preview-12ba192",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-12ba192",
  "@metamask-previews/remote-feature-flag-controller": "1.4.0-preview-12ba192",
  "@metamask-previews/selected-network-controller": "21.0.1-preview-12ba192",
  "@metamask-previews/signature-controller": "23.2.1-preview-12ba192",
  "@metamask-previews/token-search-discovery-controller": "2.1.0-preview-12ba192",
  "@metamask-previews/transaction-controller": "45.1.0-preview-12ba192",
  "@metamask-previews/user-operation-controller": "24.0.1-preview-12ba192"
}

@Mrtenz Mrtenz marked this pull request as ready for review February 18, 2025 15:47
@Mrtenz Mrtenz requested a review from a team as a code owner February 18, 2025 15:47
Copy link
Member

@ffmcgee725 ffmcgee725 left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

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

github-merge-queue bot pushed a commit to MetaMask/snaps that referenced this pull request May 15, 2025
This removes `wallet_switchEthereumChain` from the `BLOCKED_RPC_METHODS`
list.

Closes MetaMask/MetaMask-planning#2938.
Closes #2654.

Blocked by:

- MetaMask/core#4602
@Mrtenz Mrtenz force-pushed the mrtenz/snap-networks branch from b31b7b6 to 01668d1 Compare May 15, 2025 14:03
@Mrtenz Mrtenz merged commit 4a42d7a into main May 15, 2025
205 of 215 checks passed
@Mrtenz Mrtenz deleted the mrtenz/snap-networks branch May 15, 2025 14:09
github-merge-queue bot pushed a commit to MetaMask/snaps that referenced this pull request May 15, 2025
This removes `wallet_switchEthereumChain` from the `BLOCKED_RPC_METHODS`
list.

Closes MetaMask/MetaMask-planning#2938.
Closes #2654.

Blocked by:

- MetaMask/core#4602
Mrtenz added a commit to MetaMask/metamask-extension that referenced this pull request May 19, 2025
Like with websites, we want to support a custom network per Snap rather
than relying on the globally selected network. For Snaps, the permission
for the network to switch to is automatically granted.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26389?quickstart=1)

1. Copy the build files for `@metamask/selected-network-controller` from
[this PR](MetaMask/core#4602).
2. Copy the build files for `@metamask/snaps-controllers` and
`@metamask/snaps-execution-environments` from [this
PR](MetaMask/snaps#2634).
3. Run `test-snaps` for the PR above (`yarn start` in
`packages/test-snaps`).
4. Install the Ethereum Provider Example Snap.
5. Switch the chain ID using the `test-snaps` button for the Ethereum
Provider example.
6. The Snap should now use the new network, without any permission
requests.

Step 1 and 2 are no longer necessary once these PRs are merged and
released.

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

<!-- [screenshots/recordings] -->

<!-- [screenshots/recordings] -->

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants