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

Update provider detection to use wallet_getSnaps #528

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/components/InstallSnapButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('InstallSnapButton', () => {
Object.assign(globalThis, 'window', {
ethereum: getRequestMethodMock({
/* eslint-disable @typescript-eslint/naming-convention */
wallet_getAllSnaps: [],
wallet_getSnaps: [],
web3_clientVersion: 'MetaMask/v11.0.0',
/* eslint-enable @typescript-eslint/naming-convention */
}),
Expand All @@ -35,7 +35,7 @@ describe('InstallSnapButton', () => {
Object.assign(globalThis, 'window', {
ethereum: getRequestMethodMock({
/* eslint-disable @typescript-eslint/naming-convention */
wallet_getAllSnaps: new Error('Snaps are not supported.'),
wallet_getSnaps: new Error('Snaps are not supported.'),
web3_clientVersion: 'MetaMask/v10.0.0',
/* eslint-enable @typescript-eslint/naming-convention */
}),
Expand All @@ -55,7 +55,7 @@ describe('InstallSnapButton', () => {
Object.assign(globalThis, 'window', {
ethereum: getRequestMethodMock({
/* eslint-disable @typescript-eslint/naming-convention */
wallet_getAllSnaps: [],
wallet_getSnaps: [],
web3_clientVersion: 'MetaMask/v11.0.0',
wallet_requestSnaps: {
[snap.snapId]: {
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('InstallSnapButton', () => {
Object.assign(globalThis, 'window', {
ethereum: getRequestMethodMock({
/* eslint-disable @typescript-eslint/naming-convention */
wallet_getAllSnaps: [],
wallet_getSnaps: [],
web3_clientVersion: 'MetaMask/v11.0.0',
wallet_requestSnaps: new Error('User rejected the request.'),
/* eslint-enable @typescript-eslint/naming-convention */
Expand Down Expand Up @@ -123,6 +123,7 @@ describe('InstallSnapButton', () => {
Object.assign(globalThis, 'window', {
ethereum: getRequestMethodMock({
/* eslint-disable @typescript-eslint/naming-convention */
wallet_getSnaps: [],
wallet_getAllSnaps: [{ id: snap.snapId, version: '0.1.0' }],
web3_clientVersion: 'MetaMask/v11.0.0',
/* eslint-enable @typescript-eslint/naming-convention */
Expand All @@ -148,6 +149,7 @@ describe('InstallSnapButton', () => {
Object.assign(globalThis, 'window', {
ethereum: getRequestMethodMock({
/* eslint-disable @typescript-eslint/naming-convention */
wallet_getSnaps: [],
wallet_getAllSnaps: [{ id: snap.snapId, version: snap.latestVersion }],
web3_clientVersion: 'MetaMask/v11.0.0',
/* eslint-enable @typescript-eslint/naming-convention */
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useSupportedVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('useSupportedVersion', () => {
Object.assign(globalThis, 'window', {
ethereum: getRequestMethodMock({
/* eslint-disable @typescript-eslint/naming-convention */
wallet_getAllSnaps: new Error('Unsupported method.'),
wallet_getSnaps: new Error('Unsupported method.'),
web3_clientVersion: 'MetaMask/v11.0.0',
/* eslint-enable @typescript-eslint/naming-convention */
}),
Expand All @@ -29,7 +29,7 @@ describe('useSupportedVersion', () => {
Object.assign(globalThis, 'window', {
ethereum: getRequestMethodMock({
/* eslint-disable @typescript-eslint/naming-convention */
wallet_getAllSnaps: [],
wallet_getSnaps: [],
web3_clientVersion: 'MetaMask/v11.0.0',
/* eslint-enable @typescript-eslint/naming-convention */
}),
Expand Down
8 changes: 4 additions & 4 deletions src/utils/snaps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('hasSnapsSupport', () => {
it('returns `false` if the provider does not support Snaps', async () => {
const provider = getRequestMethodMock({
// eslint-disable-next-line @typescript-eslint/naming-convention
wallet_getAllSnaps: new Error('Unsupported method.'),
wallet_getSnaps: new Error('Unsupported method.'),
});

expect(await hasSnapsSupport(provider)).toBe(false);
Expand Down Expand Up @@ -249,7 +249,7 @@ describe('getSnapsProvider', () => {
detected: [
getRequestMethodMock({
// eslint-disable-next-line @typescript-eslint/naming-convention
wallet_getAllSnaps: new Error('Unsupported method.'),
wallet_getSnaps: new Error('Unsupported method.'),
}),
provider,
],
Expand All @@ -263,7 +263,7 @@ describe('getSnapsProvider', () => {
it('returns the provider if it is in the `window.ethereum.providers` array', async () => {
const provider = getRequestMethodMock({
// eslint-disable-next-line @typescript-eslint/naming-convention
wallet_getAllSnaps: [],
wallet_getSnaps: [],
});

Object.defineProperty(globalThis, 'window', {
Expand All @@ -273,7 +273,7 @@ describe('getSnapsProvider', () => {
providers: [
getRequestMethodMock({
// eslint-disable-next-line @typescript-eslint/naming-convention
wallet_getAllSnaps: new Error('Unsupported method.'),
wallet_getSnaps: new Error('Unsupported method.'),
}),
provider,
],
Expand Down
4 changes: 2 additions & 2 deletions src/utils/snaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type Fields<Query, Name extends keyof Query> = {
};

/**
* Check if the current provider supports snaps by calling `wallet_getAllSnaps`.
* Check if the current provider supports snaps by calling `wallet_getSnaps`.
*
* @param provider - The provider to use to check for snaps support. Defaults to
* `window.ethereum`.
Expand All @@ -30,7 +30,7 @@ export async function hasSnapsSupport(
) {
try {
await provider.request({
method: 'wallet_getAllSnaps',
method: 'wallet_getSnaps',
});

return true;
Expand Down
Loading