Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Use custom UI in transaction insights #1047

Merged
merged 4 commits into from Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
Mrtenz marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
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