2022-01-10 17:23:53 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2021-12-14 00:41:10 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { getTokenTrackerLink } from '@metamask/etherscan-link';
|
2022-01-10 17:23:53 +01:00
|
|
|
import { isEqual } from 'lodash';
|
2021-12-14 00:41:10 +01:00
|
|
|
import Box from '../../ui/box';
|
|
|
|
import Card from '../../ui/card';
|
|
|
|
import Typography from '../../ui/typography/typography';
|
|
|
|
import {
|
|
|
|
COLORS,
|
|
|
|
TYPOGRAPHY,
|
|
|
|
FONT_WEIGHT,
|
|
|
|
JUSTIFY_CONTENT,
|
|
|
|
FLEX_DIRECTION,
|
|
|
|
OVERFLOW_WRAP,
|
|
|
|
DISPLAY,
|
2022-01-10 17:23:53 +01:00
|
|
|
BLOCK_SIZES,
|
2021-12-14 00:41:10 +01:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
|
|
import {
|
|
|
|
getAssetImageURL,
|
|
|
|
isEqualCaseInsensitive,
|
|
|
|
shortenAddress,
|
|
|
|
} from '../../../helpers/utils/util';
|
|
|
|
import {
|
|
|
|
getCurrentChainId,
|
|
|
|
getIpfsGateway,
|
|
|
|
getRpcPrefsForCurrentProvider,
|
|
|
|
getSelectedIdentity,
|
|
|
|
} from '../../../selectors';
|
|
|
|
import AssetNavigation from '../../../pages/asset/components/asset-navigation';
|
|
|
|
import { getCollectibleContracts } from '../../../ducks/metamask/metamask';
|
2022-01-10 17:23:53 +01:00
|
|
|
import { DEFAULT_ROUTE, SEND_ROUTE } from '../../../helpers/constants/routes';
|
|
|
|
import {
|
|
|
|
checkAndUpdateSingleCollectibleOwnershipStatus,
|
|
|
|
removeAndIgnoreCollectible,
|
|
|
|
} from '../../../store/actions';
|
2021-12-14 00:41:10 +01:00
|
|
|
import {
|
|
|
|
GOERLI_CHAIN_ID,
|
|
|
|
KOVAN_CHAIN_ID,
|
|
|
|
MAINNET_CHAIN_ID,
|
|
|
|
POLYGON_CHAIN_ID,
|
|
|
|
RINKEBY_CHAIN_ID,
|
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
} 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';
|
2022-01-10 17:23:53 +01:00
|
|
|
import Button from '../../ui/button';
|
|
|
|
import { ASSET_TYPES, updateSendAsset } from '../../../ducks/send';
|
|
|
|
import InfoTooltip from '../../ui/info-tooltip';
|
|
|
|
import { ERC721 } from '../../../helpers/constants/common';
|
|
|
|
import { usePrevious } from '../../../hooks/usePrevious';
|
2021-12-14 00:41:10 +01:00
|
|
|
|
|
|
|
export default function CollectibleDetails({ collectible }) {
|
2022-01-10 17:23:53 +01:00
|
|
|
const {
|
|
|
|
image,
|
|
|
|
name,
|
|
|
|
description,
|
|
|
|
address,
|
|
|
|
tokenId,
|
|
|
|
standard,
|
|
|
|
isCurrentlyOwned,
|
|
|
|
} = collectible;
|
2021-12-14 00:41:10 +01:00
|
|
|
const t = useI18nContext();
|
|
|
|
const history = useHistory();
|
2022-01-10 17:23:53 +01:00
|
|
|
const dispatch = useDispatch();
|
2021-12-14 00:41:10 +01:00
|
|
|
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
|
|
|
|
const ipfsGateway = useSelector(getIpfsGateway);
|
|
|
|
const collectibleContracts = useSelector(getCollectibleContracts);
|
|
|
|
const currentNetwork = useSelector(getCurrentChainId);
|
|
|
|
|
|
|
|
const collectibleContractName = collectibleContracts.find(
|
|
|
|
({ address: contractAddress }) =>
|
|
|
|
isEqualCaseInsensitive(contractAddress, address),
|
|
|
|
)?.name;
|
|
|
|
const selectedAccountName = useSelector(
|
|
|
|
(state) => getSelectedIdentity(state).name,
|
|
|
|
);
|
|
|
|
const collectibleImageURL = getAssetImageURL(image, ipfsGateway);
|
|
|
|
|
|
|
|
const onRemove = () => {
|
|
|
|
dispatch(removeAndIgnoreCollectible(address, tokenId));
|
|
|
|
history.push(DEFAULT_ROUTE);
|
|
|
|
};
|
|
|
|
|
2022-01-10 17:23:53 +01:00
|
|
|
const prevCollectible = usePrevious(collectible);
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isEqual(prevCollectible, collectible)) {
|
|
|
|
checkAndUpdateSingleCollectibleOwnershipStatus(collectible);
|
|
|
|
}
|
|
|
|
}, [collectible, prevCollectible]);
|
|
|
|
|
2021-12-14 00:41:10 +01:00
|
|
|
const getOpenSeaLink = () => {
|
|
|
|
switch (currentNetwork) {
|
|
|
|
case MAINNET_CHAIN_ID:
|
|
|
|
return `https://opensea.io/assets/${address}/${tokenId}`;
|
|
|
|
case POLYGON_CHAIN_ID:
|
|
|
|
return `https://opensea.io/assets/matic/${address}/${tokenId}`;
|
|
|
|
case GOERLI_CHAIN_ID:
|
|
|
|
case KOVAN_CHAIN_ID:
|
|
|
|
case ROPSTEN_CHAIN_ID:
|
|
|
|
case RINKEBY_CHAIN_ID:
|
|
|
|
return `https://testnets.opensea.io/assets/${address}/${tokenId}`;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const openSeaLink = getOpenSeaLink();
|
2022-01-10 17:23:53 +01:00
|
|
|
const sendDisabled = standard !== ERC721;
|
|
|
|
const inPopUp = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP;
|
|
|
|
|
|
|
|
const onSend = async () => {
|
|
|
|
await dispatch(
|
|
|
|
updateSendAsset({
|
|
|
|
type: ASSET_TYPES.COLLECTIBLE,
|
|
|
|
details: collectible,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
history.push(SEND_ROUTE);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderSendButton = () => {
|
|
|
|
if (isCurrentlyOwned === false) {
|
|
|
|
return <div style={{ height: '30px' }} />;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
width={inPopUp ? BLOCK_SIZES.FULL : BLOCK_SIZES.HALF}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
onClick={onSend}
|
|
|
|
disabled={sendDisabled}
|
|
|
|
className="collectible-details__send-button"
|
|
|
|
>
|
|
|
|
{t('send')}
|
|
|
|
</Button>
|
|
|
|
{sendDisabled ? (
|
|
|
|
<InfoTooltip position="top" contentText={t('sendingDisabled')} />
|
|
|
|
) : null}
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-12-14 00:41:10 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<AssetNavigation
|
|
|
|
accountName={selectedAccountName}
|
|
|
|
assetName={collectibleContractName}
|
|
|
|
onBack={() => history.push(DEFAULT_ROUTE)}
|
|
|
|
optionsButton={
|
|
|
|
<CollectibleOptions
|
|
|
|
onViewOnOpensea={
|
|
|
|
openSeaLink
|
|
|
|
? () => global.platform.openTab({ url: openSeaLink })
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
onRemove={onRemove}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Box className="collectible-details">
|
|
|
|
<div className="collectible-details__top-section">
|
|
|
|
<Card
|
|
|
|
padding={0}
|
|
|
|
justifyContent={JUSTIFY_CONTENT.CENTER}
|
|
|
|
className="collectible-details__card"
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
className="collectible-details__image"
|
|
|
|
src={collectibleImageURL}
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
<Box
|
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
2022-01-10 17:23:53 +01:00
|
|
|
className="collectible-details__info"
|
|
|
|
justifyContent={JUSTIFY_CONTENT.SPACE_BETWEEN}
|
2021-12-14 00:41:10 +01:00
|
|
|
>
|
2022-01-10 17:23:53 +01:00
|
|
|
<div>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.BLACK}
|
|
|
|
variant={TYPOGRAPHY.H4}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
boxProps={{ margin: 0, marginBottom: 4 }}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.UI3}
|
|
|
|
variant={TYPOGRAPHY.H5}
|
|
|
|
boxProps={{ margin: 0 }}
|
|
|
|
overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
|
|
|
|
>
|
|
|
|
#{tokenId}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.BLACK}
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
className="collectible-details__description"
|
|
|
|
boxProps={{ margin: 0, marginBottom: 2 }}
|
|
|
|
>
|
|
|
|
{t('description')}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.UI4}
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
boxProps={{ margin: 0, marginBottom: 4 }}
|
|
|
|
>
|
|
|
|
{description}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
{inPopUp ? null : renderSendButton()}
|
2021-12-14 00:41:10 +01:00
|
|
|
</Box>
|
|
|
|
</div>
|
2022-01-10 17:23:53 +01:00
|
|
|
<Box marginBottom={2}>
|
2021-12-14 00:41:10 +01:00
|
|
|
<Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.BLACK}
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
boxProps={{
|
|
|
|
margin: 0,
|
|
|
|
marginBottom: 4,
|
|
|
|
marginRight: 2,
|
|
|
|
}}
|
|
|
|
className="collectible-details__link-title"
|
|
|
|
>
|
|
|
|
{t('source')}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.PRIMARY1}
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
boxProps={{
|
|
|
|
margin: 0,
|
|
|
|
marginBottom: 4,
|
|
|
|
}}
|
|
|
|
overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
href={collectibleImageURL}
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
className="collectible-details__image-link"
|
|
|
|
>
|
|
|
|
{image}
|
|
|
|
</a>
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.BLACK}
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
boxProps={{
|
|
|
|
margin: 0,
|
|
|
|
marginBottom: 4,
|
|
|
|
marginRight: 2,
|
|
|
|
}}
|
|
|
|
className="collectible-details__link-title"
|
|
|
|
>
|
|
|
|
{t('contractAddress')}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.UI3}
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
|
|
|
|
boxProps={{
|
|
|
|
margin: 0,
|
|
|
|
marginBottom: 4,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
className="collectible-details__contract-link"
|
|
|
|
href={getTokenTrackerLink(
|
|
|
|
address,
|
|
|
|
currentNetwork,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
rpcPrefs,
|
|
|
|
)}
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{getEnvironmentType() === ENVIRONMENT_TYPE_POPUP
|
|
|
|
? shortenAddress(address)
|
|
|
|
: address}
|
|
|
|
</a>
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
2022-01-10 17:23:53 +01:00
|
|
|
{inPopUp ? renderSendButton() : null}
|
2021-12-14 00:41:10 +01:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectibleDetails.propTypes = {
|
|
|
|
collectible: PropTypes.shape({
|
|
|
|
address: PropTypes.string.isRequired,
|
|
|
|
tokenId: PropTypes.string.isRequired,
|
2022-01-10 17:23:53 +01:00
|
|
|
isCurrentlyOwned: PropTypes.bool,
|
2021-12-14 00:41:10 +01:00
|
|
|
name: PropTypes.string,
|
|
|
|
description: PropTypes.string,
|
|
|
|
image: PropTypes.string,
|
|
|
|
standard: PropTypes.string,
|
|
|
|
imageThumbnail: PropTypes.string,
|
|
|
|
imagePreview: PropTypes.string,
|
|
|
|
creator: PropTypes.shape({
|
|
|
|
address: PropTypes.string,
|
|
|
|
config: PropTypes.string,
|
|
|
|
profile_img_url: PropTypes.string,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|