Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "LciQX9cjRXeSErEsKRm9OEFW8jAq9doqaa9b/TfGN3Y=",
"shasum": "8LxymXn6+X9URWzkmurIZEyCypzF3OUm53FLjlNW0/I=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "83SohbQ4Vp/wI2lFXL6tyuvWy7bLcRSL3yZikZEZrAg=",
"shasum": "hYGGCiIVhwOlDnwIyfpkscAd5bc2kVAyzXMq3UC6ORQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
39 changes: 39 additions & 0 deletions packages/snaps-sdk/src/jsx/components/Card.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Address } from './Address';
import { Card } from './Card';

describe('Card', () => {
Expand All @@ -24,4 +25,42 @@ describe('Card', () => {
},
});
});

it('renders a card with an address as title', () => {
const result = (
<Card
image="<svg />"
title={
<Address
address="0x1234567890123456789012345678901234567890"
displayName
avatar={false}
/>
}
description="Description"
value="$1200"
extra="0.12 ETH"
/>
);

expect(result).toStrictEqual({
type: 'Card',
key: null,
props: {
image: '<svg />',
title: {
key: null,
props: {
address: '0x1234567890123456789012345678901234567890',
avatar: false,
displayName: true,
},
type: 'Address',
},
description: 'Description',
value: '$1200',
extra: '0.12 ETH',
},
});
});
});
3 changes: 2 additions & 1 deletion packages/snaps-sdk/src/jsx/components/Card.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createSnapComponent } from '../component';
import type { AddressElement } from './Address';

/**
* The props of the {@link Card} component.
Expand All @@ -11,7 +12,7 @@ import { createSnapComponent } from '../component';
*/
export type CardProps = {
image?: string | undefined;
title: string;
title: string | AddressElement;
description?: string | undefined;
value: string;
extra?: string | undefined;
Expand Down
13 changes: 13 additions & 0 deletions packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,19 @@ describe('CardStruct', () => {
value="$1200"
extra="0.12 ETH"
/>,
<Card
image="<svg />"
title={
<Address
address="0x1234567890123456789012345678901234567890"
displayName
avatar={false}
/>
}
description="Description"
value="$1200"
extra="0.12 ETH"
/>,
])('validates a card element', (value) => {
expect(is(value, CardStruct)).toBe(true);
});
Expand Down
27 changes: 16 additions & 11 deletions packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,27 @@ export const DropdownStruct: Describe<DropdownElement> = element('Dropdown', {
children: children([OptionStruct]),
});

/**
* A struct for the {@link AddressElement} type.
*/
export const AddressStruct: Describe<AddressElement> = element('Address', {
address: nullUnion([HexChecksumAddressStruct, CaipAccountIdStruct]),
truncate: optional(boolean()),
displayName: optional(boolean()),
avatar: optional(boolean()),
});

/**
* A struct for the {@link CardElement} type.
*/
export const CardStruct: Describe<CardElement> = element('Card', {
image: optional(string()),
title: string(),
title: selectiveUnion((value) => {
if (typeof value === 'object') {
return AddressStruct;
}
return string();
}),
description: optional(string()),
value: string(),
extra: optional(string()),
Expand Down Expand Up @@ -538,16 +553,6 @@ export const FormattingStruct: Describe<StandardFormattingElement> = typedUnion(
[BoldStruct, ItalicStruct],
);

/**
* A struct for the {@link AddressElement} type.
*/
export const AddressStruct: Describe<AddressElement> = element('Address', {
address: nullUnion([HexChecksumAddressStruct, CaipAccountIdStruct]),
truncate: optional(boolean()),
displayName: optional(boolean()),
avatar: optional(boolean()),
});

/**
* A struct for the {@link AvatarElement} type.
*/
Expand Down
Loading