1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

updated CollectibleDetail Storybook Coverage (#17351)

* updated CollectibleDetail Storybook Coverage

* updated tooltip for collectible details

* updated color of icon

* fixed lint error

* fix lint error
This commit is contained in:
Nidhi Kumari 2023-02-02 23:56:36 +05:30 committed by GitHub
parent 7ef3fa08ff
commit b123458a26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 151 additions and 46 deletions

View File

@ -1759,6 +1759,12 @@
"lastConnected": { "lastConnected": {
"message": "Last connected" "message": "Last connected"
}, },
"lastPriceSold": {
"message": "Last price sold"
},
"lastSold": {
"message": "Last sold"
},
"learnCancelSpeeedup": { "learnCancelSpeeedup": {
"message": "Learn how to $1", "message": "Learn how to $1",
"description": "$1 is link to cancel or speed up transactions" "description": "$1 is link to cancel or speed up transactions"

View File

@ -2,12 +2,10 @@ import React, { useEffect } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { getTokenTrackerLink } from '@metamask/etherscan-link';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
import Box from '../../ui/box'; import Box from '../../ui/box';
import Card from '../../ui/card'; import Card from '../../ui/card';
import Typography from '../../ui/typography/typography'; import Typography from '../../ui/typography/typography';
import { ButtonIcon, ICON_NAMES } from '../../component-library';
import { import {
COLORS, COLORS,
TYPOGRAPHY, TYPOGRAPHY,
@ -17,14 +15,18 @@ import {
OVERFLOW_WRAP, OVERFLOW_WRAP,
DISPLAY, DISPLAY,
BLOCK_SIZES, BLOCK_SIZES,
ICON_COLORS,
} from '../../../helpers/constants/design-system'; } from '../../../helpers/constants/design-system';
import { useI18nContext } from '../../../hooks/useI18nContext'; import { useI18nContext } from '../../../hooks/useI18nContext';
import { getAssetImageURL, shortenAddress } from '../../../helpers/utils/util'; import {
formatDate,
getAssetImageURL,
shortenAddress,
} from '../../../helpers/utils/util';
import { getCollectibleImageAlt } from '../../../helpers/utils/collectibles'; import { getCollectibleImageAlt } from '../../../helpers/utils/collectibles';
import { import {
getCurrentChainId, getCurrentChainId,
getIpfsGateway, getIpfsGateway,
getRpcPrefsForCurrentProvider,
getSelectedIdentity, getSelectedIdentity,
} from '../../../selectors'; } from '../../../selectors';
import AssetNavigation from '../../../pages/asset/components/asset-navigation'; import AssetNavigation from '../../../pages/asset/components/asset-navigation';
@ -50,6 +52,8 @@ import {
TokenStandard, TokenStandard,
} from '../../../../shared/constants/transaction'; } from '../../../../shared/constants/transaction';
import CollectibleDefaultImage from '../collectible-default-image'; import CollectibleDefaultImage from '../collectible-default-image';
import { ButtonIcon, ICON_NAMES } from '../../component-library';
import Tooltip from '../../ui/tooltip';
export default function CollectibleDetails({ collectible }) { export default function CollectibleDetails({ collectible }) {
const { const {
@ -61,15 +65,15 @@ export default function CollectibleDetails({ collectible }) {
tokenId, tokenId,
standard, standard,
isCurrentlyOwned, isCurrentlyOwned,
lastSale,
imageThumbnail,
} = collectible; } = collectible;
const t = useI18nContext(); const t = useI18nContext();
const history = useHistory(); const history = useHistory();
const dispatch = useDispatch(); const dispatch = useDispatch();
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
const ipfsGateway = useSelector(getIpfsGateway); const ipfsGateway = useSelector(getIpfsGateway);
const collectibleContracts = useSelector(getCollectibleContracts); const collectibleContracts = useSelector(getCollectibleContracts);
const currentNetwork = useSelector(getCurrentChainId); const currentNetwork = useSelector(getCurrentChainId);
const [sourceCopied, handleSourceCopy] = useCopyToClipboard();
const [addressCopied, handleAddressCopy] = useCopyToClipboard(); const [addressCopied, handleAddressCopy] = useCopyToClipboard();
const collectibleContractName = collectibleContracts.find( const collectibleContractName = collectibleContracts.find(
@ -79,12 +83,16 @@ export default function CollectibleDetails({ collectible }) {
const selectedAccountName = useSelector( const selectedAccountName = useSelector(
(state) => getSelectedIdentity(state).name, (state) => getSelectedIdentity(state).name,
); );
const collectibleImageAlt = getCollectibleImageAlt(collectible);
const collectibleImageURL = getAssetImageURL( const collectibleImageURL = getAssetImageURL(
imageOriginal ?? image, imageOriginal ?? image,
ipfsGateway, ipfsGateway,
); );
const collectibleImageAlt = getCollectibleImageAlt(collectible);
const isDataURI = collectibleImageURL.startsWith('data:'); const isDataURI = collectibleImageURL.startsWith('data:');
const formattedTimestamp = formatDate(
new Date(lastSale?.event_timestamp).getTime(),
'M/d/y',
);
const onRemove = () => { const onRemove = () => {
dispatch(removeAndIgnoreNft(address, tokenId)); dispatch(removeAndIgnoreNft(address, tokenId));
@ -234,6 +242,68 @@ export default function CollectibleDetails({ collectible }) {
</Box> </Box>
</div> </div>
<Box marginBottom={2}> <Box marginBottom={2}>
{lastSale ? (
<>
<Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}>
<Typography
color={COLORS.TEXT_DEFAULT}
variant={TYPOGRAPHY.H6}
fontWeight={FONT_WEIGHT.BOLD}
boxProps={{
margin: 0,
marginBottom: 4,
marginRight: 2,
}}
className="collectible-details__link-title"
>
{t('lastSold')}
</Typography>
<Box
display={DISPLAY.FLEX}
flexDirection={FLEX_DIRECTION.ROW}
className="collectible-details__contract-wrapper"
>
<Typography
color={COLORS.TEXT_ALTERNATIVE}
variant={TYPOGRAPHY.H6}
overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
boxProps={{ margin: 0, marginBottom: 4 }}
>
{formattedTimestamp}
</Typography>
</Box>
</Box>
<Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}>
<Typography
color={COLORS.TEXT_DEFAULT}
variant={TYPOGRAPHY.H6}
fontWeight={FONT_WEIGHT.BOLD}
boxProps={{
margin: 0,
marginBottom: 4,
marginRight: 2,
}}
className="collectible-details__link-title"
>
{t('lastPriceSold')}
</Typography>
<Box
display={DISPLAY.FLEX}
flexDirection={FLEX_DIRECTION.ROW}
className="collectible-details__contract-wrapper"
>
<Typography
color={COLORS.TEXT_ALTERNATIVE}
variant={TYPOGRAPHY.H6}
overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
boxProps={{ margin: 0, marginBottom: 4 }}
>
{lastSale.total_price}
</Typography>
</Box>
</Box>
</>
) : null}
<Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}> <Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}>
<Typography <Typography
color={COLORS.TEXT_DEFAULT} color={COLORS.TEXT_DEFAULT}
@ -270,16 +340,39 @@ export default function CollectibleDetails({ collectible }) {
</a> </a>
)} )}
</Typography> </Typography>
<ButtonIcon </Box>
ariaLabel="copy" <Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}>
className="collectible-details__contract-copy-button" <Typography
onClick={() => { color={COLORS.TEXT_DEFAULT}
handleSourceCopy(collectibleImageURL); variant={TYPOGRAPHY.H6}
fontWeight={FONT_WEIGHT.BOLD}
boxProps={{
margin: 0,
marginBottom: 4,
marginRight: 2,
}} }}
iconName={ className="collectible-details__link-title"
sourceCopied ? ICON_NAMES.COPY_SUCCESS : ICON_NAMES.COPY >
} {t('link')}
/> </Typography>
<Typography
variant={TYPOGRAPHY.H6}
boxProps={{
margin: 0,
marginBottom: 4,
}}
className="collectible-details__image-source"
color={isDataURI ? COLORS.TEXT_DEFAULT : COLORS.PRIMARY_DEFAULT}
>
<a
target="_blank"
rel="noopener noreferrer"
href={collectibleImageURL}
title={collectibleImageURL}
>
{imageThumbnail}
</a>
</Typography>
</Box> </Box>
<Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}> <Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.ROW}>
<Typography <Typography
@ -301,32 +394,23 @@ export default function CollectibleDetails({ collectible }) {
className="collectible-details__contract-wrapper" className="collectible-details__contract-wrapper"
> >
<Typography <Typography
color={COLORS.PRIMARY_DEFAULT} color={COLORS.TEXT_ALTERNATIVE}
variant={TYPOGRAPHY.H6} variant={TYPOGRAPHY.H6}
overflowWrap={OVERFLOW_WRAP.BREAK_WORD} overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
boxProps={{ boxProps={{ margin: 0, marginBottom: 4 }}
margin: 0,
marginBottom: 4,
}}
className="collectible-details__contract-link"
> >
<a {shortenAddress(address)}
target="_blank"
rel="noopener noreferrer"
href={getTokenTrackerLink(
address,
currentNetwork,
null,
null,
rpcPrefs,
)}
title={address}
>
{inPopUp ? shortenAddress(address) : address}
</a>
</Typography> </Typography>
<Tooltip
wrapperClassName="collectible-details__tooltip-wrapper"
position="bottom"
title={
addressCopied ? t('copiedExclamation') : t('copyToClipboard')
}
>
<ButtonIcon <ButtonIcon
ariaLabel="copy" ariaLabel="copy"
color={ICON_COLORS.ICON_ALTERNATIVE}
className="collectible-details__contract-copy-button" className="collectible-details__contract-copy-button"
onClick={() => { onClick={() => {
handleAddressCopy(address); handleAddressCopy(address);
@ -335,6 +419,7 @@ export default function CollectibleDetails({ collectible }) {
addressCopied ? ICON_NAMES.COPY_SUCCESS : ICON_NAMES.COPY addressCopied ? ICON_NAMES.COPY_SUCCESS : ICON_NAMES.COPY
} }
/> />
</Tooltip>
</Box> </Box>
</Box> </Box>
{inPopUp ? renderSendButton() : null} {inPopUp ? renderSendButton() : null}
@ -364,5 +449,9 @@ CollectibleDetails.propTypes = {
config: PropTypes.string, config: PropTypes.string,
profile_img_url: PropTypes.string, profile_img_url: PropTypes.string,
}), }),
lastSale: PropTypes.shape({
event_timestamp: PropTypes.string,
total_price: PropTypes.string,
}),
}), }),
}; };

