Skip to content

Commit

Permalink
Use JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed May 14, 2024
1 parent d1471ed commit a88b1c3
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 140 deletions.
2 changes: 1 addition & 1 deletion packages/site/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const Index = () => {
Welcome to <Span>template-snap</Span>
</Heading>
<Subtitle>
Get started by editing <code>src/index.ts</code>
Get started by editing <code>src/index.tsx</code>
</Subtitle>
<CardContainer>
{error && (
Expand Down
4 changes: 4 additions & 0 deletions packages/site/src/utils/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export async function getMetaMaskEIP6963Provider() {
* @param event.detail - The details of the EIP6963 announceProvider event.
*/
function onAnnounceProvider({ detail }: EIP6963AnnounceProviderEvent) {
if (!detail) {
return;
}

const { info, provider } = detail;

if (info.rdns.includes('io.metamask')) {
Expand Down
14 changes: 14 additions & 0 deletions packages/snap/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ module.exports = {
extends: ['@metamask/eslint-config-nodejs'],
},

{
files: ['**/*.ts', '**/*.tsx'],
extends: ['@metamask/eslint-config-typescript'],
rules: {
// This allows importing the `Text` JSX component.
'@typescript-eslint/no-shadow': [
'error',
{
allow: ['Text'],
},
],
},
},

{
files: ['*.test.ts'],
rules: {
Expand Down
6 changes: 3 additions & 3 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"test": "jest"
},
"dependencies": {
"@metamask/snaps-sdk": "^4.0.0",
"@metamask/snaps-sdk": "^4.1.0",
"buffer": "^6.0.3"
},
"devDependencies": {
Expand All @@ -37,8 +37,8 @@
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@metamask/snaps-cli": "^6.1.0",
"@metamask/snaps-jest": "^7.0.0",
"@metamask/snaps-cli": "^6.2.0",
"@metamask/snaps-jest": "^8.0.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.45.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
input: resolve(__dirname, 'src/index.tsx'),
server: {
port: 8080,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/template-snap-monorepo.git"
},
"source": {
"shasum": "TwVBeJ/PL4uARBEFZmgJukYd3XWyTbilkOPhtdg+GvU=",
"shasum": "2OwZmIrZmVpVvpXkYreocpEeYEkeNjriRdSSjbqycCQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
23 changes: 15 additions & 8 deletions packages/snap/src/index.ts → packages/snap/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';
import { panel, text } from '@metamask/snaps-sdk';
import { Box, Text, Bold } from '@metamask/snaps-sdk/jsx';

/**
* Handle incoming JSON-RPC requests, sent through `wallet_invokeSnap`.
Expand All @@ -21,13 +21,20 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
method: 'snap_dialog',
params: {
type: 'confirmation',
content: panel([
text(`Hello, **${origin}**!`),
text('This custom confirmation is just for display purposes.'),
text(
'But you can edit the snap source code to make it do something, if you want to!',
),
]),
content: (
<Box>
<Text>
Hello, <Bold>{origin}</Bold>!
</Text>
<Text>
This custom confirmation is just for display purposes.
</Text>
<Text>
But you can edit the snap source code to make it do something,
if you want to!
</Text>
</Box>
),
},
});
default:
Expand Down
6 changes: 4 additions & 2 deletions packages/snap/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./"
"baseUrl": "./",
"jsx": "react-jsx",
"jsxImportSource": "@metamask/snaps-sdk"
},
"include": ["**/*.ts"]
"include": ["**/*.ts", "**/*.tsx"]
}
Loading

0 comments on commit a88b1c3

Please sign in to comment.