-
Notifications
You must be signed in to change notification settings - Fork 600
feat: Unblock wallet_switchEthereumChain
#2634
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
Changes from all commits
7c49af4
4f3fc66
7230f7c
a7fcfd2
6130c68
da76922
974a72e
e5c7e19
5650fc3
cab235a
aeb51ef
f6923d3
47782a2
55cd2b4
31ffcbf
03a3b7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,23 @@ import { | |
hexToNumber, | ||
} from '@metamask/utils'; | ||
|
||
import type { PersonalSignParams, SignTypedDataParams } from './types'; | ||
import type { | ||
BaseParams, | ||
PersonalSignParams, | ||
SignTypedDataParams, | ||
} from './types'; | ||
|
||
/** | ||
* Set the active Ethereum chain for the Snap. | ||
* | ||
* @param chainId - The chain ID to switch to. | ||
*/ | ||
async function switchChain(chainId: Hex) { | ||
await ethereum.request({ | ||
method: 'wallet_switchEthereumChain', | ||
params: [{ chainId }], | ||
}); | ||
} | ||
|
||
/** | ||
* Get the current gas price using the `ethereum` global. This is essentially | ||
|
@@ -207,6 +223,9 @@ async function signTypedData(message: string, from: string) { | |
* @see https://docs.metamask.io/snaps/reference/rpc-api/#wallet_invokesnap | ||
*/ | ||
export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => { | ||
const { chainId = '0x1' } = (request.params as BaseParams) ?? {}; | ||
await switchChain(chainId); | ||
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. probably not a problem, but i think always using mainnet makes it possible in the extension e2e tests that use this snap to try to hit the mainnet infura endpoint, but I think that's probably only the case if something triggers |
||
|
||
switch (request.method) { | ||
case 'getGasPrice': | ||
return await getGasPrice(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"branches": 93.64, | ||
"branches": 93.67, | ||
"functions": 98.16, | ||
"lines": 98.5, | ||
"lines": 98.51, | ||
"statements": 98.34 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.