Skip to content

Commit f3e8008

Browse files
committed
update simulator and fix tests
1 parent c0f6416 commit f3e8008

File tree

13 files changed

+74
-28
lines changed

13 files changed

+74
-28
lines changed

packages/examples/packages/browserify/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "vdovVqAuPpZUhBv7sp9jeWcbswewQ+b1/DmLtqMzCo4=",
10+
"shasum": "hXzhJjb3I9KofDHIA533vEAW0XRzESeroiYc0bsQkn8=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/rpc-methods/jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ module.exports = deepmerge(baseConfig, {
1010
],
1111
coverageThreshold: {
1212
global: {
13-
branches: 87.6,
13+
branches: 87.9,
1414
functions: 100,
15-
lines: 97.95,
16-
statements: 96.34,
15+
lines: 98.22,
16+
statements: 96.64,
1717
},
1818
},
1919
});

packages/snaps-controllers/src/snaps/SnapController.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,12 +1979,10 @@ describe('SnapController', () => {
19791979

19801980
rootMessenger.registerActionHandler(
19811981
'PhishingController:testOrigin',
1982-
async () =>
1983-
// @ts-expect-error will deal with it later.
1984-
Promise.resolve({
1985-
result: true,
1986-
type: 'fuzzy',
1987-
}),
1982+
() => ({
1983+
result: true,
1984+
type: 'fuzzy',
1985+
}),
19881986
);
19891987

19901988
await expect(

packages/snaps-simulator/src/components/Icon.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ const DEFAULT_ICONS = {
157157
alt: 'Text',
158158
src: textIcon,
159159
},
160+
link: {
161+
alt: 'Link',
162+
src: textIcon,
163+
},
160164
copyable: {
161165
alt: 'Copyable',
162166
src: copyableIcon,

packages/snaps-simulator/src/features/builder/components/Node.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const EDITABLE_NODES = [
1414
NodeType.Text,
1515
NodeType.Copyable,
1616
NodeType.Image,
17+
NodeType.Link,
1718
];
1819

1920
type NodeProps = {

packages/snaps-simulator/src/features/builder/components/TemplateComponentList.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
divider,
66
heading,
77
image,
8+
link,
89
panel,
910
text,
1011
} from '@metamask/snaps-ui';
@@ -47,6 +48,12 @@ const TEMPLATE_COMPONENTS: TemplateComponent[] = [
4748
data: text('Text'),
4849
droppable: false,
4950
},
51+
{
52+
icon: 'link',
53+
text: 'Link',
54+
data: link('Link', 'https://foo.bar'),
55+
droppable: false,
56+
},
5057
{
5158
icon: 'divider',
5259
text: 'Divider',

packages/snaps-simulator/src/features/builder/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function getComponentArgs(component: Component): string {
8686
switch (component.type) {
8787
case NodeType.Panel:
8888
return component.children.map(getComponentArgs).join(',\n');
89+
case NodeType.Link:
8990
case NodeType.Text:
9091
case NodeType.Heading:
9192
case NodeType.Copyable:

packages/snaps-simulator/src/features/renderer/Renderer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Heading,
1111
Spinner,
1212
Image,
13+
Link,
1314
} from './components';
1415

1516
export const components: Record<
@@ -23,6 +24,7 @@ export const components: Record<
2324
[NodeType.Spinner]: Spinner,
2425
[NodeType.Text]: Text,
2526
[NodeType.Image]: Image,
27+
[NodeType.Link]: Link,
2628
};
2729

2830
type RendererProps = {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Link as ChakraLink } from '@chakra-ui/react';
2+
import { isComponent } from '@metamask/snaps-ui';
3+
import { assert } from '@metamask/utils';
4+
import type { FunctionComponent } from 'react';
5+
6+
export type LinkProps = {
7+
id: string;
8+
node: unknown;
9+
};
10+
11+
export const Link: FunctionComponent<LinkProps> = ({ node, id }) => {
12+
assert(isComponent(node), 'Expected value to be a valid UI component.');
13+
assert(node.type === 'link', 'Expected value to be a link component.');
14+
15+
return (
16+
<ChakraLink
17+
fontFamily="custom"
18+
fontSize="sm"
19+
paddingBottom="1"
20+
key={`${id}-link`}
21+
href={node.url}
22+
>
23+
{node.value}
24+
</ChakraLink>
25+
);
26+
};

packages/snaps-simulator/src/features/renderer/components/Text.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Text as ChakraText } from '@chakra-ui/react';
1+
import { Text as ChakraText, Link as ChakraLink } from '@chakra-ui/react';
22
import { isComponent } from '@metamask/snaps-ui';
33
import { assert } from '@metamask/utils';
4-
import type { FunctionComponent } from 'react';
4+
import { type FunctionComponent } from 'react';
55
import ReactMarkdown from 'react-markdown';
66

77
export type TextProps = {
@@ -15,13 +15,16 @@ export const Text: FunctionComponent<TextProps> = ({ node, id }) => {
1515

1616
return (
1717
<ReactMarkdown
18-
allowedElements={['p', 'strong', 'em']}
18+
allowedElements={['p', 'strong', 'em', 'a']}
1919
components={{
2020
p: ({ children: value }) => (
2121
<ChakraText fontFamily="custom" fontSize="sm" paddingBottom="1">
2222
{value}
2323
</ChakraText>
2424
),
25+
a: ({ children: value, href }) => (
26+
<ChakraLink href={href}>{value}</ChakraLink>
27+
),
2528
}}
2629
key={`${id}-text`}
2730
>

0 commit comments

Comments
 (0)