Skip to content

Commit

Permalink
Move UI functionality to SDK (#1954)
Browse files Browse the repository at this point in the history
This moves all UI-related functionality (at least the public API) to the
SDK package. The only exception is the two validation functions, which
have been moved to `snaps-utils` instead.
  • Loading branch information
Mrtenz authored Nov 13, 2023
1 parent f621a33 commit 80e39bd
Show file tree
Hide file tree
Showing 163 changed files with 1,635 additions and 1,431 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@types/node": "18.14.2",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"chromedriver": "^119.0.0",
"chromedriver": "^119.0.1",
"depcheck": "^1.4.7",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/bip32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@metamask/key-tree": "^9.0.0",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^",
"@metamask/utils": "^8.1.0",
"@noble/ed25519": "^1.6.0",
"@noble/secp256k1": "^1.7.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "a6nSBZXDUyWbimLESJxAVZRqTWFy5YXXO/+Si9nhLNY=",
"shasum": "u5ivjgGAAm03S12NIHiNd0gcQvdarn/VSZvSgCR0Zdo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@jest/globals';
import { installSnap } from '@metamask/snaps-jest';
import { copyable, heading, panel, text } from '@metamask/snaps-ui';
import { copyable, heading, panel, text } from '@metamask/snaps-sdk';
import { assert } from '@metamask/utils';

describe('onRpcRequest', () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/examples/packages/bip32/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { providerErrors, rpcErrors } from '@metamask/rpc-errors';
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
import { DialogType } from '@metamask/snaps-sdk';
import { panel, text, heading, copyable } from '@metamask/snaps-ui';
import {
DialogType,
panel,
text,
heading,
copyable,
} from '@metamask/snaps-sdk';
import {
add0x,
assert,
Expand Down
3 changes: 0 additions & 3 deletions packages/examples/packages/bip32/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
{
"path": "../../../snaps-sdk"
},
{
"path": "../../../snaps-ui"
},
{
"path": "../../../snaps-jest"
},
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/bip44/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@metamask/key-tree": "^9.0.0",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^",
"@metamask/utils": "^8.1.0",
"@noble/bls12-381": "^1.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "kC7naDIca71EEh+FvGppoEgpkdOCNzgSC2noYtZVgKk=",
"shasum": "Tsdg8tuhFAWXwivAnEU6IwDMWc+4TMz3gJNBZx0650M=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@jest/globals';
import { installSnap } from '@metamask/snaps-jest';
import { copyable, heading, panel, text } from '@metamask/snaps-ui';
import { copyable, heading, panel, text } from '@metamask/snaps-sdk';
import { assert } from '@metamask/utils';

describe('onRpcRequest', () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/examples/packages/bip44/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { rpcErrors, providerErrors } from '@metamask/rpc-errors';
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
import { DialogType } from '@metamask/snaps-sdk';
import { panel, text, heading, copyable } from '@metamask/snaps-ui';
import {
DialogType,
panel,
text,
heading,
copyable,
} from '@metamask/snaps-sdk';
import { bytesToHex, stringToBytes } from '@metamask/utils';
import { getPublicKey, sign } from '@noble/bls12-381';

Expand Down
3 changes: 0 additions & 3 deletions packages/examples/packages/bip44/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
{
"path": "../../../snaps-sdk"
},
{
"path": "../../../snaps-ui"
},
{
"path": "../../../snaps-jest"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/packages/cronjobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
},
"dependencies": {
"@metamask/rpc-errors": "^6.1.0",
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^"
"@metamask/snaps-sdk": "workspace:^"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "B9GYMaxJ9+WDY+AxjCGZT/CF8EOqhPE8TWag16+Q0vI=",
"shasum": "KIFU8apM9tqRwrSFQfX2uxUPWOPvo5eAgTYnKkCDKmo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@jest/globals';
import { installSnap } from '@metamask/snaps-jest';
import { heading, panel, text } from '@metamask/snaps-ui';
import { heading, panel, text } from '@metamask/snaps-sdk';

describe('onCronjob', () => {
describe('execute', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rpcErrors } from '@metamask/rpc-errors';
import type { OnCronjobHandler } from '@metamask/snaps-sdk';
import { panel, text, heading } from '@metamask/snaps-ui';
import { panel, text, heading } from '@metamask/snaps-sdk';

/**
* Handle cronjob execution requests from MetaMask. This handler handles one
Expand Down
3 changes: 0 additions & 3 deletions packages/examples/packages/cronjobs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
{
"path": "../../../snaps-sdk"
},
{
"path": "../../../snaps-ui"
},
{
"path": "../../../snaps-jest"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/packages/dialogs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
},
"dependencies": {
"@metamask/rpc-errors": "^6.1.0",
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^"
"@metamask/snaps-sdk": "workspace:^"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "p1WpZhW7JUQMqqNVoMPpK3kRu0bN2TLBFMU4IU0ayDA=",
"shasum": "4c2ZW/go/unSldGCQRo8G3/t0QxKxSzlK85ggomynwA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@jest/globals';
import { installSnap } from '@metamask/snaps-jest';
import { heading, panel, text } from '@metamask/snaps-ui';
import { heading, panel, text } from '@metamask/snaps-sdk';
import { assert } from '@metamask/utils';

describe('onRpcRequest', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/packages/dialogs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { rpcErrors } from '@metamask/rpc-errors';
import { DialogType } from '@metamask/snaps-sdk';
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
import { panel, text, heading } from '@metamask/snaps-ui';
import { DialogType, panel, text, heading } from '@metamask/snaps-sdk';

/**
* Handle incoming JSON-RPC requests from the dapp, sent through the
Expand Down
3 changes: 0 additions & 3 deletions packages/examples/packages/dialogs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
{
"path": "../../../snaps-sdk"
},
{
"path": "../../../snaps-ui"
},
{
"path": "../../../snaps-jest"
},
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/ethers-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"@metamask/rpc-errors": "^6.1.0",
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^",
"ethers": "^6.3.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "kVxlpDWxMNSztVRiVmpavQX/dlZOZoT0uIl3CuULhIk=",
"shasum": "GC0840frLvW2m7j5R3W/Zc8jxn42mCSdO4O4xwGFWRQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@jest/globals';
import { installSnap } from '@metamask/snaps-jest';
import { copyable, heading, panel, text } from '@metamask/snaps-ui';
import { copyable, heading, panel, text } from '@metamask/snaps-sdk';
import { assert } from '@metamask/utils';

describe('onRpcRequest', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { providerErrors, rpcErrors } from '@metamask/rpc-errors';
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
import { panel, heading, copyable, text } from '@metamask/snaps-ui';
import { panel, heading, copyable, text } from '@metamask/snaps-sdk';
import { Wallet } from 'ethers';

import type { SignMessageParams } from './types';
Expand Down
3 changes: 0 additions & 3 deletions packages/examples/packages/ethers-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
{
"path": "../../../snaps-sdk"
},
{
"path": "../../../snaps-ui"
},
{
"path": "../../../snaps-jest"
},
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/get-entropy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"@metamask/rpc-errors": "^6.1.0",
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^",
"@metamask/utils": "^8.1.0",
"@noble/bls12-381": "^1.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "WcUEK4cnEAv1J4efCUFaXxK4XvzzSIYf9j8qscNOOQ0=",
"shasum": "j2L8jJLuo90o0YIDvdmG0D2sHiuEXWk6s7BngVDWmOE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@jest/globals';
import { installSnap } from '@metamask/snaps-jest';
import { copyable, heading, panel, text } from '@metamask/snaps-ui';
import { copyable, heading, panel, text } from '@metamask/snaps-sdk';

describe('onRpcRequest', () => {
it('throws an error if the requested method does not exist', async () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/examples/packages/get-entropy/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { rpcErrors, providerErrors } from '@metamask/rpc-errors';
import { DialogType } from '@metamask/snaps-sdk';
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
import { panel, text, heading, copyable } from '@metamask/snaps-ui';
import {
DialogType,
panel,
text,
heading,
copyable,
} from '@metamask/snaps-sdk';
import { bytesToHex, stringToBytes } from '@metamask/utils';
import { sign } from '@noble/bls12-381';

Expand Down
3 changes: 0 additions & 3 deletions packages/examples/packages/get-entropy/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
{
"path": "../../../snaps-sdk"
},
{
"path": "../../../snaps-ui"
},
{
"path": "../../../snaps-jest"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/packages/home-page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"lint:dependencies": "depcheck"
},
"dependencies": {
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^"
"@metamask/snaps-sdk": "workspace:^"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "wPZUr6vMqCfxKlW2OJjfFGZHLCcLEXS1epk8mkngclc=",
"shasum": "axgWN0FsQyfCgOWKgtC1jlThZUr1oSgx2/fjLgTjwvI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from '@jest/globals';
import { panel, text, heading } from '@metamask/snaps-ui';
import { panel, text, heading } from '@metamask/snaps-sdk';

import { onHomePage } from '.';

Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OnHomePageHandler } from '@metamask/snaps-sdk';
import { panel, text, heading } from '@metamask/snaps-ui';
import { panel, text, heading } from '@metamask/snaps-sdk';

/**
* Handle incoming home page requests from the MetaMask clients.
Expand Down
3 changes: 0 additions & 3 deletions packages/examples/packages/home-page/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
{
"path": "../../../snaps-sdk"
},
{
"path": "../../../snaps-ui"
},
{
"path": "../../../snaps-jest"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@metamask/key-tree": "^9.0.0",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^",
"@metamask/utils": "^8.1.0",
"@noble/curves": "^1.1.0",
"async-mutex": "^0.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "mGKJ1s3TMRHRpWEB274UktA7EBsNRbVfWwnms6BE434=",
"shasum": "Ewa08BobfvENHwbCt3sYFKoTA7g4dxEANeVgiuDKamY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { rpcErrors, providerErrors } from '@metamask/rpc-errors';
import { DialogType } from '@metamask/snaps-sdk';
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
import { panel, text, heading, copyable } from '@metamask/snaps-ui';
import {
DialogType,
panel,
text,
heading,
copyable,
} from '@metamask/snaps-sdk';
import { add0x, assert, hexToBytes } from '@metamask/utils';
import { secp256k1 } from '@noble/curves/secp256k1';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"path": "../../../../../snaps-sdk"
},
{
"path": "../../../../../snaps-ui"
"path": "../../../../../snaps-sdk"
},
{
"path": "../../../../../snaps-jest"
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/packages/lifecycle-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"lint:dependencies": "depcheck"
},
"dependencies": {
"@metamask/snaps-sdk": "workspace:^",
"@metamask/snaps-ui": "workspace:^"
"@metamask/snaps-sdk": "workspace:^"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "SIhRLP4UwJFtKmFA+s+iM5aNxPp5K1TIUxqsLnwaq1E=",
"shasum": "Hsk3bjjJhL83pHCiXCe7HXVdCNsWi2mF/xeHlNR77kQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Loading

0 comments on commit 80e39bd

Please sign in to comment.