1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-03 06:34:27 +01:00
metamask-extension/ui/components/app/nfts-tab/nfts-tab.js
Nidhi Kumari af56e34d5f
Updated action list in token, NFTs and activity view (#19702)
* updated ui for nft import button

* updated no nft image found in the center

* updated footer for all screens in tabs

* removed no nft state from nft tab

* updated snapshot

* lint fix

* fixed e2e tests

* fixed prep build error

* removed no nfts yet test

* updated tabs

* fixed prod error

* updated no nft screen

* changed button size to md
2023-06-27 12:05:31 +05:30

156 lines
4.6 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import NftsItems from '../nfts-items';
import {
JustifyContent,
FlexDirection,
AlignItems,
Size,
Display,
TextAlign,
TextVariant,
TextColor,
} from '../../../helpers/constants/design-system';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { getIsMainnet, getUseNftDetection } from '../../../selectors';
import { EXPERIMENTAL_ROUTE } from '../../../helpers/constants/routes';
import {
checkAndUpdateAllNftsOwnershipStatus,
detectNfts,
} from '../../../store/actions';
import { useNftsCollections } from '../../../hooks/useNftsCollections';
import { Box, ButtonLink, IconName, Text } from '../../component-library';
import NftsDetectionNotice from '../nfts-detection-notice';
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
export default function NftsTab({ onAddNFT }) {
const useNftDetection = useSelector(getUseNftDetection);
const isMainnet = useSelector(getIsMainnet);
const history = useHistory();
const t = useI18nContext();
const dispatch = useDispatch();
const { nftsLoading, collections, previouslyOwnedCollection } =
useNftsCollections();
const onEnableAutoDetect = () => {
history.push(EXPERIMENTAL_ROUTE);
};
const onRefresh = () => {
if (isMainnet) {
dispatch(detectNfts());
}
checkAndUpdateAllNftsOwnershipStatus();
};
if (nftsLoading) {
return <div className="nfts-tab__loading">{t('loadingNFTs')}</div>;
}
return (
<Box className="nfts-tab">
{Object.keys(collections).length > 0 ||
previouslyOwnedCollection.nfts.length > 0 ? (
<NftsItems
collections={collections}
previouslyOwnedCollection={previouslyOwnedCollection}
/>
) : (
<>
{isMainnet && !useNftDetection ? <NftsDetectionNotice /> : null}{' '}
<Box
padding={12}
display={Display.Flex}
flexDirection={FlexDirection.Column}
alignItems={AlignItems.center}
justifyContent={JustifyContent.center}
>
<Box justifyContent={JustifyContent.center}>
<img src="./images/no-nfts.svg" />
</Box>
<Box
marginTop={4}
marginBottom={12}
display={Display.Flex}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
flexDirection={FlexDirection.Column}
className="nfts-tab__link"
>
<Text
color={TextColor.textMuted}
variant={TextVariant.headingSm}
align={TextAlign.Center}
as="h4"
>
{t('noNFTs')}
</Text>
<ButtonLink
size={Size.MD}
data-testid="import-nft-button"
href={ZENDESK_URLS.NFT_TOKENS}
externalLink
>
{t('learnMoreUpperCase')}
</ButtonLink>
</Box>
</Box>
</>
)}
<Box
className="nfts-tab__buttons"
display={Display.Flex}
flexDirection={FlexDirection.Column}
alignItems={AlignItems.flexStart}
margin={4}
gap={2}
marginBottom={2}
>
<ButtonLink
size={Size.MD}
data-testid="import-nft-button"
startIconName={IconName.Add}
onClick={onAddNFT}
>
{t('importNFT')}
</ButtonLink>
{!isMainnet && Object.keys(collections).length < 1 ? null : (
<>
<Box
className="nfts-tab__link"
justifyContent={JustifyContent.flexEnd}
>
{isMainnet && !useNftDetection ? (
<ButtonLink
size={Size.MD}
startIconName={IconName.Setting}
data-testid="refresh-list-button"
onClick={onEnableAutoDetect}
>
{t('enableAutoDetect')}
</ButtonLink>
) : (
<ButtonLink
size={Size.MD}
startIconName={IconName.Refresh}
data-testid="refresh-list-button"
onClick={onRefresh}
>
{t('refreshList')}
</ButtonLink>
)}
</Box>
</>
)}
</Box>
</Box>
);
}
NftsTab.propTypes = {
onAddNFT: PropTypes.func.isRequired,
};