2022-04-25 20:28:52 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import Box from '../../../../components/ui/box';
|
|
|
|
import SiteIcon from '../../../../components/ui/site-icon';
|
|
|
|
import Typography from '../../../../components/ui/typography/typography';
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
TypographyVariant,
|
2022-04-25 20:28:52 +02:00
|
|
|
FONT_WEIGHT,
|
|
|
|
DISPLAY,
|
2023-02-02 21:15:26 +01:00
|
|
|
JustifyContent,
|
2022-04-25 20:28:52 +02:00
|
|
|
BLOCK_SIZES,
|
2023-02-02 21:15:26 +01:00
|
|
|
AlignItems,
|
2022-04-25 20:28:52 +02:00
|
|
|
TEXT_ALIGN,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
2022-04-25 20:28:52 +02:00
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import {
|
|
|
|
CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP,
|
|
|
|
NETWORK_TO_NAME_MAP,
|
|
|
|
} from '../../../../../shared/constants/network';
|
|
|
|
|
|
|
|
export default function ConfirmationNetworkSwitch({ newNetwork }) {
|
|
|
|
const currentNetwork = useSelector((state) => ({
|
|
|
|
nickname: state.metamask.provider.nickname,
|
|
|
|
type: state.metamask.provider.type,
|
|
|
|
chainId: state.metamask.provider.chainId,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
className="confirmation-network-switch"
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
height={BLOCK_SIZES.FULL}
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.center}
|
2022-04-25 20:28:52 +02:00
|
|
|
marginTop={8}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
className="confirmation-network-switch__icon"
|
|
|
|
display={DISPLAY.BLOCK}
|
|
|
|
>
|
|
|
|
{currentNetwork.chainId in CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP ? (
|
|
|
|
<SiteIcon
|
|
|
|
icon={CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP[currentNetwork.chainId]}
|
|
|
|
name={currentNetwork.nickname}
|
|
|
|
size={64}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="confirmation-network-switch__unknown-icon">
|
|
|
|
<i className="fa fa-question fa-2x" />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
|
|
|
variant={TypographyVariant.H6}
|
2022-04-25 20:28:52 +02:00
|
|
|
fontWeight={FONT_WEIGHT.NORMAL}
|
|
|
|
align={TEXT_ALIGN.CENTER}
|
|
|
|
boxProps={{
|
|
|
|
display: DISPLAY.FLEX,
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent: JustifyContent.center,
|
2022-04-25 20:28:52 +02:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{currentNetwork.nickname || NETWORK_TO_NAME_MAP[currentNetwork.type]}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
className="confirmation-network-switch__center-icon"
|
|
|
|
display={DISPLAY.FLEX}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.center}
|
2022-04-25 20:28:52 +02:00
|
|
|
>
|
|
|
|
<i className="fa fa-angle-right fa-lg confirmation-network-switch__check" />
|
|
|
|
<div className="confirmation-network-switch__dashed-line" />
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
className="confirmation-network-switch__icon"
|
|
|
|
display={DISPLAY.BLOCK}
|
|
|
|
>
|
|
|
|
{newNetwork.chainId in CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP ? (
|
|
|
|
<SiteIcon
|
|
|
|
icon={CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP[newNetwork.chainId]}
|
2023-03-09 22:00:28 +01:00
|
|
|
name={newNetwork.nickname}
|
2022-04-25 20:28:52 +02:00
|
|
|
size={64}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="confirmation-network-switch__unknown-icon">
|
|
|
|
<i className="fa fa-question fa-2x" />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
|
|
|
variant={TypographyVariant.H6}
|
2022-04-25 20:28:52 +02:00
|
|
|
fontWeight={FONT_WEIGHT.NORMAL}
|
|
|
|
align={TEXT_ALIGN.CENTER}
|
|
|
|
boxProps={{
|
|
|
|
display: DISPLAY.FLEX,
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent: JustifyContent.center,
|
2022-04-25 20:28:52 +02:00
|
|
|
}}
|
|
|
|
>
|
2023-03-09 22:00:28 +01:00
|
|
|
{newNetwork.nickname}
|
2022-04-25 20:28:52 +02:00
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmationNetworkSwitch.propTypes = {
|
|
|
|
newNetwork: PropTypes.shape({
|
|
|
|
chainId: PropTypes.string.isRequired,
|
2023-03-09 22:00:28 +01:00
|
|
|
nickname: PropTypes.string.isRequired,
|
2022-04-25 20:28:52 +02:00
|
|
|
}),
|
|
|
|
};
|