Skip to content

Commit

Permalink
Add JSX example to test-snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed May 1, 2024
1 parent 30c88f8 commit 1cda053
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/test-snaps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@metamask/insights-example-snap": "workspace:^",
"@metamask/interactive-ui-example-snap": "workspace:^",
"@metamask/json-rpc-example-snap": "workspace:^",
"@metamask/jsx-example-snap": "workspace:^",
"@metamask/lifecycle-hooks-example-snap": "workspace:^",
"@metamask/localization-example-snap": "workspace:^",
"@metamask/manage-state-example-snap": "workspace:^",
Expand Down
1 change: 1 addition & 0 deletions packages/test-snaps/src/features/snaps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './localization';
export * from './home-page';
export * from './images';
export * from './json-rpc';
export * from './jsx';
export * from './lifecycle-hooks';
export * from './manage-state';
export * from './multi-install';
Expand Down
45 changes: 45 additions & 0 deletions packages/test-snaps/src/features/snaps/jsx/Jsx.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { logError } from '@metamask/snaps-utils';
import type { FunctionComponent } from 'react';
import { Button } from 'react-bootstrap';

import { useInvokeMutation } from '../../../api';
import { Result, Snap } from '../../../components';
import { getSnapId } from '../../../utils';
import { JSX_SNAP_ID, JSX_SNAP_PORT, JSX_VERSION } from './constants';

export const Jsx: FunctionComponent = () => {
const [invokeSnap, { isLoading, data, error }] = useInvokeMutation();

const handleSubmit = () => {
invokeSnap({
snapId: getSnapId(JSX_SNAP_ID, JSX_SNAP_PORT),
method: 'display',
}).catch(logError);
};

return (
<Snap
name="JSX Snap"
snapId={JSX_SNAP_ID}
port={JSX_SNAP_PORT}
version={JSX_VERSION}
testId="jsx"
>
<Button
variant="primary"
id="displayJsx"
className="mb-3"
disabled={isLoading}
onClick={handleSubmit}
>
Show JSX dialog
</Button>
<Result>
<span id="rpcResult">
{JSON.stringify(data, null, 2)}
{JSON.stringify(error, null, 2)}
</span>
</Result>
</Snap>
);
};
5 changes: 5 additions & 0 deletions packages/test-snaps/src/features/snaps/jsx/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import packageJson from '@metamask/jsx-example-snap/package.json';

export const JSX_SNAP_ID = 'npm:@metamask/jsx-example-snap';
export const JSX_SNAP_PORT = 8029;
export const JSX_VERSION = packageJson.version;
1 change: 1 addition & 0 deletions packages/test-snaps/src/features/snaps/jsx/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Jsx';
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4910,7 +4910,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/jsx-example-snap@workspace:packages/examples/packages/jsx":
"@metamask/jsx-example-snap@workspace:^, @metamask/jsx-example-snap@workspace:packages/examples/packages/jsx":
version: 0.0.0-use.local
resolution: "@metamask/jsx-example-snap@workspace:packages/examples/packages/jsx"
dependencies:
Expand Down Expand Up @@ -6144,6 +6144,7 @@ __metadata:
"@metamask/insights-example-snap": "workspace:^"
"@metamask/interactive-ui-example-snap": "workspace:^"
"@metamask/json-rpc-example-snap": "workspace:^"
"@metamask/jsx-example-snap": "workspace:^"
"@metamask/lifecycle-hooks-example-snap": "workspace:^"
"@metamask/localization-example-snap": "workspace:^"
"@metamask/manage-state-example-snap": "workspace:^"
Expand Down

0 comments on commit 1cda053

Please sign in to comment.