-
Notifications
You must be signed in to change notification settings - Fork 5k
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
feat(snaps): Add support for custom network per Snap #26389
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b98184
Add support for custom network per Snap
Mrtenz 751a679
Remove console.log
Mrtenz ffc0b42
Add migration adding permission to the Snap and setting the Snap's cu…
Mrtenz 3905e57
Update migration
Mrtenz 7f2494b
Add another test
Mrtenz 6453f80
Fix lint issues
Mrtenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -528,6 +528,7 @@ export default class MetamaskController extends EventEmitter { | |
trackMetaMetricsEvent: (...args) => | ||
this.metaMetricsController.trackEvent(...args), | ||
}); | ||
|
||
this.networkController.initializeProvider(); | ||
this.provider = | ||
this.networkController.getProviderAndBlockTracker().provider; | ||
|
@@ -5502,6 +5503,25 @@ export default class MetamaskController extends EventEmitter { | |
}, | ||
}, | ||
), | ||
grantPermittedChainsPermission: (chainIds) => { | ||
this.permissionController.grantPermissionsIncremental({ | ||
subject: { | ||
origin, | ||
}, | ||
requestData: { | ||
approvedChainIds: chainIds, | ||
}, | ||
approvedPermissions: { | ||
[PermissionNames.permittedChains]: { | ||
caveats: [ | ||
CaveatFactories[CaveatTypes.restrictNetworkSwitching]( | ||
chainIds, | ||
), | ||
], | ||
}, | ||
Comment on lines
+5511
to
+5521
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems a bit strange that we have to specify the chain IDs twice 🤔 Seems like the permission specification strictly uses |
||
}, | ||
}); | ||
}, | ||
requestPermissionsForOrigin: | ||
this.permissionController.requestPermissions.bind( | ||
this.permissionController, | ||
|
@@ -5550,9 +5570,11 @@ export default class MetamaskController extends EventEmitter { | |
), | ||
setActiveNetwork: async (networkClientId) => { | ||
await this.networkController.setActiveNetwork(networkClientId); | ||
// if the origin has the eth_accounts permission | ||
// we set per dapp network selection state | ||
|
||
// If the origin has the `eth_accounts` permission, or if it's a Snap, | ||
// we set per origin network selection state. | ||
if ( | ||
subjectType === SubjectType.Snap || | ||
this.permissionController.hasPermission( | ||
origin, | ||
PermissionNames.eth_accounts, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we test this functionality?