2022-08-23 17:52:08 +02:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2022-10-25 17:03:45 +02:00
|
|
|
import IconWithFallback from '../../ui/icon-with-fallback';
|
2022-10-06 16:43:52 +02:00
|
|
|
import Identicon from '../../ui/identicon';
|
2022-08-23 17:52:08 +02:00
|
|
|
import {
|
2023-06-21 00:14:45 +02:00
|
|
|
Display,
|
|
|
|
FlexDirection,
|
2023-05-05 13:14:09 +02:00
|
|
|
TextVariant,
|
|
|
|
FontWeight,
|
2023-02-02 21:15:26 +01:00
|
|
|
AlignItems,
|
|
|
|
JustifyContent,
|
2023-05-05 13:14:09 +02:00
|
|
|
TextAlign,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
2022-08-23 17:52:08 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import Box from '../../ui/box/box';
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
2022-10-25 17:03:45 +02:00
|
|
|
import { CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP } from '../../../../shared/constants/network';
|
2023-07-14 19:59:30 +02:00
|
|
|
import { Text } from '../../component-library/text/deprecated';
|
2022-08-23 17:52:08 +02:00
|
|
|
|
|
|
|
export default function NetworkAccountBalanceHeader({
|
|
|
|
networkName,
|
|
|
|
accountName,
|
|
|
|
accountBalance,
|
2022-10-25 17:03:45 +02:00
|
|
|
tokenName, // Derived from nativeCurrency
|
2022-08-23 17:52:08 +02:00
|
|
|
accountAddress,
|
2022-10-25 17:03:45 +02:00
|
|
|
chainId,
|
2022-08-23 17:52:08 +02:00
|
|
|
}) {
|
|
|
|
const t = useContext(I18nContext);
|
2022-10-25 17:03:45 +02:00
|
|
|
const networkIcon = CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP[chainId];
|
|
|
|
const networkIconWrapperClass = networkIcon
|
|
|
|
? 'network-account-balance-header__network-account__ident-icon-ethereum'
|
|
|
|
: 'network-account-balance-header__network-account__ident-icon-ethereum--gray';
|
2022-08-23 17:52:08 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Box
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Row}
|
2022-08-23 17:52:08 +02:00
|
|
|
padding={4}
|
|
|
|
className="network-account-balance-header"
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.spaceBetween}
|
2022-08-23 17:52:08 +02:00
|
|
|
>
|
|
|
|
<Box
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Row}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
2022-08-23 17:52:08 +02:00
|
|
|
gap={2}
|
|
|
|
>
|
|
|
|
<Box
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Row}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
2022-08-23 17:52:08 +02:00
|
|
|
>
|
|
|
|
<Identicon address={accountAddress} diameter={32} />
|
2022-10-25 17:03:45 +02:00
|
|
|
<IconWithFallback
|
|
|
|
name={networkName}
|
|
|
|
size={16}
|
|
|
|
icon={networkIcon}
|
|
|
|
wrapperClassName={networkIconWrapperClass}
|
2022-08-23 17:52:08 +02:00
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
<Box
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.flexStart}
|
2023-06-21 00:14:45 +02:00
|
|
|
flexDirection={FlexDirection.Column}
|
2022-08-23 17:52:08 +02:00
|
|
|
>
|
2023-05-05 13:14:09 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2022-08-23 17:52:08 +02:00
|
|
|
>
|
|
|
|
{networkName}
|
2023-05-05 13:14:09 +02:00
|
|
|
</Text>
|
2022-08-23 17:52:08 +02:00
|
|
|
|
2023-05-05 13:14:09 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
2023-05-05 13:14:09 +02:00
|
|
|
fontWeight={FontWeight.Bold}
|
2022-08-23 17:52:08 +02:00
|
|
|
>
|
|
|
|
{accountName}
|
2023-05-05 13:14:09 +02:00
|
|
|
</Text>
|
2022-08-23 17:52:08 +02:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<Box
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.flexEnd}
|
2023-06-21 00:14:45 +02:00
|
|
|
flexDirection={FlexDirection.Column}
|
2022-08-23 17:52:08 +02:00
|
|
|
>
|
2023-05-05 13:14:09 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2022-08-23 17:52:08 +02:00
|
|
|
>
|
|
|
|
{t('balance')}
|
2023-05-05 13:14:09 +02:00
|
|
|
</Text>
|
2022-08-23 17:52:08 +02:00
|
|
|
|
2023-05-05 13:14:09 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textDefault}
|
2023-05-05 13:14:09 +02:00
|
|
|
fontWeight={FontWeight.Bold}
|
|
|
|
align={TextAlign.End}
|
2022-08-23 17:52:08 +02:00
|
|
|
>
|
|
|
|
{accountBalance} {tokenName}
|
2023-05-05 13:14:09 +02:00
|
|
|
</Text>
|
2022-08-23 17:52:08 +02:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkAccountBalanceHeader.propTypes = {
|
|
|
|
networkName: PropTypes.string,
|
|
|
|
accountName: PropTypes.string,
|
2022-09-21 16:15:34 +02:00
|
|
|
accountBalance: PropTypes.string,
|
2022-08-23 17:52:08 +02:00
|
|
|
tokenName: PropTypes.string,
|
|
|
|
accountAddress: PropTypes.string,
|
2022-10-25 17:03:45 +02:00
|
|
|
chainId: PropTypes.string,
|
2022-08-23 17:52:08 +02:00
|
|
|
};
|