Skip to content

Commit

Permalink
Merge pull request #60 from ShubhamParkhi/dev
Browse files Browse the repository at this point in the history
feat: New Apis for Snap
  • Loading branch information
jaybuidl authored Sep 23, 2024
2 parents 6daa4c2 + 572e57d commit 8c579a5
Show file tree
Hide file tree
Showing 11 changed files with 2,784 additions and 604 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16
v20
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
"yaml@npm:^2.0.0": "^2.3.1"
},
"dependencies": {
"@metamask/snaps-cli": "^0.32.2",
"@metamask/snaps-ui": "^0.32.2",
"cross-env": "^7.0.3",
"crypto": "^1.0.1",
"gatsby-cli": "^5.13.3",
Expand Down Expand Up @@ -67,7 +65,7 @@
"node": ">=16.0.0"
},
"volta": {
"node": "16.20.0",
"node": "20.11.0",
"yarn": "3.3.1"
}
}
2 changes: 1 addition & 1 deletion packages/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"node": ">=16.0.0"
},
"volta": {
"node": "16.20.0",
"node": "20.11.0",
"yarn": "3.3.1"
}
}
2 changes: 1 addition & 1 deletion packages/snap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This Snap pulls contract metadata from Kleros's decentralized token curated regi

## Publication to NPM

