2022-02-25 17:50:16 +01:00
|
|
|
import React, { useContext } from 'react';
|
2022-04-25 20:30:46 +02:00
|
|
|
import { useSelector } from 'react-redux';
|
2022-02-25 17:50:16 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
|
|
|
import Box from '../../ui/box';
|
|
|
|
import Typography from '../../ui/typography';
|
|
|
|
import {
|
|
|
|
ALIGN_ITEMS,
|
|
|
|
BLOCK_SIZES,
|
|
|
|
COLORS,
|
|
|
|
DISPLAY,
|
|
|
|
FLEX_DIRECTION,
|
2022-04-25 20:30:46 +02:00
|
|
|
FONT_WEIGHT,
|
2022-02-25 17:50:16 +01:00
|
|
|
TYPOGRAPHY,
|
2022-04-25 20:30:46 +02:00
|
|
|
JUSTIFY_CONTENT,
|
2022-02-25 17:50:16 +01:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import Button from '../../ui/button';
|
2022-03-08 22:50:35 +01:00
|
|
|
import IconCaretLeft from '../../ui/icon/icon-caret-left';
|
2022-04-25 20:30:46 +02:00
|
|
|
import Tooltip from '../../ui/tooltip';
|
|
|
|
import IconWithFallback from '../../ui/icon-with-fallback';
|
|
|
|
import IconBorder from '../../ui/icon-border';
|
|
|
|
import { getTheme } from '../../../selectors';
|
|
|
|
import { THEME_TYPE } from '../../../pages/settings/experimental-tab/experimental-tab.constant';
|
2022-02-25 17:50:16 +01:00
|
|
|
|
|
|
|
const AddNetwork = ({
|
|
|
|
onBackClick,
|
|
|
|
onAddNetworkClick,
|
|
|
|
onAddNetworkManuallyClick,
|
|
|
|
featuredRPCS,
|
|
|
|
}) => {
|
|
|
|
const t = useContext(I18nContext);
|
2022-04-25 20:30:46 +02:00
|
|
|
const theme = useSelector(getTheme);
|
|
|
|
|
|
|
|
const infuraRegex = /infura.io/u;
|
2022-02-25 17:50:16 +01:00
|
|
|
|
|
|
|
const nets = featuredRPCS
|
|
|
|
.sort((a, b) => (a.ticker > b.ticker ? 1 : -1))
|
2022-04-25 20:30:46 +02:00
|
|
|
.slice(0, 8);
|
2022-02-25 17:50:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Box
|
|
|
|
height={BLOCK_SIZES.TWO_TWELFTHS}
|
|
|
|
padding={[4, 0, 4, 0]}
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
alignItems={ALIGN_ITEMS.CENTER}
|
|
|
|
flexDirection={FLEX_DIRECTION.ROW}
|
|
|
|
className="add-network__header"
|
|
|
|
>
|
2022-03-08 22:50:35 +01:00
|
|
|
<IconCaretLeft
|
|
|
|
aria-label={t('back')}
|
2022-02-25 17:50:16 +01:00
|
|
|
onClick={onBackClick}
|
|
|
|
className="add-network__header__back-icon"
|
|
|
|
/>
|
2022-03-09 16:24:53 +01:00
|
|
|
<Typography variant={TYPOGRAPHY.H3} color={COLORS.TEXT_DEFAULT}>
|
2022-02-25 17:50:16 +01:00
|
|
|
{t('addNetwork')}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
height={BLOCK_SIZES.FOUR_FIFTHS}
|
|
|
|
width={BLOCK_SIZES.TEN_TWELFTHS}
|
|
|
|
margin={[0, 6, 0, 6]}
|
|
|
|
>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H6}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_ALTERNATIVE}
|
2022-02-25 17:50:16 +01:00
|
|
|
margin={[4, 0, 0, 0]}
|
|
|
|
>
|
|
|
|
{t('addFromAListOfPopularNetworks')}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H7}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_MUTED}
|
2022-02-25 17:50:16 +01:00
|
|
|
margin={[4, 0, 3, 0]}
|
|
|
|
>
|
2022-04-25 20:30:46 +02:00
|
|
|
{t('popularCustomNetworks')}
|
2022-02-25 17:50:16 +01:00
|
|
|
</Typography>
|
|
|
|
{nets.map((item, index) => (
|
|
|
|
<Box
|
|
|
|
key={index}
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
alignItems={ALIGN_ITEMS.CENTER}
|
2022-04-25 20:30:46 +02:00
|
|
|
justifyContent={JUSTIFY_CONTENT.SPACE_BETWEEN}
|
2022-02-25 17:50:16 +01:00
|
|
|
marginBottom={6}
|
|
|
|
>
|
2022-04-25 20:30:46 +02:00
|
|
|
<Box display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.CENTER}>
|
|
|
|
<IconBorder size={24}>
|
|
|
|
<IconWithFallback
|
|
|
|
icon={item.rpcPrefs.imageUrl}
|
|
|
|
name={item.nickname}
|
|
|
|
size={24}
|
|
|
|
/>
|
|
|
|
</IconBorder>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
color={COLORS.TEXT_DEFAULT}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
boxProps={{ marginLeft: 2 }}
|
|
|
|
>
|
|
|
|
{item.nickname}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.CENTER}>
|
|
|
|
{
|
|
|
|
// Warning for the networks that doesn't use infura.io as the RPC
|
|
|
|
!infuraRegex.test(item.rpcUrl) && (
|
|
|
|
<Tooltip
|
|
|
|
className="add-network__warning-tooltip"
|
|
|
|
position="top"
|
|
|
|
interactive
|
|
|
|
html={
|
|
|
|
<Box margin={3} className="add-network__warning-tooltip">
|
|
|
|
{t('addNetworkTooltipWarning', [
|
|
|
|
<a
|
|
|
|
key="zendesk_page_link"
|
|
|
|
href="https://metamask.zendesk.com/hc/en-us/articles/4417500466971"
|
|
|
|
rel="noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{t('learnMoreUpperCase')}
|
|
|
|
</a>,
|
|
|
|
])}
|
|
|
|
</Box>
|
|
|
|
}
|
|
|
|
trigger="mouseenter"
|
|
|
|
theme={theme === THEME_TYPE.DEFAULT ? 'light' : 'dark'}
|
|
|
|
>
|
|
|
|
<i
|
|
|
|
className="fa fa-exclamation-triangle add-network__warning-icon"
|
|
|
|
title={t('warning')}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
<Button
|
|
|
|
type="inline"
|
|
|
|
className="add-network__add-button"
|
|
|
|
onClick={onAddNetworkClick}
|
|
|
|
>
|
|
|
|
{t('add')}
|
|
|
|
</Button>
|
|
|
|
</Box>
|
2022-02-25 17:50:16 +01:00
|
|
|
</Box>
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
height={BLOCK_SIZES.ONE_TWELFTH}
|
|
|
|
padding={[4, 4, 4, 4]}
|
|
|
|
className="add-network__footer"
|
|
|
|
>
|
|
|
|
<Button type="link" onClick={onAddNetworkManuallyClick}>
|
2022-03-09 16:24:53 +01:00
|
|
|
<Typography variant={TYPOGRAPHY.H6} color={COLORS.PRIMARY_DEFAULT}>
|
2022-02-25 17:50:16 +01:00
|
|
|
{t('addANetworkManually')}
|
|
|
|
</Typography>
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
AddNetwork.propTypes = {
|
|
|
|
onBackClick: PropTypes.func,
|
|
|
|
onAddNetworkClick: PropTypes.func,
|
|
|
|
onAddNetworkManuallyClick: PropTypes.func,
|
|
|
|
featuredRPCS: PropTypes.array,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AddNetwork;
|