Skip to content

Commit 1844e67

Browse files
GuillaumeRxFrederikBolding
authored andcommitted
feat(snaps): allow usage of Text in Value props (#29624)
## **Description** This PR allows the usage of the `Text` component in the Snap UI `Value` component props. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29624?quickstart=1) ## **Related issues** progresses: MetaMask/snaps#2984 ## **Manual testing steps** ```tsx <Box> <Row label="Amount"> <Value value={<Text color="success">1.555 ETH</Text>} extra={<Text color="error">2.44 $</Text>} /> </Row> </Box> ``` ## **Screenshots/Recordings** ![image](https://github.com/user-attachments/assets/44d06181-cd3c-472b-8067-a665c6bbc81f) ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent e2b3211 commit 1844e67

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

ui/components/app/confirm/info/row/value-double.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { ReactNode } from 'react';
22
import { Box, Text } from '../../../../component-library';
33
import {
44
AlignItems,
@@ -12,8 +12,8 @@ import { useRowContext } from './hook';
1212
import { ConfirmInfoRowVariant } from './row';
1313

1414
export type ConfirmInfoRowValueDoubleProps = {
15-
left: string;
16-
right: string;
15+
left: ReactNode;
16+
right: ReactNode;
1717
};
1818

1919
const LEFT_TEXT_COLORS = {
@@ -35,8 +35,16 @@ export const ConfirmInfoRowValueDouble = ({
3535
flexWrap={FlexWrap.Wrap}
3636
gap={1}
3737
>
38-
<Text color={LEFT_TEXT_COLORS[variant] as TextColor}>{left}</Text>
39-
<Text color={TextColor.inherit}>{right}</Text>
38+
{typeof left === 'string' ? (
39+
<Text color={LEFT_TEXT_COLORS[variant] as TextColor}>{left}</Text>
40+
) : (
41+
left
42+
)}
43+
{typeof right === 'string' ? (
44+
<Text color={TextColor.inherit}>{right}</Text>
45+
) : (
46+
right
47+
)}
4048
</Box>
4149
);
4250
};
Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
import { ValueElement } from '@metamask/snaps-sdk/jsx';
2+
import { mapToTemplate } from '../utils';
23
import { UIComponentFactory } from './types';
34

4-
export const value: UIComponentFactory<ValueElement> = ({ element }) => ({
5-
element: 'ConfirmInfoRowValueDouble',
6-
props: {
7-
left: element.props.extra,
8-
right: element.props.value,
9-
},
10-
});
5+
export const value: UIComponentFactory<ValueElement> = ({
6+
element,
7+
...params
8+
}) => {
9+
return {
10+
element: 'ConfirmInfoRowValueDouble',
11+
props: {
12+
left:
13+
typeof element.props.extra === 'string'
14+
? element.props.extra
15+
: undefined,
16+
right:
17+
typeof element.props.value === 'string'
18+
? element.props.value
19+
: undefined,
20+
},
21+
propComponents: {
22+
left:
23+
typeof element.props.extra === 'string'
24+
? undefined
25+
: mapToTemplate({ element: element.props.extra, ...params }),
26+
right:
27+
typeof element.props.value === 'string'
28+
? undefined
29+
: mapToTemplate({ element: element.props.value, ...params }),
30+
},
31+
};
32+
};

0 commit comments

Comments
 (0)