1. Bump the version in `package.json`
1. Bump the version in `package.json` and `snap.manifest.json`
1. Run a clean build: `yarn clean && yarn build`
1. Commit the change to git: `git add -u ; git commit -m "chore: release"`
1. Tag this version: `version=v$(cat package.json | jq -r .version) && git tag -m $version $version`
Expand Down
94 changes: 94 additions & 0 deletions packages/snap/images/insights-display.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions packages/snap/images/process-explanation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 10 additions & 9 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kleros/scout-snap",
"version": "1.3.1",
"version": "1.3.3",
"description": "A Metamask Snap that retrieves contract metadata from the Kleros Curate registries",
"repository": {
"type": "git",
Expand Down Expand Up @@ -31,16 +31,17 @@
"serve": "mm-snap serve",
"start": "mm-snap watch"
},
"dependencies": {
"@metamask/snaps-sdk": "^3.1.1"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.5.1",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/eslint-config": "^11.1.0",
"@metamask/eslint-config-jest": "^11.1.0",
"@metamask/eslint-config-nodejs": "^11.1.0",
"@metamask/eslint-config-typescript": "^11.1.0",
"@metamask/snaps-cli": "^0.32.2",
"@metamask/snaps-types": "^0.32.2",
"@metamask/snaps-ui": "^0.32.2",
"@metamask/snaps-cli": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.57.0",
Expand All @@ -55,16 +56,16 @@
"rimraf": "^3.0.2",
"typescript": "^4.9.5"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=16.0.0"
},
"volta": {
"node": "16.20.0",
"node": "20.11.0",
"yarn": "3.3.1"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
24 changes: 22 additions & 2 deletions packages/snap/snap.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
module.exports = {
cliOptions: {
src: './src/index.ts',
bundler: 'webpack',
input: 'src/index.ts',
output: {
filename: 'bundle.js',
path: 'dist',
},
server: {
port: 8080,
},
manifest: {
path: 'snap.manifest.json',
},
features: {
images: true,
},
environment: {
SNAP_ENV: process.env.SNAP_ENV,

Check failure on line 18 in packages/snap/snap.config.js

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Unexpected use of process.env

Check failure on line 18 in packages/snap/snap.config.js

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Unexpected use of process.env
PUBLIC_KEY: process.env.PUBLIC_KEY,

Check failure on line 19 in packages/snap/snap.config.js

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Unexpected use of process.env

Check failure on line 19 in packages/snap/snap.config.js

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Unexpected use of process.env
},
polyfills: {
buffer: true,
crypto: true,
path: true,
},
};
9 changes: 6 additions & 3 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.3.1",
"version": "1.3.3",
"description": "A Snap that retrieves contract metadata from the Kleros Curate registries.",
"proposedName": "Kleros Scout",
"repository": {
"type": "git",
"url": "https://github.com/kleros/scout-snap.git"
},
"source": {
"shasum": "KCzo/QBHtC+GPdGeVJaIgLy+O5nucZ3jEY7PvNbBtH4=",
"shasum": "i0jrmOrh1H7O2ukHsfVRsFwZycxUkMx2w5eKSTbxFwQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -21,7 +21,10 @@
"endowment:transaction-insight": {
"allowTransactionOrigin": true
},
"endowment:network-access": {}
"endowment:network-access": {},
"endowment:page-home": {},
"endowment:lifecycle-hooks": {},
"snap_dialog": {}
},
"manifestVersion": "0.1"
}
79 changes: 76 additions & 3 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { OnTransactionHandler } from '@metamask/snaps-types';
import { panel, heading, text } from '@metamask/snaps-ui';
import {
OnHomePageHandler,
OnTransactionHandler,
OnInstallHandler,
panel,
text,
heading,
divider,
image

Check failure on line 9 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Insert `,`

Check failure on line 9 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Insert `,`
} from '@metamask/snaps-sdk';
// eslint-disable-next-line import/no-extraneous-dependencies
import mdEscape from 'markdown-escape';

Check failure on line 12 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (16.x)

There should be at least one empty line between import groups

Check failure on line 12 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (18.x)

There should be at least one empty line between import groups
import InsightsDisplayImage from '../images/insights-display.svg';
import ProcessExplanationImage from '../images/process-explanation.svg';

// Define types
type AddressTag = {
caipAddress: string;
publicName: string;
Expand Down Expand Up @@ -185,6 +196,8 @@ const getInsights = async (

// If insight search has no result in a category, the result is omitted.
const insights: string[] = [];
let hasCDNInsight = false;

if (result.addressTag) {
// key2 is projectName, which is optional. No project name === "", which is falsy.
const projectNameLabel = result.addressTag.projectName
Expand All @@ -202,6 +215,7 @@ const getInsights = async (
if (result.contractDomain) {
const domainLabel = `**Domain:** _${domain}_ is **verified** for this contract`;
insights.push(domainLabel);
hasCDNInsight = true;
}

if (result.token) {
Expand All @@ -215,14 +229,73 @@ const getInsights = async (
insights.push(
'No insights available for this contract. Interact at your own risk.',
);
}

const excludedDomains = [
'etherscan.io', 'bscscan.com', 'gnosisscan.io', 'polygonscan.com',

Check failure on line 235 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Replace `·'bscscan.com',·'gnosisscan.io',` with `⏎····'bscscan.com',⏎····'gnosisscan.io',⏎···`

Check failure on line 235 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Replace `·'bscscan.com',·'gnosisscan.io',` with `⏎····'bscscan.com',⏎····'gnosisscan.io',⏎···`
'mempool.space', 'explorer.solana.com', 'basescan.org', 'arbiscan.io',

Check failure on line 236 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Replace `·'explorer.solana.com',·'basescan.org',` with `⏎····'explorer.solana.com',⏎····'basescan.org',⏎···`

Check failure on line 236 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Replace `·'explorer.solana.com',·'basescan.org',` with `⏎····'explorer.solana.com',⏎····'basescan.org',⏎···`
'moonscan.io', 'lineascan.build', 'optimistic.etherscan.io', 'ftmscan.com',

Check failure on line 237 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Replace `·'lineascan.build',·'optimistic.etherscan.io',` with `⏎····'lineascan.build',⏎····'optimistic.etherscan.io',⏎···`

Check failure on line 237 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Replace `·'lineascan.build',·'optimistic.etherscan.io',` with `⏎····'lineascan.build',⏎····'optimistic.etherscan.io',⏎···`
'moonriver.moonscan.io', 'snowscan.xyz', 'cronoscan.com', 'bttcscan.com',

Check failure on line 238 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Replace `·'snowscan.xyz',·'cronoscan.com',` with `⏎····'snowscan.xyz',⏎····'cronoscan.com',⏎···`

Check failure on line 238 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Replace `·'snowscan.xyz',·'cronoscan.com',` with `⏎····'snowscan.xyz',⏎····'cronoscan.com',⏎···`
'zkevm.polygonscan.com', 'wemixscan.com', 'scrollscan.com', 'era.zksync.network', 'celoscan.io'

Check failure on line 239 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Replace `·'wemixscan.com',·'scrollscan.com',·'era.zksync.network',·'celoscan.io'` with `⏎····'wemixscan.com',⏎····'scrollscan.com',⏎····'era.zksync.network',⏎····'celoscan.io',`

Check failure on line 239 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Replace `·'wemixscan.com',·'scrollscan.com',·'era.zksync.network',·'celoscan.io'` with `⏎····'wemixscan.com',⏎····'scrollscan.com',⏎····'era.zksync.network',⏎····'celoscan.io',`
];

if (!excludedDomains.includes(domain) && !hasCDNInsight) {
const cdnPathURL = `https://app.klerosscout.eth.limo/#/?registry=CDN&network=1&network=100&network=137&network=56&network=42161&network=10&network=43114&network=534352&network=42220&network=8453&network=250&network=324&status=Registered&status=RegistrationRequested&status=ClearingRequested&status=Absent&disputed=true&disputed=false&page=1&orderDirection=desc&&additem=CDN&caip10Address=${caipAddress}&domain=${domain}`;

insights.push(
'Do you know this contract? Submit insights on curate.kleros.io in Gnosis Chain and earn rewards!',
`Is this contract linked to this domain? If so, submit the info at [Scout App](${cdnPathURL}) to verify it for all users!`,
);
}

return insights;
};

export const onInstall: OnInstallHandler = async () => {
await snap.request({
method: 'snap_dialog',
params: {
type: 'alert',
content: panel([
heading(
'Kleros Scout’s community curated contract insights secures your dApp browsing.',
),
text(
'Congrats on taking a crucial step towards safeguarding your wallet interactions!',
),
divider(),
heading('How to use the Snap?'),
text(
'The Kleros Scout Snap provides 3 points of insight on every transaction:',
),
text(
'**Project:** _Which project does the contract you’re interacting with belong to?_',
),
text(
'**Contract Tag:** _What is the function or tag associated with the smart contract?_',
),
text('**Domain:** _Whether this contract is known to be used on this domain?_'),

Check failure on line 276 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Replace `'**Domain:**·_Whether·this·contract·is·known·to·be·used·on·this·domain?_'` with `⏎··········'**Domain:**·_Whether·this·contract·is·known·to·be·used·on·this·domain?_',⏎········`

Check failure on line 276 in packages/snap/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint (18.x)

Replace `'**Domain:**·_Whether·this·contract·is·known·to·be·used·on·this·domain?_'` with `⏎··········'**Domain:**·_Whether·this·contract·is·known·to·be·used·on·this·domain?_',⏎········`
image(InsightsDisplayImage),
]),
},
});
};

export const onHomePage: OnHomePageHandler = async () => {
return {
content: panel([
heading(
'Kleros Scout’s community curated contract insights secures your dApp browsing.',
),
divider(),
heading('How does it work?'),
text(
'Anyone can submit contract insights & earn up to $15 per entry! [Head here to know more.](https://klerosscout.eth.limo)',
),
image(ProcessExplanationImage),
]),
};
};

export const onTransaction: OnTransactionHandler = async ({
transactionOrigin,
transaction,
Expand Down
Loading

0 comments on commit 8c579a5

Please sign in to comment.