2022-08-24 19:12:52 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2022-10-05 21:48:35 +02:00
|
|
|
import { getAccountLink } from '@metamask/etherscan-link';
|
|
|
|
import { useSelector } from 'react-redux';
|
2022-08-24 19:12:52 +02:00
|
|
|
import Box from '../../../ui/box';
|
|
|
|
import Button from '../../../ui/button/button.component';
|
|
|
|
import Tooltip from '../../../ui/tooltip/tooltip';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
2022-10-06 16:43:52 +02:00
|
|
|
import Identicon from '../../../ui/identicon';
|
2022-08-24 19:12:52 +02:00
|
|
|
import { ellipsify } from '../../../../pages/send/send.utils';
|
|
|
|
import Popover from '../../../ui/popover';
|
|
|
|
import {
|
2023-04-25 15:26:58 +02:00
|
|
|
FontWeight,
|
|
|
|
TextVariant,
|
2023-06-21 00:14:45 +02:00
|
|
|
Display,
|
2023-02-02 21:15:26 +01:00
|
|
|
Size,
|
|
|
|
BorderStyle,
|
|
|
|
BorderColor,
|
|
|
|
TextColor,
|
2023-02-04 00:47:45 +01:00
|
|
|
Color,
|
2023-02-09 17:21:51 +01:00
|
|
|
AlignItems,
|
2022-08-24 19:12:52 +02:00
|
|
|
} from '../../../../helpers/constants/design-system';
|
2022-10-05 21:48:35 +02:00
|
|
|
import { useCopyToClipboard } from '../../../../hooks/useCopyToClipboard';
|
|
|
|
import { getAddressBookEntry } from '../../../../selectors';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { TokenStandard } from '../../../../../shared/constants/transaction';
|
2022-11-14 20:28:27 +01:00
|
|
|
import NftCollectionImage from '../../../ui/nft-collection-image/nft-collection-image';
|
2023-04-25 15:26:58 +02:00
|
|
|
import { ButtonIcon, IconName, Text } from '../../../component-library';
|
2022-08-24 19:12:52 +02:00
|
|
|
|
2022-10-05 21:48:35 +02:00
|
|
|
export default function ContractDetailsModal({
|
|
|
|
onClose,
|
|
|
|
tokenName,
|
|
|
|
tokenAddress,
|
|
|
|
toAddress,
|
|
|
|
chainId,
|
|
|
|
rpcPrefs,
|
2022-11-14 20:28:27 +01:00
|
|
|
tokenId,
|
|
|
|
assetName,
|
|
|
|
assetStandard,
|
2022-11-21 18:19:49 +01:00
|
|
|
isContractRequestingSignature,
|
2022-10-05 21:48:35 +02:00
|
|
|
}) {
|
2022-08-24 19:12:52 +02:00
|
|
|
const t = useI18nContext();
|
2022-10-05 21:48:35 +02:00
|
|
|
const [copiedTokenAddress, handleCopyTokenAddress] = useCopyToClipboard();
|
|
|
|
const [copiedToAddress, handleCopyToAddress] = useCopyToClipboard();
|
|
|
|
|
|
|
|
const addressBookEntry = useSelector((state) => ({
|
|
|
|
data: getAddressBookEntry(state, toAddress),
|
|
|
|
}));
|
2022-11-14 20:28:27 +01:00
|
|
|
const nft =
|
2023-01-18 15:47:29 +01:00
|
|
|
assetStandard === TokenStandard.ERC721 ||
|
|
|
|
assetStandard === TokenStandard.ERC1155 ||
|
2022-11-14 20:28:27 +01:00
|
|
|
// if we don't have an asset standard but we do have either both an assetname and a tokenID or both a tokenName and tokenId we assume its an NFT
|
|
|
|
(assetName && tokenId) ||
|
|
|
|
(tokenName && tokenId);
|
2022-08-24 19:12:52 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Popover className="contract-details-modal">
|
|
|
|
<Box
|
|
|
|
paddingTop={6}
|
|
|
|
paddingRight={4}
|
|
|
|
paddingBottom={8}
|
|
|
|
paddingLeft={4}
|
|
|
|
className="contract-details-modal__content"
|
|
|
|
>
|
2023-04-25 15:26:58 +02:00
|
|
|
<Text
|
|
|
|
fontWeight={FontWeight.Bold}
|
|
|
|
variant={TextVariant.bodyMd}
|
|
|
|
as="h5"
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2022-08-24 19:12:52 +02:00
|
|
|
>
|
|
|
|
{t('contractTitle')}
|
2023-04-25 15:26:58 +02:00
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2023-06-21 00:14:45 +02:00
|
|
|
marginTop={2}
|
2022-08-24 19:12:52 +02:00
|
|
|
>
|
|
|
|
{t('contractDescription')}
|
2023-04-25 15:26:58 +02:00
|
|
|
</Text>
|
2022-11-21 18:19:49 +01:00
|
|
|
{!isContractRequestingSignature && (
|
|
|
|
<>
|
2023-04-25 15:26:58 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2022-08-24 19:12:52 +02:00
|
|
|
marginTop={4}
|
2022-11-21 18:19:49 +01:00
|
|
|
marginBottom={2}
|
2022-08-24 19:12:52 +02:00
|
|
|
>
|
2022-11-21 18:19:49 +01:00
|
|
|
{nft ? t('contractNFT') : t('contractToken')}
|
2023-04-25 15:26:58 +02:00
|
|
|
</Text>
|
2022-11-21 18:19:49 +01:00
|
|
|
<Box
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-02 21:15:26 +01:00
|
|
|
borderRadius={Size.SM}
|
|
|
|
borderStyle={BorderStyle.solid}
|
|
|
|
borderColor={BorderColor.borderDefault}
|
2022-11-21 18:19:49 +01:00
|
|
|
className="contract-details-modal__content__contract"
|
|
|
|
>
|
|
|
|
{nft ? (
|
|
|
|
<Box margin={4}>
|
|
|
|
<NftCollectionImage
|
|
|
|
assetName={assetName}
|
|
|
|
tokenAddress={tokenAddress}
|
2022-08-24 19:12:52 +02:00
|
|
|
/>
|
2022-11-21 18:19:49 +01:00
|
|
|
</Box>
|
|
|
|
) : (
|
|
|
|
<Identicon
|
|
|
|
className="contract-details-modal__content__contract__identicon"
|
|
|
|
address={tokenAddress}
|
|
|
|
diameter={24}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Box data-testid="recipient">
|
2023-04-25 15:26:58 +02:00
|
|
|
<Text
|
|
|
|
fontWeight={FontWeight.Bold}
|
|
|
|
variant={TextVariant.bodyMd}
|
|
|
|
as="h5"
|
2022-11-21 18:19:49 +01:00
|
|
|
marginTop={4}
|
|
|
|
>
|
|
|
|
{tokenName || ellipsify(tokenAddress)}
|
2023-04-25 15:26:58 +02:00
|
|
|
</Text>
|
2022-11-21 18:19:49 +01:00
|
|
|
{tokenName && (
|
2023-04-25 15:26:58 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2022-11-21 18:19:49 +01:00
|
|
|
marginBottom={4}
|
|
|
|
>
|
|
|
|
{ellipsify(tokenAddress)}
|
2023-04-25 15:26:58 +02:00
|
|
|
</Text>
|
2022-11-21 18:19:49 +01:00
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
<Box
|
2023-02-09 17:21:51 +01:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
marginLeft="auto"
|
|
|
|
marginRight={4}
|
|
|
|
gap={2}
|
2022-11-21 18:19:49 +01:00
|
|
|
>
|
2023-02-09 17:21:51 +01:00
|
|
|
<Tooltip
|
|
|
|
position="top"
|
|
|
|
title={
|
|
|
|
copiedTokenAddress
|
|
|
|
? t('copiedExclamation')
|
|
|
|
: t('copyToClipboard')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ButtonIcon
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-09 17:21:51 +01:00
|
|
|
iconName={
|
2023-04-19 23:16:49 +02:00
|
|
|
copiedTokenAddress ? IconName.CopySuccess : IconName.Copy
|
2023-02-09 17:21:51 +01:00
|
|
|
}
|
|
|
|
onClick={() => handleCopyTokenAddress(tokenAddress)}
|
|
|
|
color={Color.iconMuted}
|
|
|
|
ariaLabel={
|
2022-11-21 18:19:49 +01:00
|
|
|
copiedTokenAddress
|
|
|
|
? t('copiedExclamation')
|
|
|
|
: t('copyToClipboard')
|
|
|
|
}
|
2023-02-09 17:21:51 +01:00
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip position="top" title={t('openInBlockExplorer')}>
|
|
|
|
<ButtonIcon
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-04-19 23:16:49 +02:00
|
|
|
iconName={IconName.Export}
|
2023-02-09 17:21:51 +01:00
|
|
|
color={Color.iconMuted}
|
|
|
|
onClick={() => {
|
|
|
|
const blockExplorerTokenLink = getAccountLink(
|
|
|
|
tokenAddress,
|
|
|
|
chainId,
|
|
|
|
{
|
|
|
|
blockExplorerUrl: rpcPrefs?.blockExplorerUrl ?? null,
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
);
|
|
|
|
global.platform.openTab({
|
|
|
|
url: blockExplorerTokenLink,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
ariaLabel={t('openInBlockExplorer')}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
2022-11-21 18:19:49 +01:00
|
|
|
</Box>
|
2022-08-24 19:12:52 +02:00
|
|
|
</Box>
|
2022-11-21 18:19:49 +01:00
|
|
|
</>
|
|
|
|
)}
|
2023-04-25 15:26:58 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2022-08-24 19:12:52 +02:00
|
|
|
marginTop={4}
|
|
|
|
marginBottom={2}
|
|
|
|
>
|
2022-11-21 18:19:49 +01:00
|
|
|
{nft && t('contractRequestingAccess')}
|
|
|
|
{isContractRequestingSignature && t('contractRequestingSignature')}
|
|
|
|
{!nft &&
|
|
|
|
!isContractRequestingSignature &&
|
|
|
|
t('contractRequestingSpendingCap')}
|
2023-04-25 15:26:58 +02:00
|
|
|
</Text>
|
2022-08-24 19:12:52 +02:00
|
|
|
<Box
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-02 21:15:26 +01:00
|
|
|
borderRadius={Size.SM}
|
|
|
|
borderStyle={BorderStyle.solid}
|
|
|
|
borderColor={BorderColor.borderDefault}
|
2022-08-24 19:12:52 +02:00
|
|
|
className="contract-details-modal__content__contract"
|
|
|
|
>
|
2023-02-23 15:54:04 +01:00
|
|
|
<Identicon
|
|
|
|
className="contract-details-modal__content__contract__identicon"
|
|
|
|
diameter={24}
|
|
|
|
address={toAddress}
|
|
|
|
/>
|
2022-08-24 19:12:52 +02:00
|
|
|
<Box data-testid="recipient">
|
2023-04-25 15:26:58 +02:00
|
|
|
<Text
|
|
|
|
fontWeight={FontWeight.Bold}
|
|
|
|
variant={TextVariant.bodyMd}
|
|
|
|
as="h5"
|
2022-08-24 19:12:52 +02:00
|
|
|
marginTop={4}
|
|
|
|
>
|
2022-10-05 21:48:35 +02:00
|
|
|
{addressBookEntry?.data?.name || ellipsify(toAddress)}
|
2023-04-25 15:26:58 +02:00
|
|
|
</Text>
|
2022-10-05 21:48:35 +02:00
|
|
|
{addressBookEntry?.data?.name && (
|
2023-04-25 15:26:58 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2022-11-14 20:28:27 +01:00
|
|
|
marginBottom={4}
|
2022-08-24 19:12:52 +02:00
|
|
|
>
|
2022-10-05 21:48:35 +02:00
|
|
|
{ellipsify(toAddress)}
|
2023-04-25 15:26:58 +02:00
|
|
|
</Text>
|
2022-08-24 19:12:52 +02:00
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
<Box
|
2023-02-09 17:21:51 +01:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
marginLeft="auto"
|
|
|
|
marginRight={4}
|
|
|
|
gap={2}
|
2022-08-24 19:12:52 +02:00
|
|
|
>
|
2023-02-09 17:21:51 +01:00
|
|
|
<Tooltip
|
|
|
|
position="top"
|
|
|
|
title={
|
|
|
|
copiedToAddress ? t('copiedExclamation') : t('copyToClipboard')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ButtonIcon
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-02-09 17:21:51 +01:00
|
|
|
iconName={
|
2023-04-19 23:16:49 +02:00
|
|
|
copiedToAddress ? IconName.CopySuccess : IconName.Copy
|
2023-02-09 17:21:51 +01:00
|
|
|
}
|
|
|
|
onClick={() => handleCopyToAddress(toAddress)}
|
|
|
|
color={Color.iconMuted}
|
|
|
|
ariaLabel={
|
|
|
|
copiedTokenAddress
|
2022-10-05 21:48:35 +02:00
|
|
|
? t('copiedExclamation')
|
|
|
|
: t('copyToClipboard')
|
|
|
|
}
|
2023-02-09 17:21:51 +01:00
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip position="top" title={t('openInBlockExplorer')}>
|
|
|
|
<ButtonIcon
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2023-04-19 23:16:49 +02:00
|
|
|
iconName={IconName.Export}
|
2023-02-09 17:21:51 +01:00
|
|
|
color={Color.iconMuted}
|
|
|
|
onClick={() => {
|
|
|
|
const blockExplorerTokenLink = getAccountLink(
|
|
|
|
toAddress,
|
|
|
|
chainId,
|
|
|
|
{
|
|
|
|
blockExplorerUrl: rpcPrefs?.blockExplorerUrl ?? null,
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
);
|
|
|
|
global.platform.openTab({
|
|
|
|
url: blockExplorerTokenLink,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
ariaLabel={t('openInBlockExplorer')}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
2022-08-24 19:12:52 +02:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<Box
|
2023-06-21 00:14:45 +02:00
|
|
|
display={Display.Flex}
|
2022-08-24 19:12:52 +02:00
|
|
|
paddingTop={6}
|
|
|
|
paddingRight={4}
|
|
|
|
paddingBottom={6}
|
|
|
|
paddingLeft={4}
|
|
|
|
>
|
2022-10-05 21:48:35 +02:00
|
|
|
<Button type="primary" onClick={() => onClose()}>
|
|
|
|
{t('recoveryPhraseReminderConfirm')}
|
2022-08-24 19:12:52 +02:00
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
</Popover>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContractDetailsModal.propTypes = {
|
2022-10-05 21:48:35 +02:00
|
|
|
/**
|
|
|
|
* Function that should close the modal
|
|
|
|
*/
|
2022-08-24 19:12:52 +02:00
|
|
|
onClose: PropTypes.func,
|
2022-10-05 21:48:35 +02:00
|
|
|
/**
|
|
|
|
* Name of the token that is waiting to be allowed
|
|
|
|
*/
|
2022-08-24 19:12:52 +02:00
|
|
|
tokenName: PropTypes.string,
|
2022-10-05 21:48:35 +02:00
|
|
|
/**
|
|
|
|
* Address of the token that is waiting to be allowed
|
|
|
|
*/
|
|
|
|
tokenAddress: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Contract address requesting spending cap
|
|
|
|
*/
|
|
|
|
toAddress: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Current network chainId
|
|
|
|
*/
|
|
|
|
chainId: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* RPC prefs of the current network
|
|
|
|
*/
|
|
|
|
rpcPrefs: PropTypes.object,
|
2022-11-14 20:28:27 +01:00
|
|
|
/**
|
2023-02-16 20:23:29 +01:00
|
|
|
* The token id of the NFT
|
2022-11-14 20:28:27 +01:00
|
|
|
*/
|
|
|
|
tokenId: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Token Standard
|
|
|
|
*/
|
|
|
|
assetStandard: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* The name of the collection
|
|
|
|
*/
|
|
|
|
assetName: PropTypes.string,
|
2022-11-21 18:19:49 +01:00
|
|
|
/**
|
|
|
|
* Whether contract requesting signature flow has started
|
|
|
|
*/
|
|
|
|
isContractRequestingSignature: PropTypes.bool,
|
2022-08-24 19:12:52 +02:00
|
|
|
};
|