2023-04-17 17:06:41 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2023-04-27 12:27:31 +02:00
|
|
|
import CustodyLabels from '../../../components/institutional/custody-labels';
|
|
|
|
import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/swaps';
|
|
|
|
import { CHAIN_IDS } from '../../../../shared/constants/network';
|
|
|
|
import { shortenAddress } from '../../../helpers/utils/util';
|
|
|
|
import Tooltip from '../../../components/ui/tooltip';
|
2023-04-17 17:06:41 +02:00
|
|
|
import {
|
|
|
|
TextVariant,
|
|
|
|
JustifyContent,
|
2023-07-13 18:27:49 +02:00
|
|
|
BlockSize,
|
|
|
|
Display,
|
2023-04-17 17:06:41 +02:00
|
|
|
IconColor,
|
2023-07-13 18:27:49 +02:00
|
|
|
FlexDirection,
|
|
|
|
AlignItems,
|
2023-04-27 12:27:31 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2023-04-17 17:06:41 +02:00
|
|
|
import {
|
2023-07-13 18:27:49 +02:00
|
|
|
Box,
|
|
|
|
Button,
|
2023-04-17 17:06:41 +02:00
|
|
|
Label,
|
|
|
|
Icon,
|
|
|
|
IconName,
|
|
|
|
IconSize,
|
|
|
|
ButtonLink,
|
2023-07-13 18:27:49 +02:00
|
|
|
BUTTON_VARIANT,
|
|
|
|
BUTTON_SIZES,
|
2023-07-20 21:49:35 +02:00
|
|
|
Text,
|
2023-04-27 12:27:31 +02:00
|
|
|
} from '../../../components/component-library';
|
|
|
|
import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard';
|
2023-04-17 17:06:41 +02:00
|
|
|
|
|
|
|
const getButtonLinkHref = (account) => {
|
|
|
|
const url = SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[CHAIN_IDS.MAINNET];
|
|
|
|
return `${url}address/${account.address}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function CustodyAccountList({
|
|
|
|
rawList,
|
|
|
|
accounts,
|
|
|
|
onAccountChange,
|
2023-07-13 18:27:49 +02:00
|
|
|
selectedAccounts,
|
2023-04-17 17:06:41 +02:00
|
|
|
onCancel,
|
|
|
|
onAddAccounts,
|
|
|
|
custody,
|
|
|
|
}) {
|
|
|
|
const t = useI18nContext();
|
|
|
|
const [copied, handleCopy] = useCopyToClipboard();
|
|
|
|
const tooltipText = copied ? t('copiedExclamation') : t('copyToClipboard');
|
2023-07-13 18:27:49 +02:00
|
|
|
const disabled =
|
|
|
|
!selectedAccounts || Object.keys(selectedAccounts).length === 0;
|
2023-04-17 17:06:41 +02:00
|
|
|
|
|
|
|
return (
|
2023-07-13 18:27:49 +02:00
|
|
|
<Box className="page-container">
|
|
|
|
<Box padding={4} className="page-container__content">
|
2023-04-17 17:06:41 +02:00
|
|
|
<Box
|
2023-07-13 18:27:49 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
|
|
|
width={BlockSize.Full}
|
2023-04-17 17:06:41 +02:00
|
|
|
className="custody-account-list"
|
|
|
|
data-testid="custody-account-list"
|
|
|
|
>
|
|
|
|
{accounts.map((account, idx) => (
|
|
|
|
<Box
|
2023-07-13 18:27:49 +02:00
|
|
|
display={Display.Flex}
|
2023-04-17 17:06:41 +02:00
|
|
|
className="custody-account-list__item"
|
|
|
|
key={account.address}
|
|
|
|
>
|
|
|
|
<Box
|
2023-07-13 18:27:49 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
alignItems={AlignItems.flexStart}
|
2023-04-17 17:06:41 +02:00
|
|
|
data-testid="custody-account-list-item-radio-button"
|
|
|
|
>
|
|
|
|
{!rawList && (
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="selectedAccount"
|
|
|
|
id={`address-${idx}`}
|
2023-07-13 18:27:49 +02:00
|
|
|
onChange={() =>
|
2023-04-17 17:06:41 +02:00
|
|
|
onAccountChange({
|
|
|
|
name: account.name,
|
2023-07-13 18:27:49 +02:00
|
|
|
address: account.address,
|
2023-04-17 17:06:41 +02:00
|
|
|
custodianDetails: account.custodianDetails,
|
|
|
|
labels: account.labels,
|
|
|
|
chainId: account.chainId,
|
|
|
|
})
|
|
|
|
}
|
2023-07-13 18:27:49 +02:00
|
|
|
checked={selectedAccounts[account.address] || false}
|
2023-04-17 17:06:41 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
<Box
|
2023-07-13 18:27:49 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
2023-04-17 17:06:41 +02:00
|
|
|
marginLeft={2}
|
2023-07-13 18:27:49 +02:00
|
|
|
width={BlockSize.Full}
|
2023-04-17 17:06:41 +02:00
|
|
|
>
|
|
|
|
<Label
|
2023-07-13 18:27:49 +02:00
|
|
|
display={Display.Flex}
|
2023-04-17 17:06:41 +02:00
|
|
|
marginTop={2}
|
|
|
|
marginLeft={2}
|
|
|
|
htmlFor={`address-${idx}`}
|
|
|
|
className="custody-account-list__item__title"
|
|
|
|
>
|
|
|
|
<Text
|
|
|
|
as="span"
|
|
|
|
variant={TextVariant.inherit}
|
|
|
|
size={TextVariant.bodySm}
|
|
|
|
paddingRight={1}
|
|
|
|
className="custody-account-list__item__name"
|
|
|
|
>
|
|
|
|
{account.name}
|
|
|
|
</Text>
|
|
|
|
</Label>
|
|
|
|
<Label
|
2023-07-13 18:27:49 +02:00
|
|
|
display={Display.Flex}
|
2023-04-17 17:06:41 +02:00
|
|
|
size={TextVariant.bodySm}
|
|
|
|
marginTop={2}
|
2023-04-27 12:27:31 +02:00
|
|
|
marginLeft={2}
|
2023-04-17 17:06:41 +02:00
|
|
|
marginRight={3}
|
|
|
|
htmlFor={`address-${idx}`}
|
|
|
|
>
|
|
|
|
<Text
|
|
|
|
as="span"
|
|
|
|
variant={TextVariant.bodyMd}
|
2023-07-13 18:27:49 +02:00
|
|
|
display={Display.Flex}
|
2023-04-17 17:06:41 +02:00
|
|
|
className="custody-account-list__item"
|
|
|
|
>
|
|
|
|
<ButtonLink
|
|
|
|
href={getButtonLinkHref(account)}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{shortenAddress(account.address)}
|
|
|
|
<Icon
|
|
|
|
name={IconSize.EXPORT}
|
|
|
|
size={IconName.SM}
|
|
|
|
color={IconColor.primaryDefault}
|
|
|
|
marginLeft={1}
|
|
|
|
/>
|
|
|
|
</ButtonLink>
|
|
|
|
<Tooltip
|
|
|
|
position="bottom"
|
|
|
|
title={tooltipText}
|
|
|
|
style={{ backgroundColor: 'transparent' }}
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
className="custody-account-list__item__clipboard"
|
|
|
|
onClick={() => handleCopy(account.address)}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
name={IconSize.COPY}
|
|
|
|
size={IconName.XS}
|
|
|
|
color={IconColor.iconMuted}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
</Text>
|
|
|
|
</Label>
|
|
|
|
<Box
|
2023-07-13 18:27:49 +02:00
|
|
|
display={Display.Flex}
|
2023-04-17 17:06:41 +02:00
|
|
|
justifyContent={JustifyContent.spaceBetween}
|
|
|
|
>
|
|
|
|
{account.labels && (
|
|
|
|
<CustodyLabels
|
|
|
|
labels={account.labels}
|
|
|
|
index={idx.toString()}
|
|
|
|
hideNetwork
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
{!rawList && (
|
2023-07-13 18:27:49 +02:00
|
|
|
<Box as="footer" className="page-container__footer" padding={4}>
|
|
|
|
<Box display={Display.Flex} gap={4}>
|
|
|
|
<Button
|
|
|
|
data-testid="custody-account-cancel-button"
|
|
|
|
block
|
|
|
|
variant={BUTTON_VARIANT.SECONDARY}
|
|
|
|
size={BUTTON_SIZES.LG}
|
|
|
|
className="custody-account-list__button"
|
|
|
|
onClick={onCancel}
|
|
|
|
>
|
|
|
|
{t('cancel')}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
data-testid="custody-account-connect-button"
|
|
|
|
block
|
|
|
|
variant={BUTTON_VARIANT.PRIMARY}
|
|
|
|
size={BUTTON_SIZES.LG}
|
|
|
|
className="custody-account-list__button"
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={() => onAddAccounts(custody)}
|
|
|
|
>
|
|
|
|
{t('connect')}
|
|
|
|
</Button>
|
|
|
|
</Box>
|
2023-04-17 17:06:41 +02:00
|
|
|
</Box>
|
|
|
|
)}
|
2023-07-13 18:27:49 +02:00
|
|
|
</Box>
|
2023-04-17 17:06:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
CustodyAccountList.propTypes = {
|
|
|
|
custody: PropTypes.string,
|
|
|
|
accounts: PropTypes.array.isRequired,
|
|
|
|
onAccountChange: PropTypes.func,
|
|
|
|
selectedAccounts: PropTypes.object,
|
|
|
|
onAddAccounts: PropTypes.func,
|
|
|
|
onCancel: PropTypes.func,
|
|
|
|
rawList: PropTypes.bool,
|
|
|
|
};
|