import React, { useEffect } from 'react'; import PropTypes from 'prop-types'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory } from 'react-router-dom'; import { isEqual } from 'lodash'; import Box from '../../ui/box'; import Card from '../../ui/card'; import Typography from '../../ui/typography/typography'; import { TextColor, IconColor, TypographyVariant, FONT_WEIGHT, JustifyContent, FLEX_DIRECTION, OVERFLOW_WRAP, DISPLAY, BLOCK_SIZES, } from '../../../helpers/constants/design-system'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { formatDate, getAssetImageURL, shortenAddress, } from '../../../helpers/utils/util'; import { getCollectibleImageAlt } from '../../../helpers/utils/collectibles'; import { getCurrentChainId, getIpfsGateway, getSelectedIdentity, } from '../../../selectors'; import AssetNavigation from '../../../pages/asset/components/asset-navigation'; import { getCollectibleContracts } from '../../../ducks/metamask/metamask'; import { DEFAULT_ROUTE, SEND_ROUTE } from '../../../helpers/constants/routes'; import { checkAndUpdateSingleNftOwnershipStatus, removeAndIgnoreNft, setRemoveCollectibleMessage, } from '../../../store/actions'; import { CHAIN_IDS } from '../../../../shared/constants/network'; import { getEnvironmentType } from '../../../../app/scripts/lib/util'; import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app'; import CollectibleOptions from '../collectible-options/collectible-options'; import Button from '../../ui/button'; import { startNewDraftTransaction } from '../../../ducks/send'; import InfoTooltip from '../../ui/info-tooltip'; import { usePrevious } from '../../../hooks/usePrevious'; import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard'; import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils'; import { AssetType, TokenStandard, } from '../../../../shared/constants/transaction'; import CollectibleDefaultImage from '../collectible-default-image'; import { ButtonIcon, ICON_NAMES } from '../../component-library'; import Tooltip from '../../ui/tooltip'; export default function CollectibleDetails({ collectible }) { const { image, imageOriginal, name, description, address, tokenId, standard, isCurrentlyOwned, lastSale, imageThumbnail, } = collectible; const t = useI18nContext(); const history = useHistory(); const dispatch = useDispatch(); const ipfsGateway = useSelector(getIpfsGateway); const collectibleContracts = useSelector(getCollectibleContracts); const currentNetwork = useSelector(getCurrentChainId); const [addressCopied, handleAddressCopy] = useCopyToClipboard(); const collectibleContractName = collectibleContracts.find( ({ address: contractAddress }) => isEqualCaseInsensitive(contractAddress, address), )?.name; const selectedAccountName = useSelector( (state) => getSelectedIdentity(state).name, ); const collectibleImageAlt = getCollectibleImageAlt(collectible); const collectibleImageURL = getAssetImageURL( imageOriginal ?? image, ipfsGateway, ); const isDataURI = collectibleImageURL.startsWith('data:'); const formattedTimestamp = formatDate( new Date(lastSale?.event_timestamp).getTime(), 'M/d/y', ); const onRemove = () => { dispatch(removeAndIgnoreNft(address, tokenId)); dispatch(setRemoveCollectibleMessage('success')); history.push(DEFAULT_ROUTE); }; const prevCollectible = usePrevious(collectible); useEffect(() => { if (!isEqual(prevCollectible, collectible)) { checkAndUpdateSingleNftOwnershipStatus(collectible); } }, [collectible, prevCollectible]); const getOpenSeaLink = () => { switch (currentNetwork) { case CHAIN_IDS.MAINNET: return `https://opensea.io/assets/${address}/${tokenId}`; case CHAIN_IDS.POLYGON: return `https://opensea.io/assets/matic/${address}/${tokenId}`; case CHAIN_IDS.GOERLI: case CHAIN_IDS.SEPOLIA: return `https://testnets.opensea.io/assets/${address}/${tokenId}`; default: return null; } }; const openSeaLink = getOpenSeaLink(); const sendDisabled = standard !== TokenStandard.ERC721; const inPopUp = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP; const onSend = async () => { await dispatch( startNewDraftTransaction({ type: AssetType.NFT, details: collectible, }), ); history.push(SEND_ROUTE); }; const renderSendButton = () => { if (isCurrentlyOwned === false) { return
; } return (