2022-01-31 19:56:49 +01:00
|
|
|
import React 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 Box from '../../ui/box';
|
|
|
|
import Button from '../../ui/button';
|
|
|
|
import Typography from '../../ui/typography/typography';
|
2023-02-08 15:34:56 +01:00
|
|
|
import CollectiblesDetectionNotice from '../nfts-detection-notice';
|
|
|
|
import CollectiblesItems from '../nfts-items';
|
2021-12-14 00:41:10 +01:00
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
TypographyVariant,
|
2021-12-14 00:41:10 +01:00
|
|
|
TEXT_ALIGN,
|
2023-02-02 21:15:26 +01:00
|
|
|
JustifyContent,
|
2021-12-14 00:41:10 +01:00
|
|
|
FLEX_DIRECTION,
|
|
|
|
FONT_WEIGHT,
|
2023-02-02 21:15:26 +01:00
|
|
|
AlignItems,
|
|
|
|
TextColor,
|
2021-12-14 00:41:10 +01:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2022-11-15 19:49:42 +01:00
|
|
|
import { getIsMainnet, getUseNftDetection } from '../../../selectors';
|
2021-12-14 00:41:10 +01:00
|
|
|
import { EXPERIMENTAL_ROUTE } from '../../../helpers/constants/routes';
|
2022-01-03 21:39:41 +01:00
|
|
|
import {
|
2022-11-15 19:49:42 +01:00
|
|
|
checkAndUpdateAllNftsOwnershipStatus,
|
|
|
|
detectNfts,
|
2022-01-03 21:39:41 +01:00
|
|
|
} from '../../../store/actions';
|
2023-02-08 15:34:56 +01:00
|
|
|
import { useCollectiblesCollections } from '../../../hooks/useNftsCollections';
|
2022-08-23 16:19:31 +02:00
|
|
|
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
|
2021-12-14 00:41:10 +01:00
|
|
|
|
|
|
|
export default function CollectiblesTab({ onAddNFT }) {
|
2022-11-15 19:49:42 +01:00
|
|
|
const useNftDetection = useSelector(getUseNftDetection);
|
2021-12-14 00:41:10 +01:00
|
|
|
const isMainnet = useSelector(getIsMainnet);
|
|
|
|
const history = useHistory();
|
|
|
|
const t = useI18nContext();
|
|
|
|
const dispatch = useDispatch();
|
2022-01-10 17:23:53 +01:00
|
|
|
|
2022-07-31 20:26:40 +02:00
|
|
|
const { collectiblesLoading, collections, previouslyOwnedCollection } =
|
|
|
|
useCollectiblesCollections();
|
2021-12-14 00:41:10 +01:00
|
|
|
|
|
|
|
const onEnableAutoDetect = () => {
|
|
|
|
history.push(EXPERIMENTAL_ROUTE);
|
|
|
|
};
|
|
|
|
|
2022-01-03 21:39:41 +01:00
|
|
|
const onRefresh = () => {
|
|
|
|
if (isMainnet) {
|
2022-11-15 19:49:42 +01:00
|
|
|
dispatch(detectNfts());
|
2022-01-03 21:39:41 +01:00
|
|
|
}
|
2022-11-15 19:49:42 +01:00
|
|
|
checkAndUpdateAllNftsOwnershipStatus();
|
2022-01-03 21:39:41 +01:00
|
|
|
};
|
|
|
|
|
2022-01-31 19:56:49 +01:00
|
|
|
if (collectiblesLoading) {
|
|
|
|
return <div className="collectibles-tab__loading">{t('loadingNFTs')}</div>;
|
|
|
|
}
|
|
|
|
|
2021-12-14 00:41:10 +01:00
|
|
|
return (
|
2022-03-31 16:02:47 +02:00
|
|
|
<Box className="collectibles-tab">
|
2022-01-10 17:23:53 +01:00
|
|
|
{Object.keys(collections).length > 0 ||
|
|
|
|
previouslyOwnedCollection.collectibles.length > 0 ? (
|
2022-01-03 21:39:41 +01:00
|
|
|
<CollectiblesItems
|
|
|
|
collections={collections}
|
|
|
|
previouslyOwnedCollection={previouslyOwnedCollection}
|
|
|
|
/>
|
2021-12-14 00:41:10 +01:00
|
|
|
) : (
|
2022-03-31 16:02:47 +02:00
|
|
|
<>
|
2023-01-25 20:28:15 +01:00
|
|
|
{isMainnet && !useNftDetection ? (
|
2021-12-14 00:41:10 +01:00
|
|
|
<CollectiblesDetectionNotice />
|
|
|
|
) : null}
|
2022-03-31 16:02:47 +02:00
|
|
|
<Box padding={12}>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Box justifyContent={JustifyContent.center}>
|
2022-03-31 16:02:47 +02:00
|
|
|
<img src="./images/no-nfts.svg" />
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
marginTop={4}
|
|
|
|
marginBottom={12}
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.center}
|
2022-03-31 16:02:47 +02:00
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
className="collectibles-tab__link"
|
2021-12-14 00:41:10 +01:00
|
|
|
>
|
2022-03-31 16:02:47 +02:00
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textMuted}
|
|
|
|
variant={TypographyVariant.H4}
|
2022-03-31 16:02:47 +02:00
|
|
|
align={TEXT_ALIGN.CENTER}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{t('noNFTs')}
|
|
|
|
</Typography>
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2022-08-23 16:19:31 +02:00
|
|
|
href={ZENDESK_URLS.NFT_TOKENS}
|
2022-03-31 16:02:47 +02:00
|
|
|
>
|
|
|
|
{t('learnMoreUpperCase')}
|
|
|
|
</Button>
|
|
|
|
</Box>
|
2021-12-14 00:41:10 +01:00
|
|
|
</Box>
|
2022-03-31 16:02:47 +02:00
|
|
|
</>
|
2021-12-14 00:41:10 +01:00
|
|
|
)}
|
|
|
|
<Box
|
|
|
|
marginBottom={4}
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.center}
|
2021-12-14 00:41:10 +01:00
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
>
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textMuted}
|
|
|
|
variant={TypographyVariant.H5}
|
2021-12-14 00:41:10 +01:00
|
|
|
align={TEXT_ALIGN.CENTER}
|
|
|
|
>
|
|
|
|
{t('missingNFT')}
|
|
|
|
</Typography>
|
|
|
|
<Box
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.center}
|
2021-12-14 00:41:10 +01:00
|
|
|
>
|
2022-01-20 18:49:49 +01:00
|
|
|
{!isMainnet && Object.keys(collections).length < 1 ? null : (
|
|
|
|
<>
|
|
|
|
<Box
|
|
|
|
className="collectibles-tab__link"
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.flexEnd}
|
2022-01-20 18:49:49 +01:00
|
|
|
>
|
2022-11-15 19:49:42 +01:00
|
|
|
{isMainnet && !useNftDetection ? (
|
2022-01-20 18:49:49 +01:00
|
|
|
<Button type="link" onClick={onEnableAutoDetect}>
|
|
|
|
{t('enableAutoDetect')}
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<Button type="link" onClick={onRefresh}>
|
|
|
|
{t('refreshList')}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textMuted}
|
|
|
|
variant={TypographyVariant.H6}
|
2022-01-20 18:49:49 +01:00
|
|
|
align={TEXT_ALIGN.CENTER}
|
|
|
|
>
|
|
|
|
{t('or')}
|
|
|
|
</Typography>
|
|
|
|
</>
|
|
|
|
)}
|
2021-12-14 00:41:10 +01:00
|
|
|
<Box
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.flexStart}
|
2021-12-14 00:41:10 +01:00
|
|
|
className="collectibles-tab__link"
|
|
|
|
>
|
|
|
|
<Button type="link" onClick={onAddNFT}>
|
|
|
|
{t('importNFTs')}
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
2022-03-31 16:02:47 +02:00
|
|
|
</Box>
|
2021-12-14 00:41:10 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectiblesTab.propTypes = {
|
|
|
|
onAddNFT: PropTypes.func.isRequired,
|
|
|
|
};
|