mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
4c37448c97
* added ipfs toggle * added placeholder valur * fixed snapshot * updated tests * updated spec file * hide input if toggle is disabled * updated e2e tests for nft image * fixed view-ercc-1155 spec * updated e2e tests for nfts * added ipfs toggle modal * updated UI for ipfs * updated tests * updated classname * added placeholder image * lint fix * removed prop ipfsEnabled and used with selector * fixed ui for ipfs toggle * updated test * updated test to handle cases * nit fix * ensure default image height match nft image
116 lines
3.2 KiB
JavaScript
116 lines
3.2 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import classnames from 'classnames';
|
|
import { useSelector } from 'react-redux';
|
|
import NftDefaultImage from '../../app/nft-default-image/nft-default-image';
|
|
import {
|
|
AvatarNetwork,
|
|
AvatarNetworkSize,
|
|
BadgeWrapper,
|
|
BadgeWrapperAnchorElementShape,
|
|
Box,
|
|
} from '../../component-library';
|
|
import {
|
|
BackgroundColor,
|
|
Display,
|
|
JustifyContent,
|
|
} from '../../../helpers/constants/design-system';
|
|
import {
|
|
getIpfsGateway,
|
|
getTestNetworkBackgroundColor,
|
|
} from '../../../selectors';
|
|
|
|
export const NftItem = ({
|
|
alt,
|
|
name,
|
|
src,
|
|
networkName,
|
|
networkSrc,
|
|
tokenId,
|
|
onClick,
|
|
clickable,
|
|
nftImageURL,
|
|
}) => {
|
|
const testNetworkBackgroundColor = useSelector(getTestNetworkBackgroundColor);
|
|
const isIpfsEnabled = useSelector(getIpfsGateway);
|
|
const isIpfsURL = nftImageURL?.includes('ipfs:');
|
|
return (
|
|
<Box
|
|
className="nft-item__container"
|
|
data-testid="nft-item"
|
|
as="button"
|
|
onClick={onClick}
|
|
>
|
|
<BadgeWrapper
|
|
className={classnames('nft-item__badge-wrapper', {
|
|
'nft-item__badge-wrapper__clickable': clickable,
|
|
})}
|
|
anchorElementShape={BadgeWrapperAnchorElementShape.circular}
|
|
positionObj={{ top: -4, right: -4 }}
|
|
display={Display.Block}
|
|
badge={
|
|
<AvatarNetwork
|
|
className="nft-item__network-badge"
|
|
backgroundColor={testNetworkBackgroundColor}
|
|
data-testid="nft-network-badge"
|
|
size={AvatarNetworkSize.Sm}
|
|
name={networkName}
|
|
src={networkSrc}
|
|
borderWidth={2}
|
|
borderColor={BackgroundColor.backgroundDefault}
|
|
/* We are using BackgroundColor.backgroundDefault here because
|
|
* there is no equivalent BorderColor to get the "cutout" effect
|
|
*/
|
|
/>
|
|
}
|
|
>
|
|
{isIpfsEnabled ? (
|
|
<Box
|
|
className="nft-item__item nft-item__item-image"
|
|
data-testid="nft-image"
|
|
as="img"
|
|
src={src}
|
|
alt={alt}
|
|
display={Display.Block}
|
|
justifyContent={JustifyContent.center}
|
|
/>
|
|
) : (
|
|
<>
|
|
{isIpfsURL ? (
|
|
<NftDefaultImage
|
|
className="nft-item__default-image"
|
|
data-testid="nft-default-image"
|
|
name={name}
|
|
tokenId={tokenId}
|
|
clickable={clickable}
|
|
/>
|
|
) : (
|
|
<Box
|
|
className="nft-item__item nft-item__item-image"
|
|
data-testid="nft-image"
|
|
as="img"
|
|
src={src}
|
|
alt={alt}
|
|
display={Display.Block}
|
|
justifyContent={JustifyContent.center}
|
|
/>
|
|
)}
|
|
</>
|
|
)}
|
|
</BadgeWrapper>
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
NftItem.propTypes = {
|
|
src: PropTypes.string,
|
|
alt: PropTypes.string.isRequired,
|
|
name: PropTypes.string.isRequired,
|
|
networkName: PropTypes.string.isRequired,
|
|
networkSrc: PropTypes.string.isRequired,
|
|
tokenId: PropTypes.string.isRequired,
|
|
onClick: PropTypes.func,
|
|
clickable: PropTypes.bool,
|
|
nftImageURL: PropTypes.string,
|
|
};
|