From edf8a30b4dff6fd56033d51fc8fc4fee6810d3a3 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 30 Jan 2025 12:11:58 +0100 Subject: [PATCH 1/3] Update provider detection to use `wallet_getSnaps` --- src/utils/snaps.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/snaps.ts b/src/utils/snaps.ts index bd8058a4fd..9b99340c1a 100644 --- a/src/utils/snaps.ts +++ b/src/utils/snaps.ts @@ -19,7 +19,7 @@ export type Fields = { }; /** - * 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`. @@ -30,7 +30,7 @@ export async function hasSnapsSupport( ) { try { await provider.request({ - method: 'wallet_getAllSnaps', + method: 'wallet_getSnaps', }); return true; From 1fff3158d091c6c5daea5dfb72208e50e5786800 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 30 Jan 2025 12:18:03 +0100 Subject: [PATCH 2/3] Update tests --- src/components/InstallSnapButton.test.tsx | 10 ++++++---- src/hooks/useSupportedVersion.test.ts | 4 ++-- src/utils/snaps.test.ts | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/InstallSnapButton.test.tsx b/src/components/InstallSnapButton.test.tsx index c32ce21c6a..a5a8e7d899 100644 --- a/src/components/InstallSnapButton.test.tsx +++ b/src/components/InstallSnapButton.test.tsx @@ -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 */ }), @@ -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 */ }), @@ -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]: { @@ -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 */ @@ -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 */ @@ -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 */ diff --git a/src/hooks/useSupportedVersion.test.ts b/src/hooks/useSupportedVersion.test.ts index d7ee94cc06..73c1889317 100644 --- a/src/hooks/useSupportedVersion.test.ts +++ b/src/hooks/useSupportedVersion.test.ts @@ -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 */ }), @@ -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 */ }), diff --git a/src/utils/snaps.test.ts b/src/utils/snaps.test.ts index ca9c63b61a..aba678488d 100644 --- a/src/utils/snaps.test.ts +++ b/src/utils/snaps.test.ts @@ -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); @@ -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, ], @@ -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', { @@ -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, ], From 6ec82cc3e037343fb0dc87121670867465f183cb Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 30 Jan 2025 12:20:42 +0100 Subject: [PATCH 3/3] Update array return value to object --- src/components/InstallSnapButton.test.tsx | 10 +++++----- src/hooks/useSupportedVersion.test.ts | 2 +- src/utils/snaps.test.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/InstallSnapButton.test.tsx b/src/components/InstallSnapButton.test.tsx index a5a8e7d899..106730d54c 100644 --- a/src/components/InstallSnapButton.test.tsx +++ b/src/components/InstallSnapButton.test.tsx @@ -16,7 +16,7 @@ describe('InstallSnapButton', () => { Object.assign(globalThis, 'window', { ethereum: getRequestMethodMock({ /* eslint-disable @typescript-eslint/naming-convention */ - wallet_getSnaps: [], + wallet_getSnaps: {}, web3_clientVersion: 'MetaMask/v11.0.0', /* eslint-enable @typescript-eslint/naming-convention */ }), @@ -55,7 +55,7 @@ describe('InstallSnapButton', () => { Object.assign(globalThis, 'window', { ethereum: getRequestMethodMock({ /* eslint-disable @typescript-eslint/naming-convention */ - wallet_getSnaps: [], + wallet_getSnaps: {}, web3_clientVersion: 'MetaMask/v11.0.0', wallet_requestSnaps: { [snap.snapId]: { @@ -91,7 +91,7 @@ describe('InstallSnapButton', () => { Object.assign(globalThis, 'window', { ethereum: getRequestMethodMock({ /* eslint-disable @typescript-eslint/naming-convention */ - wallet_getSnaps: [], + wallet_getSnaps: {}, web3_clientVersion: 'MetaMask/v11.0.0', wallet_requestSnaps: new Error('User rejected the request.'), /* eslint-enable @typescript-eslint/naming-convention */ @@ -123,7 +123,7 @@ describe('InstallSnapButton', () => { Object.assign(globalThis, 'window', { ethereum: getRequestMethodMock({ /* eslint-disable @typescript-eslint/naming-convention */ - wallet_getSnaps: [], + wallet_getSnaps: {}, wallet_getAllSnaps: [{ id: snap.snapId, version: '0.1.0' }], web3_clientVersion: 'MetaMask/v11.0.0', /* eslint-enable @typescript-eslint/naming-convention */ @@ -149,7 +149,7 @@ describe('InstallSnapButton', () => { Object.assign(globalThis, 'window', { ethereum: getRequestMethodMock({ /* eslint-disable @typescript-eslint/naming-convention */ - wallet_getSnaps: [], + wallet_getSnaps: {}, wallet_getAllSnaps: [{ id: snap.snapId, version: snap.latestVersion }], web3_clientVersion: 'MetaMask/v11.0.0', /* eslint-enable @typescript-eslint/naming-convention */ diff --git a/src/hooks/useSupportedVersion.test.ts b/src/hooks/useSupportedVersion.test.ts index 73c1889317..83d3d9a796 100644 --- a/src/hooks/useSupportedVersion.test.ts +++ b/src/hooks/useSupportedVersion.test.ts @@ -29,7 +29,7 @@ describe('useSupportedVersion', () => { Object.assign(globalThis, 'window', { ethereum: getRequestMethodMock({ /* eslint-disable @typescript-eslint/naming-convention */ - wallet_getSnaps: [], + wallet_getSnaps: {}, web3_clientVersion: 'MetaMask/v11.0.0', /* eslint-enable @typescript-eslint/naming-convention */ }), diff --git a/src/utils/snaps.test.ts b/src/utils/snaps.test.ts index aba678488d..65b25aca8b 100644 --- a/src/utils/snaps.test.ts +++ b/src/utils/snaps.test.ts @@ -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_getSnaps: [], + wallet_getSnaps: {}, }); Object.defineProperty(globalThis, 'window', {