From 142d0b0bd756a6d38d76021ed7b96dfebdedbf73 Mon Sep 17 00:00:00 2001 From: mtyszczak <mateusz.tyszczak@gmail.com> Date: Tue, 11 Mar 2025 13:27:16 +0100 Subject: [PATCH] Use snap from npm --- package.json | 4 +--- pnpm-lock.yaml | 9 --------- public/dist/bundle.js | 1 - public/snap.manifest.json | 1 - public/src/assets/icon.svg | 1 - src/utils/wallet/metamask/metamask.ts | 6 +++--- src/utils/wallet/metamask/snap.ts | 4 +++- 7 files changed, 7 insertions(+), 19 deletions(-) delete mode 120000 public/dist/bundle.js delete mode 120000 public/snap.manifest.json delete mode 120000 public/src/assets/icon.svg diff --git a/package.json b/package.json index 1365b7a..cc7fe50 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,7 @@ "license": "MIT", "type": "module", "files": [ - "dist/index.html", - "dist/assets" + "dist" ], "scripts": { "start": "vite", @@ -24,7 +23,6 @@ }, "dependencies": {}, "devDependencies": { - "@hiveio/metamask-snap": "1.0.0", "@hiveio/wax": "1.27.6-rc7-250304235913", "@mdi/js": "^7.4.47", "@metamask/providers": "^16.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 282e338..2e8ca62 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,9 +8,6 @@ importers: .: devDependencies: - '@hiveio/metamask-snap': - specifier: 1.0.0 - version: 1.0.0 '@hiveio/wax': specifier: 1.27.6-rc7-250304235913 version: 1.27.6-rc7-250304235913 @@ -287,10 +284,6 @@ packages: resolution: {integrity: sha1-6fL+OgTwp6MSp0Xm3fwj+kFLzD8=, tarball: https://gitlab.syncad.com/api/v4/projects/198/packages/npm/@hiveio/beekeeper/-/@hiveio/beekeeper-1.27.9-stable.250219154236.tgz} engines: {node: ^20.11 || >= 21.2} - '@hiveio/metamask-snap@1.0.0': - resolution: {integrity: sha1-J1nqU58VQL1u50HG17e3W+ScKMw=, tarball: https://gitlab.syncad.com/api/v4/projects/514/packages/npm/@hiveio/metamask-snap/-/@hiveio/metamask-snap-1.0.0.tgz} - engines: {node: ^20.18.1 || >= 21.2} - '@hiveio/wax@1.27.6-rc7-250304235913': resolution: {integrity: sha1-Dk27ws/cbPd8P+aomJlGCzL98rI=, tarball: https://gitlab.syncad.com/api/v4/projects/419/packages/npm/@hiveio/wax/-/@hiveio/wax-1.27.6-rc7-250304235913.tgz} engines: {node: ^20.11 || >= 21.2} @@ -1639,8 +1632,6 @@ snapshots: '@hiveio/beekeeper@1.27.9-stable.250219154236': {} - '@hiveio/metamask-snap@1.0.0': {} - '@hiveio/wax@1.27.6-rc7-250304235913': dependencies: '@hiveio/beekeeper': 1.27.9-stable.250219154236 diff --git a/public/dist/bundle.js b/public/dist/bundle.js deleted file mode 120000 index 7735287..0000000 --- a/public/dist/bundle.js +++ /dev/null @@ -1 +0,0 @@ -../../node_modules/@hiveio/metamask-snap/dist/bundle.js \ No newline at end of file diff --git a/public/snap.manifest.json b/public/snap.manifest.json deleted file mode 120000 index f36a9f0..0000000 --- a/public/snap.manifest.json +++ /dev/null @@ -1 +0,0 @@ -../node_modules/@hiveio/metamask-snap/snap.manifest.json \ No newline at end of file diff --git a/public/src/assets/icon.svg b/public/src/assets/icon.svg deleted file mode 120000 index 913d594..0000000 --- a/public/src/assets/icon.svg +++ /dev/null @@ -1 +0,0 @@ -../../../node_modules/@hiveio/metamask-snap/src/assets/icon.svg \ No newline at end of file diff --git a/src/utils/wallet/metamask/metamask.ts b/src/utils/wallet/metamask/metamask.ts index d965c29..1da6ed0 100644 --- a/src/utils/wallet/metamask/metamask.ts +++ b/src/utils/wallet/metamask/metamask.ts @@ -1,5 +1,5 @@ import type { MetaMaskInpageProvider } from "@metamask/providers"; -import { defaultSnapOrigin, isLocalSnap } from "./snap"; +import { defaultSnapOrigin, defaultSnapVersion, isLocalSnap } from "./snap"; export type MetamaskSnapData = { permissionName: string; @@ -37,9 +37,9 @@ export class MetamaskWallet { * Request the snap to be installed or reinstalled. * You can check if snap is installed using {@link isInstalled} */ - public async installSnap(version?: string) { + public async installSnap(version: string | undefined = defaultSnapVersion) { const snaps = await this.request('wallet_requestSnaps', { - [defaultSnapOrigin]: version ? { version } : {} + [defaultSnapOrigin]: (typeof version === "undefined" || version.length === 0) ? {} : { version } }) as MetamaskSnapsResponse; this.currentSnap = snaps[defaultSnapOrigin]!; diff --git a/src/utils/wallet/metamask/snap.ts b/src/utils/wallet/metamask/snap.ts index 423a429..8d313df 100644 --- a/src/utils/wallet/metamask/snap.ts +++ b/src/utils/wallet/metamask/snap.ts @@ -6,7 +6,9 @@ * don't. Instead, rename `.env.production.dist` to `.env.production` and set the production URL * there. Running `yarn build` will automatically use the production environment variables. */ -export const defaultSnapOrigin = import.meta.env.SNAP_ORIGIN ?? `local:${window.location.protocol}//${window.location.host}`; +export const defaultSnapOrigin = import.meta.env.SNAP_ORIGIN ?? `npm:@hiveio/metamask-snap`; + +export const defaultSnapVersion: string | undefined = import.meta.env.SNAP_VERSION ?? '1.0.1'; /** * Check if a snap ID is a local snap ID. -- GitLab