Skip to content

Commit

Permalink
add metamask snap
Browse files Browse the repository at this point in the history
  • Loading branch information
AZbang committed Jul 18, 2023
1 parent f5fb260 commit 48f03d7
Show file tree
Hide file tree
Showing 21 changed files with 766 additions and 29 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ yarn add \
@near-wallet-selector/sender \
@near-wallet-selector/nearfi \
@near-wallet-selector/here-wallet \
@near-wallet-selector/metamask-snap \
@near-wallet-selector/math-wallet \
@near-wallet-selector/nightly \
@near-wallet-selector/meteor-wallet \
Expand All @@ -81,6 +82,7 @@ npm install \
@near-wallet-selector/sender \
@near-wallet-selector/nearfi \
@near-wallet-selector/here-wallet \
@near-wallet-selector/metamask-snap \
@near-wallet-selector/math-wallet \
@near-wallet-selector/nightly \
@near-wallet-selector/meteor-wallet \
Expand Down Expand Up @@ -117,6 +119,7 @@ import { setupNearWallet } from "@near-wallet-selector/near-wallet";
import { setupMyNearWallet } from "@near-wallet-selector/my-near-wallet";
import { setupSender } from "@near-wallet-selector/sender";
import { setupHereWallet } from "@near-wallet-selector/here-wallet";
import { setupMetamaskSnap } from "@near-wallet-selector/metamask-snap";
import { setupMathWallet } from "@near-wallet-selector/math-wallet";
import { setupNightly } from "@near-wallet-selector/nightly";
import { setupMeteorWallet } from "@near-wallet-selector/meteor-wallet";
Expand All @@ -140,6 +143,7 @@ const selector = await setupWalletSelector({
setupMyNearWallet(),
setupSender(),
setupHereWallet(),
setupMetamaskSnap(),
setupMathWallet(),
setupNightly(),
setupMeteorWallet(),
Expand Down
12 changes: 7 additions & 5 deletions examples/react/contexts/WalletSelectorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import { setupSender } from "@near-wallet-selector/sender";
import { setupWalletConnect } from "@near-wallet-selector/wallet-connect";
import { setupNearSnap } from "@near-wallet-selector/near-snap";
import { setupWelldoneWallet } from "@near-wallet-selector/welldone-wallet";
import { setupMetamaskSnap } from '@near-wallet-selector/metamask-snap';

Check failure on line 18 in examples/react/contexts/WalletSelectorContext.tsx

View workflow job for this annotation

GitHub Actions / Test Suite

Replace `'@near-wallet-selector/metamask-snap'` with `"@near-wallet-selector/metamask-snap"`
import { setupNeth } from "@near-wallet-selector/neth";
import { setupOptoWallet } from "@near-wallet-selector/opto-wallet";
import { setupFinerWallet } from "@near-wallet-selector/finer-wallet";
import { setupMyNearWallet } from "@near-wallet-selector/my-near-wallet";
import { setupLedger } from "@near-wallet-selector/ledger";
import { setupXDEFI } from "@near-wallet-selector/xdefi";
import type { ReactNode } from "react";
import React, {
Expand All @@ -26,12 +32,7 @@ import React, {
} from "react";
import { distinctUntilChanged, map } from "rxjs";

import { setupNeth } from "@near-wallet-selector/neth";
import { setupOptoWallet } from "@near-wallet-selector/opto-wallet";
import { setupFinerWallet } from "@near-wallet-selector/finer-wallet";
import { Loading } from "../components/Loading";
import { setupMyNearWallet } from "@near-wallet-selector/my-near-wallet";
import { setupLedger } from "@near-wallet-selector/ledger";
import { CONTRACT_ID } from "../constants";

declare global {
Expand Down Expand Up @@ -71,6 +72,7 @@ export const WalletSelectorContextProvider: React.FC<{
setupMathWallet(),
setupNightly(),
setupMeteorWallet(),
setupMetamaskSnap({}),
setupNearSnap(),
setupNarwallets(),
setupWelldoneWallet(),
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"build:xdefi-wallet": "nx run-many --target=build --projects=xdefi --configuration=production",
"build:wallet-utils": "nx run-many --target=build --projects=wallet-utils --configuration=production",
"build:default-wallets": "nx run-many --target=build --projects=default-wallets --configuration=production",
"build:metamask-snap": "nx run-many --target=build --projects=metamask-snap --configuration=production",
"build:near-snap": "nx run-many --target=build --projects=near-snap --configuration=production",
"build:account-export": "nx run-many --target=build --projects=account-export --configuration=production",
"lint": "nx workspace-lint && nx run-many --target=lint --all --parallel",
Expand All @@ -89,12 +90,14 @@
"@ledgerhq/hw-transport-webhid": "6.27.16",
"@metamask/detect-provider": "^2.0.0",
"@meteorwallet/sdk": "^0.8.0",
"@near-snap/sdk": "^0.4.0",
"@nightlylabs/connect-near": "0.0.15",
"@walletconnect/sign-client": "2.8.6",
"@web3modal/standalone": "^2.2.2",
"better-sqlite3": "^8.4.0",
"big.js": "^6.1.1",
"bn.js": "^5.2.0",
"browserify-fs": "^1.0.0",
"bs58": "^5.0.0",
"buffer": "^6.0.3",
"copy-to-clipboard": "^3.3.3",
Expand Down Expand Up @@ -136,6 +139,7 @@
"@nrwl/rollup": "16.0.0",
"@nrwl/tao": "16.0.0",
"@nrwl/webpack": "16.0.0",
"@nx/angular": "16.0.0",
"@nx/cypress": "16.0.0",
"@nx/eslint-plugin": "16.0.0",
"@nx/jest": "16.0.0",
Expand Down Expand Up @@ -204,7 +208,6 @@
"url-loader": "^4.1.1",
"uuid": "^9.0.0",
"webpack": "^5.75.0",
"webpack-merge": "^5.8.0",
"@nx/angular": "16.0.0"
"webpack-merge": "^5.8.0"
}
}
10 changes: 10 additions & 0 deletions packages/metamask-snap/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nrwl/js/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions packages/metamask-snap/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
65 changes: 65 additions & 0 deletions packages/metamask-snap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# @near-wallet-selector/metamask-snap

This is the NEAR Metamask Snap package for NEAR Wallet Selector.

## Installation and Usage

The easiest way to use this package is to install it from the NPM registry, this package requires `near-api-js` v1.0.0 or above:

```bash
# Using Yarn
yarn add near-api-js

# Using NPM.
npm install near-api-js
```

```bash
# Using Yarn
yarn add @near-wallet-selector/metamask-snap

# Using NPM.
npm install @near-wallet-selector/metamask-snap
```

Then use it in your dApp:

```ts
import { setupWalletSelector } from "@near-wallet-selector/core";
import { setupMetamaskSnap } from "@near-wallet-selector/metamask-snap";

const selector = await setupWalletSelector({
network: "testnet",
modules: [setupMetamaskSnap()],
});
```


## Here Wallet JS SDK

The library uses @near-snap/sdk, you can read more about the functionality here:
https://github.com/here-wallet/near-snap


## Options

- `iconUrl`: (`string?`): Icon is optional. Default image point to Here Wallet Logo in base64 format.
- `deprecated`: (`boolean?`): Deprecated is optional. Default is `false`.

## Assets

Assets such as icons can be found in the `/assets` directory of the package. Below is an example using Webpack:

```ts
import { setupMetamaskSnap } from "@near-wallet-selector/metamask-snap";
import SnapIconUrl from "@near-wallet-selector/metamask-snap/assets/snap-icon.png";

const snapWallet = setupMetamaskSnap({
iconUrl: SnapIconUrl
});

```

## License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
Binary file added packages/metamask-snap/assets/snap-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions packages/metamask-snap/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: "metamask-snap",
preset: "../../jest.preset.js",
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tsconfig.spec.json",
},
},
transform: {
"^.+\\.[tj]sx?$": "ts-jest",
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
coverageDirectory: "../../coverage/packages/metamask-snap",
};
16 changes: 16 additions & 0 deletions packages/metamask-snap/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
export default {
displayName: "metamask-snap",
preset: "../../jest.preset.js",
globals: {},
transform: {
"^.+\\.[tj]s$": [
"ts-jest",
{
tsconfig: "<rootDir>/tsconfig.spec.json",
},
],
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
coverageDirectory: "../../coverage/packages/metamask-snap",
};
30 changes: 30 additions & 0 deletions packages/metamask-snap/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@near-wallet-selector/metamask-snap",
"version": "8.2.0",
"description": "Metamask Near Snap package for NEAR Wallet Selector.",
"keywords": [
"near",
"blockchain",
"wallets",
"dapps",
"near-protocol",
"near-blockchain",
"wallet selector",
"injected wallet",
"metamask"
],
"repository": {
"type": "git",
"url": "https://github.com/near/wallet-selector.git"
},
"bugs": {
"url": "https://github.com/near/wallet-selector/issues"
},
"homepage": "https://github.com/near/wallet-selector/tree/main/packages/metamask-snap",
"peerDependencies": {
"near-api-js": "^1.0.0 || ^2.0.0"
},
"dependencies": {
"@near-snap/sdk": "^0.2.1"
}
}
55 changes: 55 additions & 0 deletions packages/metamask-snap/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "metamask-snap",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/metamask-snap/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/metamask-snap",
"tsConfig": "packages/metamask-snap/tsconfig.lib.json",
"project": "packages/metamask-snap/package.json",
"entryFile": "packages/metamask-snap/src/index.ts",
"buildableProjectDepsInPackageJsonType": "dependencies",
"compiler": "babel",
"format": ["esm", "cjs"],
"assets": [
{
"glob": "packages/metamask-snap/README.md",
"input": ".",
"output": "."
},
{
"glob": "packages/metamask-snap/assets/*",
"input": ".",
"output": "assets"
}
]
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/metamask-snap/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/packages/metamask-snap"],
"options": {
"jestConfig": "packages/metamask-snap/jest.config.ts",
"passWithNoTests": true
}
},
"deploy": {
"executor": "ngx-deploy-npm:deploy",
"options": {
"access": "public"
}
}
},
"tags": ["browser-wallet"]
}
1 change: 1 addition & 0 deletions packages/metamask-snap/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { setupMetamaskSnap } from "./lib";
1 change: 1 addition & 0 deletions packages/metamask-snap/src/lib/icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzFfNCkiPgo8cGF0aCBkPSJNMTcuMDM3IDBINi45NzQ5OUMyLjYwNTA0IDAgLTkuNTM2NzNlLTA3IDIuNjE1NjkgLTkuNTM2NzNlLTA3IDYuOTgzNTFWMTcuMDI4NUMtOS41MzY3M2UtMDcgMjEuMzk2MyAyLjYwNTA0IDI0IDYuOTc0OTkgMjRIMTcuMDI1QzIxLjM5NDkgMjQgMjQgMjEuMzk2MyAyNCAxNy4wMjc1VjYuOTg0NTFDMjQuMDEyIDIuNjE1NjkgMjEuNDA2OSAwIDE3LjAzNyAwWiIgZmlsbD0iIzI0MjcyQSIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTcuMDc1NzcgNi4wMTg0M0M2Ljc2MjgxIDYuMDYwNTkgNi40NzY5MyA2LjIyMDE2IDYuMjY5NzQgNi40NjgzNUM2LjExMjg1IDYuNjU2MjkgNi4wMTExMyA2Ljg5NDEzIDUuOTgwOTUgNy4xNDM1NEM1Ljk3NjggNy4xNzc5MSA1Ljk3NDgzIDguNzU1MzMgNS45NzQ5MiAxMi4wMDlDNS45NzUwMSAxNi4xMTggN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go8Y2xpcFBhdGggaWQ9ImNsaXAwXzFfNCI+CjxyZWN0IHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K";
26 changes: 26 additions & 0 deletions packages/metamask-snap/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { WalletModuleFactory } from "@near-wallet-selector/core";
import { initMetamaskSnap } from "./selector";
import icon from "./icon";

export { icon };

export function setupMetamaskSnap({
deprecated = false,
iconUrl = icon,
}): WalletModuleFactory {
return async () => {
return {
id: "metamask-snap",
type: "injected",
init: initMetamaskSnap,
metadata: {
name: "Metamask Snap",
description: "Metamask plugin for NEAR Protocol",
downloadUrl: "https://near-snap.surge.sh",
iconUrl,
deprecated,
available: true,
},
};
};
}
Loading

0 comments on commit 48f03d7

Please sign in to comment.