Skip to content

Commit

Permalink
BREAKING: Use custom UI in transaction insights (#1047)
Browse files Browse the repository at this point in the history
* Allow custom UI in transaction insights

* Fix tsconfigs

* Update packages/snaps-utils/src/handlers.ts

Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>

* Update example

Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
  • Loading branch information
FrederikBolding and Mrtenz committed Dec 14, 2022
1 parent 2ed41d3 commit 1fe00c8
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/examples/examples/insights/package.json
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"@metamask/abi-utils": "^1.0.0",
"@metamask/snaps-ui": "^0.26.2",
"@metamask/utils": "^3.3.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/insights/snap.manifest.json
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "a6DXy5lnzdhX/f1YSb0pRFgY8JC2kqbAqd6Rf4iA55g=",
"shasum": "RcPonQimhnc2MFKDfIKvYsfXtZRZQlV26YCwqgQFLeE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
10 changes: 9 additions & 1 deletion packages/examples/examples/insights/src/index.ts
@@ -1,4 +1,5 @@
import { OnTransactionHandler } from '@metamask/snaps-types';
import { panel, text, copyable } from '@metamask/snaps-ui';

import { getInsights } from './insights';

Expand All @@ -10,7 +11,14 @@ import { getInsights } from './insights';
* @returns The transaction insights.
*/
export const onTransaction: OnTransactionHandler = async ({ transaction }) => {
const { type, args } = await getInsights(transaction);
const content = panel([
text(`**Type:** ${type}`),
...(args
? [text('**Args:**'), copyable(JSON.stringify(args, null, 2))]
: []),
]);
return {
insights: await getInsights(transaction),
content,
};
};
5 changes: 0 additions & 5 deletions packages/snaps-ui/tsconfig.build.json
Expand Up @@ -11,10 +11,5 @@
"./src/**/test-utils",
"./src/**/__mocks__",
"./src/**/__snapshots__"
],
"references": [
{
"path": "../snaps-utils/tsconfig.build.json"
}
]
}
3 changes: 1 addition & 2 deletions packages/snaps-ui/tsconfig.json
Expand Up @@ -3,6 +3,5 @@
"compilerOptions": {
"baseUrl": "./"
},
"include": ["./src"],
"references": [{ "path": "../snaps-utils" }]
"include": ["./src"]
}
1 change: 1 addition & 0 deletions packages/snaps-utils/package.json
Expand Up @@ -53,6 +53,7 @@
"@babel/core": "^7.18.6",
"@babel/types": "^7.18.7",
"@metamask/providers": "^10.2.1",
"@metamask/snaps-ui": "^0.26.2",
"@metamask/utils": "^3.3.1",
"@noble/hashes": "^1.1.3",
"@scure/base": "^1.1.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/snaps-utils/src/handlers.ts
@@ -1,4 +1,5 @@
import type { StreamProvider } from '@metamask/providers';
import { Component } from '@metamask/snaps-ui';
import { Json, JsonRpcRequest } from '@metamask/utils';

import { AccountId, ChainId, RequestArguments } from './namespace';
Expand Down Expand Up @@ -34,7 +35,7 @@ export type OnRpcRequestHandler = (args: {
* If the snap has no insights about the transaction, this should be `null`.
*/
export type OnTransactionResponse = {
insights: { [key: string]: Json } | null;
content: Component;
};

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/snaps-utils/tsconfig.build.json
Expand Up @@ -11,5 +11,10 @@
"./src/**/test-utils",
"./src/**/__mocks__",
"./src/**/__snapshots__"
],
"references": [
{
"path": "../snaps-ui/tsconfig.build.json"
}
]
}
3 changes: 2 additions & 1 deletion packages/snaps-utils/tsconfig.json
Expand Up @@ -3,5 +3,6 @@
"compilerOptions": {
"baseUrl": "./"
},
"include": ["./src"]
"include": ["./src"],
"references": [{ "path": "../snaps-ui" }]
}
4 changes: 3 additions & 1 deletion yarn.lock
Expand Up @@ -3013,7 +3013,7 @@ __metadata:
languageName: unknown
linkType: soft

"@metamask/snaps-ui@workspace:packages/snaps-ui":
"@metamask/snaps-ui@^0.26.2, @metamask/snaps-ui@workspace:packages/snaps-ui":
version: 0.0.0-use.local
resolution: "@metamask/snaps-ui@workspace:packages/snaps-ui"
dependencies:
Expand Down Expand Up @@ -3060,6 +3060,7 @@ __metadata:
"@metamask/eslint-config-nodejs": ^11.0.1
"@metamask/eslint-config-typescript": ^11.0.0
"@metamask/providers": ^10.2.1
"@metamask/snaps-ui": ^0.26.2
"@metamask/utils": ^3.3.1
"@noble/hashes": ^1.1.3
"@scure/base": ^1.1.1
Expand Down Expand Up @@ -15613,6 +15614,7 @@ __metadata:
"@metamask/eslint-config-typescript": ^11.0.0
"@metamask/snaps-cli": ^0.26.2
"@metamask/snaps-types": ^0.26.2
"@metamask/snaps-ui": ^0.26.2
"@metamask/utils": ^3.3.1
"@typescript-eslint/eslint-plugin": ^5.42.1
"@typescript-eslint/parser": ^5.42.1
Expand Down

0 comments on commit 1fe00c8

Please sign in to comment.