View File

@ -6,8 +6,13 @@ const collectible = {
tokenId: '1124157', tokenId: '1124157',
address: '0x06012c8cf97bead5deae237070f9587f8e7a266d', address: '0x06012c8cf97bead5deae237070f9587f8e7a266d',
image: './catnip-spicywright.png', image: './catnip-spicywright.png',
imageThumbnail: 'https://www.cryptokitties.co/.../1124157',
description: description:
"Good day. My name is Catnip Spicywight, which got me teased a lot in high school. If I want to put low fat mayo all over my hamburgers, I shouldn't have to answer to anyone about it, am I right? One time I beat Arlene in an arm wrestle.", "Good day. My name is Catnip Spicywight, which got me teased a lot in high school. If I want to put low fat mayo all over my hamburgers, I shouldn't have to answer to anyone about it, am I right? One time I beat Arlene in an arm wrestle.",
lastSale: {
event_timestamp: '2023-01-18T21:51:23',
total_price: '4900000000000000',
},
}; };
export default { export default {

View File

@ -10,10 +10,16 @@ $spacer-break-small: 16px;
padding: 0 $spacer-break-large; padding: 0 $spacer-break-large;
} }
&__tooltip-wrapper {
width: 100%;
}
&__top-section { &__top-section {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-bottom: $spacer-break-small; margin-bottom: $spacer-break-small;
box-shadow: var(--shadow-size-xs) var(--color-shadow-default);
padding: $spacer-break-large;
@include screen-sm-min { @include screen-sm-min {
margin-bottom: $spacer-break-large; margin-bottom: $spacer-break-large;
@ -79,7 +85,6 @@ $spacer-break-small: 16px;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
width: 332px;
} }
&__image-source { &__image-source {