Skip to content

Commit

Permalink
fix: moved provider type to adapter, updated to mm v12
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Sep 3, 2024
1 parent ad5f28c commit 56da6b5
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 115 deletions.
20 changes: 10 additions & 10 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,30 @@
}
},
"dependencies": {
"@metamask/key-tree": "^9.0.0",
"@metamask/snaps-sdk": "^6.0.0",
"@metamask/key-tree": "^9.1.2",
"@metamask/snaps-sdk": "^6.3.0",
"@paulmillr/qr": "^0.2.0",
"dequal": "^2.0.3",
"iso-base": "^4.0.0",
"iso-filecoin": "^4.1.0",
"merge-options": "^3.0.4",
"sirv-cli": "^2.0.2",
"viem": "^2.17.0",
"viem": "^2.20.1",
"zod": "^3.22.4"
},
"devDependencies": {
"@metamask/approval-controller": "^7.0.0",
"@metamask/approval-controller": "^7.0.2",
"@metamask/snaps-rollup-plugin": "^3.0.0",
"@playwright/test": "^1.45.1",
"@playwright/test": "^1.46.1",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-sucrase": "^5.0.2",
"@rollup/plugin-terser": "^0.4.4",
"metamask-testing-tools": "^1.2.6",
"playwright-test": "^14.1.1",
"rollup": "^4.12.0",
"type-fest": "^4.21.0",
"typescript": "5.5.3"
"metamask-testing-tools": "^2.0.0",
"playwright-test": "^14.1.4",
"rollup": "^4.21.2",
"type-fest": "^4.26.0",
"typescript": "5.5.4"
},
"publishConfig": {
"provenance": true
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
timeout: process.env.CI ? 60 * 1000 : 30 * 1000,
forbidOnly: Boolean(process.env.CI),
retries: process.env.CI ? 2 : 1,
workers: process.env.CI ? 1 : 2,
workers: process.env.CI ? 1 : 1,
reporter: process.env.CI ? [['html'], ['list']] : 'list',
use: {
baseURL: 'http://example.org',
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/filecoin-project/filsnap.git"
},
"source": {
"shasum": "KD3E+tnx/8f/Z4XImMnezw76DxoubGurnxXd8Tslpcc=",
"shasum": "4Hli2ldMXbJmpDd2+MHqlCDBk2zoU2jT5quO3ZyFuh0=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export type {
AccountInfo,
FilSnapMethods,
Network,
RequestWithFilSnap,
SnapConfig,
Snap,
SnapError,
} from './types'

// Disable transaction insight for now
Expand Down
84 changes: 3 additions & 81 deletions packages/snap/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import type {
GetSnapsParams,
JsonRpcError,
JsonRpcParams,
JsonRpcRequest,
Snap,
SnapMethods,
SnapsProvider,
} from '@metamask/snaps-sdk'
import type { SnapsProvider } from '@metamask/snaps-sdk'

import type { accountFromPrivateKey } from 'iso-filecoin/wallet'

import type { z } from 'zod'
import type { configure } from './rpc/configure'
import type { exportPrivateKey } from './rpc/export-private-key'
Expand Down Expand Up @@ -97,75 +91,3 @@ export interface FilSnapMethods {
fil_sendMessage: typeof sendMessage
fil_getAccountInfo: typeof getAccountInfo
}

/**
* Snaps Provider request types
*
* @see https://github.com/MetaMask/snaps/blob/main/packages/snaps-sdk/src/types/methods/methods.ts
*/

export type Method<
MethodName extends string,
Params extends JsonRpcParams,
> = Partial<JsonRpcRequest> & Params extends never
? {
method: MethodName
}
: {
method: MethodName
params: Params
}

/**
* Patched GetSnapsResult
*/
type GetSnapsResult = Record<
string,
| {
error: JsonRpcError
}
| Snap
>

export type AddEthereumChainParameter = {
chainId: string
chainName: string
rpcUrls: string[]
blockExplorerUrls: string[]
nativeCurrency: {
name: string
symbol: string
decimals: number
}
iconUrls: string[]
}

export type CustomSnapsMethos = SnapMethods & {
wallet_getSnaps: [GetSnapsParams, GetSnapsResult]
wallet_switchEthereumChain: [{ chainId: string }[], null]
wallet_addEthereumChain: [[AddEthereumChainParameter], null]
}

export type RequestWithFilSnap = <
MethodName extends keyof CustomSnapsMethos,
SnapMethod extends keyof FilSnapMethods = keyof FilSnapMethods,
>(
args: MethodName extends 'wallet_invokeSnap'
? {
method: MethodName
params: {
request: Parameters<FilSnapMethods[SnapMethod]>[1] extends undefined
? {
method: SnapMethod
}
: {
method: SnapMethod
params: Parameters<FilSnapMethods[SnapMethod]>[1]
}
snapId: string
}
}
: Method<MethodName, CustomSnapsMethos[MethodName][0]>
) => MethodName extends 'wallet_invokeSnap'
? ReturnType<FilSnapMethods[SnapMethod]>
: Promise<CustomSnapsMethos[MethodName][1]>
7 changes: 4 additions & 3 deletions packages/snap/test/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { test, expect } = createFixture({
isolated: true,
downloadOptions: {
flask: true,
tag: 'v11.16.5',
},
snap: {
id: 'local:http://localhost:8081',
Expand All @@ -25,7 +24,8 @@ test.describe('fil_configure', () => {
})

const dialog = await metamask.waitForDialog('confirmation')
await dialog.getByRole('button').filter({ hasText: 'Approve' }).click()
await dialog.getByTestId('confirmation-submit-button').click()
await dialog.getByTestId('confirmation-submit-button').click()

const response = await req
expect(response.result).toStrictEqual({
Expand All @@ -51,7 +51,8 @@ test.describe('fil_configure', () => {
})

const dialog = await metamask.waitForDialog('confirmation')
await dialog.getByRole('button').filter({ hasText: 'Approve' }).click()
await dialog.getByTestId('confirmation-submit-button').click()
await dialog.getByTestId('confirmation-submit-button').click()

const response = await req
expect(response.result).toStrictEqual({
Expand Down
1 change: 0 additions & 1 deletion packages/snap/test/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { test, expect } = createFixture({
isolated: false,
downloadOptions: {
flask: true,
tag: 'v11.16.5',
},
snap: {
id: 'local:http://localhost:8081',
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/test/gas-estimate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { test, expect } = createFixture({
isolated: false,
downloadOptions: {
flask: true,
tag: 'v11.16.5',
},
snap: {
id: 'local:http://localhost:8081',
Expand All @@ -27,7 +26,8 @@ test.beforeAll(async ({ metamask, page }) => {
})

const dialog = await metamask.waitForDialog('confirmation')
await dialog.getByRole('button').filter({ hasText: 'Approve' }).click()
await dialog.getByTestId('confirmation-submit-button').click()
await dialog.getByTestId('confirmation-submit-button').click()

await req
})
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/test/mainnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { test, expect } = createFixture({
isolated: false,
downloadOptions: {
flask: true,
tag: 'v11.16.5',
},
snap: {
id: 'local:http://localhost:8081',
Expand All @@ -24,7 +23,8 @@ test.beforeAll(async ({ metamask, page }) => {
})

const dialog = await metamask.waitForDialog('confirmation')
await dialog.getByRole('button').filter({ hasText: 'Approve' }).click()
await dialog.getByTestId('confirmation-submit-button').click()
await dialog.getByTestId('confirmation-submit-button').click()

await req
})
Expand Down
25 changes: 12 additions & 13 deletions packages/snap/test/methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const { test, expect } = createFixture({
isolated: false,
downloadOptions: {
flask: true,
tag: 'v11.16.5',
},
snap: {
id: 'local:http://localhost:8081',
},
})

test.beforeAll(async ({ metamask, page }) => {
await metamask.page.getByTestId('confirmation-submit-button').click()
const req = metamask.invokeSnap({
request: {
method: 'fil_configure',
Expand All @@ -36,8 +36,7 @@ test.beforeAll(async ({ metamask, page }) => {
})

const dialog = await metamask.waitForDialog('confirmation')
await dialog.getByRole('button').filter({ hasText: 'Approve' }).click()

await dialog.getByTestId('confirmation-submit-button').click()
await req
})

Expand Down Expand Up @@ -74,11 +73,11 @@ test.describe('filsnap testnet', () => {
page,
})

const dialog1 = await metamask.waitForDialog('confirmation')
await dialog1.getByRole('button').filter({ hasText: 'Approve' }).click()
let popup = await metamask.waitForDialog('confirmation')
await popup.getByTestId('confirmation-submit-button').click()
popup = await metamask.waitForDialog('confirmation')
await popup.getByTestId('confirmation-submit-button').click()

const dialog2 = await metamask.waitForDialog('confirmation')
await dialog2.locator('.confirmation-footer__actions > button').click()
const { result } = await privateKey

expect(result).toBe(true)
Expand All @@ -104,8 +103,8 @@ test.describe('filsnap testnet', () => {
page,
})

const dialog = await metamask.waitForDialog('confirmation')
await dialog.getByRole('button').filter({ hasText: 'Approve' }).click()
const popup = await metamask.waitForDialog('confirmation')
await popup.getByTestId('confirmation-submit-button').click()
const { result } = await signRaw

expect(result).toStrictEqual(
Expand Down Expand Up @@ -141,8 +140,8 @@ test.describe('filsnap testnet', () => {
page,
})

const dialog = await metamask.waitForDialog('confirmation')
await dialog.getByRole('button').filter({ hasText: 'Approve' }).click()
const popup = await metamask.waitForDialog('confirmation')
await popup.getByTestId('confirmation-submit-button').click()
const { result } = await sign

if (result == null) {
Expand Down Expand Up @@ -179,8 +178,8 @@ test.describe('filsnap testnet', () => {
page,
})

const dialog = await metamask.waitForDialog('confirmation')
await dialog.getByRole('button').filter({ hasText: 'Approve' }).click()
const popup = await metamask.waitForDialog('confirmation')
await popup.getByTestId('confirmation-submit-button').click()
const signedMessageResponse = await invoke

if (signedMessageResponse.error != null) {
Expand Down

0 comments on commit 56da6b5

Please sign in to comment.