Skip to content

Commit

Permalink
feat: add url value component for use in re-designed confirmation pag…
Browse files Browse the repository at this point in the history
…es (#11567)

## **Description**

Add url value component for use in re-designed confirmation pages

## **Related issues**

Fixes: #11496

## **Manual testing steps**

1. Run storybook locally
2. Check confirmations -> info row story

## **Screenshots/Recordings**
<img width="399" alt="Screenshot 2024-10-02 at 3 08 32 PM"
src="https://github.com/user-attachments/assets/6c4427bb-34ac-411b-954f-d5a12964e753">

## **Pre-merge author checklist**

- [X] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [X] I've completed the PR template to the best of my ability
- [X] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [X] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/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.
  • Loading branch information
jpuri authored Oct 4, 2024
1 parent bdc9043 commit c531cf8
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 17 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,7 @@
- [#10383](https://github.com/MetaMask/metamask-mobile/pull/10383): fix: race condition issues when doing batch-rpc calls in the DeeplinkProtocolService (#10383)
- [#10365](https://github.com/MetaMask/metamask-mobile/pull/10365): fix: attribution link (#10365)
- [#10303](https://github.com/MetaMask/metamask-mobile/pull/10303): fix: page navigation during QR accounts selection (#10303)
<<<<<<< HEAD

=======
>>>>>>> main
## 7.28.1 - Aug 15, 2024
### Fixed
- [#10637](https://github.com/MetaMask/metamask-mobile/pull/10637): fix: swap button blocked by SwapsController polling issue (#10637)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ storiesOf('Confirmations / ExpandableSection', module)
.addDecorator((getStory) => getStory())
.add('Default', () => (
<ExpandableSection
content={
collapsedContent={
<View>
<Text>Open</Text>
</View>
}
modalContent={
expandedContent={
<InfoSection>
<InfoRow label="label-Key">Value-Text</InfoRow>
</InfoSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe('ExpandableSection', () => {
it('should match snapshot for simple ExpandableSection', async () => {
const container = render(
<ExpandableSection
content={
collapsedContent={
<View>
<Text>Open</Text>
</View>
}
modalContent={
expandedContent={
<InfoSection>
<InfoRow label="label-Key">Value-Text</InfoRow>
</InfoSection>
Expand All @@ -29,12 +29,12 @@ describe('ExpandableSection', () => {
it('should display default content', async () => {
const { getByText } = render(
<ExpandableSection
content={
collapsedContent={
<View>
<Text>Open</Text>
</View>
}
modalContent={
expandedContent={
<InfoSection>
<InfoRow label="label-Key">Value-Text</InfoRow>
</InfoSection>
Expand All @@ -48,12 +48,12 @@ describe('ExpandableSection', () => {
it('should open modal when right icon is pressed', async () => {
const { getByTestId, getByText } = render(
<ExpandableSection
content={
collapsedContent={
<View>
<Text>Open</Text>
</View>
}
modalContent={
expandedContent={
<InfoSection>
<InfoRow label="label-Key">Value-Text</InfoRow>
</InfoSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import BottomModal from '../BottomModal';
import styleSheet from './ExpandableSection.styles';

interface ExpandableSectionProps {
content: ReactNode;
modalContent: ReactNode;
collapsedContent: ReactNode;
expandedContent: ReactNode;
modalTitle: string;
openButtonTestId?: string;
closeButtonTestId?: string;
}

const ExpandableSection = ({
content,
modalContent,
collapsedContent,
expandedContent,
modalTitle,
openButtonTestId,
closeButtonTestId,
Expand All @@ -33,7 +33,7 @@ const ExpandableSection = ({
return (
<View>
<View style={styles.container}>
{content}
{collapsedContent}
<ButtonIcon
iconColor={IconColor.Muted}
size={ButtonIconSizes.Sm}
Expand All @@ -56,7 +56,7 @@ const ExpandableSection = ({
/>
<Text style={styles.modalTitle}>{modalTitle}</Text>
</View>
{modalContent}
{expandedContent}
</View>
</BottomModal>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StyleProp, Text, TextStyle, View } from 'react-native';

import InfoRow from './InfoRow';
import InfoSection from './InfoSection';
import InfoURL from './InfoValue/InfoURL';

const style = {
container: { padding: 8 },
Expand All @@ -26,5 +27,14 @@ storiesOf('Confirmations / InfoRow', module)
Value-Text Value-Text Value-Text Value-Text
</InfoRow>
</InfoSection>
<Text style={style.title as StyleProp<TextStyle>}>URL</Text>
<InfoSection>
<InfoRow label="url-key">
<InfoURL url="https://google.com" />
</InfoRow>
<InfoRow label="url-key">
<InfoURL url="http://google.com" />
</InfoRow>
</InfoSection>
</View>
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { StyleSheet } from 'react-native';

import { Theme } from '../../../../../../../../util/theme/models';
import { fontStyles } from '../../../../../../../../styles/common';

const styleSheet = (params: { theme: Theme }) => {
const { theme } = params;

return StyleSheet.create({
container: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
},
value: {
color: theme.colors.text.default,
...fontStyles.normal,
fontSize: 14,
marginTop: 8,
},
warningContainer: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
marginRight: 8,
marginTop: 8,
paddingVertical: 2,
paddingHorizontal: 4,
backgroundColor: theme.colors.error.muted,
borderRadius: 4,
},
warningText: {
color: theme.colors.error.default,
marginLeft: 4,
},
});
};

export default styleSheet;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { render } from '@testing-library/react-native';

import InfoURL from './index';

describe('InfoURL', () => {
it('should display url as expected', async () => {
const container = render(<InfoURL url="https://google.com" />);
expect(container).toMatchSnapshot();
});

it('should show warning if protocol is HTTP', async () => {
const { getByText } = render(<InfoURL url="http://google.com" />);
expect(getByText('HTTP')).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import { Text, View } from 'react-native';

import Icon, {
IconColor,
IconName,
IconSize,
} from '../../../../../../../../component-library/components/Icons/Icon';
import Logger from '../../../../../../../../util/Logger';
import { useStyles } from '../../../../../../../../component-library/hooks';
import styleSheet from './InfoURL.styles';

interface InfoURLProps {
url: string;
}

const InfoURL = ({ url }: InfoURLProps) => {
let urlObject;

try {
urlObject = new URL(url);
} catch (e) {
// eslint-disable-next-line no-console
Logger.error(e as Error, `InfoURL: new URL(url) cannot parse ${url}`);
}

const isHTTP = urlObject?.protocol === 'http:';

const urlWithoutProtocol = url?.replace(/https?:\/\//u, '');

const { styles } = useStyles(styleSheet, {});

return (
<View style={styles.container}>
{isHTTP && (
<View style={styles.warningContainer}>
<Icon
color={IconColor.Warning}
size={IconSize.Md}
name={IconName.Danger}
/>
<Text style={styles.warningText}>HTTP</Text>
</View>
)}
<Text style={styles.value}>{urlWithoutProtocol}</Text>
</View>
);
};

export default InfoURL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InfoURL should display url as expected 1`] = `
<View
style={
{
"alignItems": "center",
"display": "flex",
"flexDirection": "row",
}
}
>
<Text
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"marginTop": 8,
}
}
>
google.com
</Text>
</View>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './InfoURL';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { StyleSheet } from 'react-native';

import { Colors } from '../../../../../../../../util/theme/models';
import { fontStyles } from '../../../../../../../../styles/common';

const createStyles = (colors: Colors) =>
StyleSheet.create({
container: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
},
value: {
color: colors.text.default,
...fontStyles.normal,
fontSize: 14,
marginTop: 8,
},
warningContainer: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
marginRight: 8,
marginTop: 8,
paddingVertical: 2,
paddingHorizontal: 4,
backgroundColor: colors.error.muted,
borderRadius: 4,
},
warningText: {
color: colors.error.default,
marginLeft: 4,
},
});

export default createStyles;

0 comments on commit c531cf8

Please sign in to comment.