Skip to content

Commit

Permalink
Creating network value component for re-designed confirmation pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri committed Oct 16, 2024
1 parent fc55bce commit 6513ca6
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ exports[`Confirm should match snapshot for personal sign 1`] = `
}
}
>
Ethereum Main Network
Mainnet
</Text>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ import Badge, {
BadgeVariant,
} from '../../../../../../../component-library/components/Badges/Badge';
import BadgeWrapper from '../../../../../../../component-library/components/Badges/BadgeWrapper';
import { RootState } from '../../../../../../UI/BasicFunctionality/BasicFunctionalityModal/BasicFunctionalityModal.test';
import { selectChainId } from '../../../../../../../selectors/networkController';
import { useStyles } from '../../../../../../../component-library/hooks';
import {
selectNetworkImageSource,
selectNetworkName,
} from '../../../../../../../selectors/networkInfos';
import { RootState } from '../../../../../../UI/BasicFunctionality/BasicFunctionalityModal/BasicFunctionalityModal.test';
import useAccountInfo from '../../../../hooks/useAccountInfo';
import useApprovalRequest from '../../../../hooks/useApprovalRequest';
import useNetworkInfo from '../../../../hooks/useNetworkInfo';
import styleSheet from './AccountNetworkInfoCollapsed.styles';

const AccountNetworkInfoCollapsed = () => {
const { approvalRequest } = useApprovalRequest();
const networkName = useSelector(selectNetworkName);
const networkImage = useSelector(selectNetworkImageSource);
const chainId = useSelector(selectChainId);
const { networkName, networkImage } = useNetworkInfo(chainId);
const useBlockieIcon = useSelector(
(state: RootState) => state.settings.useBlockieIcon,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ exports[`AccountNetworkInfoCollapsed should match snapshot for personal sign 1`]
}
}
>
Ethereum Main Network
Mainnet
</Text>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import { View } from 'react-native';
import { useSelector } from 'react-redux';

import { strings } from '../../../../../../../../locales/i18n';
import { selectProviderConfig } from '../../../../../../../selectors/networkController';
import { selectNetworkName } from '../../../../../../../selectors/networkInfos';
import {
selectChainId,
selectProviderConfig,
} from '../../../../../../../selectors/networkController';
import useAccountInfo from '../../../../hooks/useAccountInfo';
import useApprovalRequest from '../../../../hooks/useApprovalRequest';
import InfoSection from '../../../UI/InfoRow/InfoSection';
import InfoRow from '../../../UI/InfoRow';
import InfoURL from '../../../UI/InfoRow/InfoValue/InfoURL';
import Url from '../../../UI/InfoRow/InfoValue/Url';
import Network from '../../../UI/InfoRow/InfoValue/Network';

// todo: use value component for address, network, currency value
// todo: use value component for address, currency value
const AccountNetworkInfoExpanded = () => {
const { approvalRequest } = useApprovalRequest();
const networkName = useSelector(selectNetworkName);
const chainId = useSelector(selectChainId);
const { rpcUrl: networkRpcUrl, type: networkType } =
useSelector(selectProviderConfig);
const fromAddress = approvalRequest?.requestData?.from;
Expand All @@ -32,12 +35,10 @@ const AccountNetworkInfoExpanded = () => {
// todo: add tooltip content when available
tooltip={strings('confirm.network')}
>
{networkName}
<Network chainId={chainId} />
</InfoRow>
<InfoRow label={strings('confirm.rpc_url')}>
<InfoURL
url={networkRpcUrl ?? `https://${networkType}.infura.io/v3/`}
/>
<Url url={networkRpcUrl ?? `https://${networkType}.infura.io/v3/`} />
</InfoRow>
</InfoSection>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,61 @@ exports[`AccountNetworkInfoExpanded should match snapshot for personal sign 1`]
/>
</View>
</View>
<Text
<View
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"marginTop": 8,
"alignItems": "center",
"display": "flex",
"flexDirection": "row",
}
}
>
Ethereum Main Network
</Text>
<View
style={
{
"alignItems": "center",
"backgroundColor": "#ffffff",
"borderRadius": 12,
"height": 24,
"justifyContent": "center",
"overflow": "hidden",
"width": 24,
}
}
>
<Image
onError={[Function]}
resizeMode="contain"
source={
{
"default": {
"uri": "MockImage",
},
}
}
style={
{
"height": 24,
"width": 24,
}
}
testID="network-avatar-image"
/>
</View>
<Text
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"marginLeft": 8,
}
}
>
Mainnet
</Text>
</View>
</View>
<View
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ exports[`AccountNetworkInfo should match snapshot for personal sign 1`] = `
}
}
>
Ethereum Main Network
Mainnet
</Text>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { strings } from '../../../../../../../../locales/i18n';
import useApprovalRequest from '../../../../hooks/useApprovalRequest';
import InfoSection from '../../../UI/InfoRow/InfoSection';
import InfoRow from '../../../UI/InfoRow';
import InfoURL from '../../../UI/InfoRow/InfoValue/InfoURL';
import Url from '../../../UI/InfoRow/InfoValue/Url';
import Message from './Message';
import Simulation from './Simulation';

Expand All @@ -23,7 +23,7 @@ const PersonalSign = () => {
label={strings('confirm.request_from')}
tooltip={strings('confirm.personal_sign_tooltip')}
>
<InfoURL url={approvalRequest.origin} />
<Url url={approvalRequest.origin} />
</InfoRow>
</InfoSection>
<Message />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StyleProp, Text, TextStyle, View } from 'react-native';

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

const style = {
container: { padding: 8 },
Expand All @@ -30,10 +30,10 @@ storiesOf('Confirmations / InfoRow', module)
<Text style={style.title as StyleProp<TextStyle>}>URL</Text>
<InfoSection>
<InfoRow label="url-key">
<InfoURL url="https://google.com" />
<Url url="https://google.com" />
</InfoRow>
<InfoRow label="url-key">
<InfoURL url="http://google.com" />
<Url url="http://google.com" />
</InfoRow>
</InfoSection>
</View>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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,
marginLeft: 8,
},
});
};

export default styleSheet;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { CHAIN_IDS } from '@metamask/transaction-controller';
import React from 'react';

import renderWithProvider from '../../../../../../../../util/test/renderWithProvider';
import { backgroundState } from '../../../../../../../../util/test/initial-root-state';
import { mockNetworkState } from '../../../../../../../../util/test/network';
import Network from './Network';

const mockInitialState = {
engine: {
backgroundState: {
...backgroundState,
NetworkController: {
...mockNetworkState({
id: 'mainnet',
nickname: 'Ethereum Mainnet',
ticker: 'ETH',
chainId: CHAIN_IDS.MAINNET,
}),
},
},
},
};

describe('URL', () => {
it('should display url as expected', async () => {
const container = renderWithProvider(
<Network chainId={CHAIN_IDS.MAINNET} />,
{ state: mockInitialState },
);
expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { Text, View } from 'react-native';

import Avatar, {
AvatarSize,
AvatarVariant,
} from '../../../../../../../../component-library/components/Avatars/Avatar';
import { useStyles } from '../../../../../../../../component-library/hooks';
import useNetworkInfo from '../../../../../hooks/useNetworkInfo';
import styleSheet from './Network.styles';

interface NetworkProps {
chainId?: string;
}

const Network = ({ chainId }: NetworkProps) => {
const { networkName, networkImage } = useNetworkInfo(chainId);
const { styles } = useStyles(styleSheet, {});

if (!chainId) {
return null;
}

return (
<View style={styles.container}>
<Avatar
variant={AvatarVariant.Network}
name={networkName}
imageSource={networkImage}
size={AvatarSize.Sm}
/>
<Text style={styles.value}>{networkName}</Text>
</View>
);
};

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

exports[`URL should display url as expected 1`] = `
<View
style={
{
"alignItems": "center",
"display": "flex",
"flexDirection": "row",
}
}
>
<View
style={
{
"alignItems": "center",
"backgroundColor": "#ffffff",
"borderRadius": 12,
"height": 24,
"justifyContent": "center",
"overflow": "hidden",
"width": 24,
}
}
>
<Image
onError={[Function]}
resizeMode="contain"
source={
{
"default": {
"uri": "MockImage",
},
}
}
style={
{
"height": 24,
"width": 24,
}
}
testID="network-avatar-image"
/>
</View>
<Text
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"marginLeft": 8,
}
}
>
Ethereum Mainnet
</Text>
</View>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Network';
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import { render } from '@testing-library/react-native';

import InfoURL from './index';
import Url from './Url';

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

it('should show warning if protocol is HTTP', async () => {
const { getByText } = render(<InfoURL url="http://google.com" />);
const { getByText } = render(<Url url="http://google.com" />);
expect(getByText('HTTP')).toBeDefined();
});
});
Loading

0 comments on commit 6513ca6

Please sign in to comment.