Skip to content

Commit

Permalink
Chore: update types based on new snap package
Browse files Browse the repository at this point in the history
  • Loading branch information
avivash committed Jun 27, 2023
1 parent 80f056c commit 27439a3
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 33 deletions.
10 changes: 7 additions & 3 deletions packages/adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
"types": "./build/index.d.ts",
"scripts": {
"lint": "tsc --build && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"test": "tsc --build && mocha --colors \"test/**/*.spec.ts\" -n loader=ts-node/esm",
"test:e2e": "pnpm run build && pnpm exec playwright test"
"test": "tsc --build && mocha --colors \"test/**/*.spec.ts\" -n loader=ts-node/esm"
},
"devDependencies": {
"@playwright/test": "^1.35.1",
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-sucrase": "^5.0.1",
"@types/chai": "^4.3.5",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-subset": "^1.3.3",
Expand All @@ -43,6 +46,7 @@
"metamask-testing-tools": "^1.0.1",
"mocha": "^10.2.0",
"playwright-test": "^9.2.0",
"rollup": "^3.25.1",
"sinon": "^15.1.2",
"sinon-chai": "^3.7.0",
"typescript": "5.1.3"
Expand All @@ -62,6 +66,6 @@
]
},
"dependencies": {
"filsnap": "^0.0.1"
"filsnap": "workspace:^0.0.1"
}
}
32 changes: 32 additions & 0 deletions packages/adapter/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { defineConfig } from 'rollup'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
// import snaps from '@metamask/snaps-rollup-plugin'
import sucrase from '@rollup/plugin-sucrase'

export default defineConfig({
input: 'src/index.ts',

output: {
file: './dist/adapter.js',
format: 'umd',
name: '<adapter>',
},
plugins: [
commonjs(),
resolve({
preferBuiltins: false,
browser: true,
}),
sucrase({
exclude: ['test/**/*'],
transforms: ['typescript'],
}),
// snaps.default({
// eval: true,
// stripComments: true,
// manifestPath: './snap.manifest.json',
// writeManifest: true,
// }),
],
})
18 changes: 5 additions & 13 deletions packages/adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import type { SnapConfig } from 'filsnap/src/types.ts'
import {
hasMetaMask,
isMetamaskSnapsSupported,
isSnapInstalled,
} from './utils.ts'
import { MetamaskFilecoinSnap } from './snap.ts'
import type { SnapConfig } from 'filsnap/src/types'
import { hasMetaMask, isMetamaskSnapsSupported, isSnapInstalled } from './utils'
import { MetamaskFilecoinSnap } from './snap'

const defaultSnapOrigin = 'npm:filsnap'

export { MetamaskFilecoinSnap } from './snap.ts'
export {
hasMetaMask,
isMetamaskSnapsSupported,
isSnapInstalled,
} from './utils.ts'
export { MetamaskFilecoinSnap } from './snap'
export { hasMetaMask, isMetamaskSnapsSupported, isSnapInstalled } from './utils'

export type SnapInstallationParamNames = 'version' | string

Expand Down
4 changes: 2 additions & 2 deletions packages/adapter/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type {
SignMessageRawResponse,
SnapConfig,
MessageGasEstimate,
} from 'filsnap/src/types.ts'
} from 'filsnap/src/types'

import type { MetamaskFilecoinSnap } from './snap.ts'
import type { MetamaskFilecoinSnap } from './snap'

/**
* Invoke a snap method
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter/src/snap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FilecoinSnapApi } from 'filsnap/src/types.ts'
import type { FilecoinSnapApi } from 'filsnap/src/types'
import {
calculateGasForMessage,
configure,
Expand All @@ -10,7 +10,7 @@ import {
sendMessage,
signMessage,
signMessageRaw,
} from './methods.ts'
} from './methods'

export class MetamaskFilecoinSnap {
// snap parameters
Expand Down
6 changes: 1 addition & 5 deletions packages/adapter/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { SnapRpcMethodRequest } from 'filsnap/src/types.ts'

declare global {
interface Window {
ethereum: {
isMetaMask: boolean
isUnlocked: Promise<boolean>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
request: <T>(
request: SnapRpcMethodRequest | { method: string; params?: any }
) => Promise<T>
request: <T>(request: { method: string; params?: any }) => Promise<T>
on: (eventName: unknown, callback: unknown) => unknown
}
}
Expand Down
10 changes: 2 additions & 8 deletions packages/adapter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"allowImportingTsExtensions": true
"outDir": "dist"
},
"references": [
{
"path": "../snap"
}
],
"include": ["src"],
"include": ["src", "test"],
"exclude": ["node_modules", "dist", "out"],
"typedocOptions": {
"entryPoints": ["src/index.ts"],
Expand Down

0 comments on commit 27439a3

Please sign in to comment.