import React from 'react'; 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'; import NewCollectiblesNotice from '../new-collectibles-notice'; import CollectiblesItems from '../collectibles-items'; import { COLORS, TYPOGRAPHY, TEXT_ALIGN, JUSTIFY_CONTENT, FLEX_DIRECTION, FONT_WEIGHT, } from '../../../helpers/constants/design-system'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { getCollectibles, getCollectibleContracts, } from '../../../ducks/metamask/metamask'; import { getUseCollectibleDetection } from '../../../selectors'; import { EXPERIMENTAL_ROUTE } from '../../../helpers/constants/routes'; import { detectCollectibles } from '../../../store/actions'; export default function CollectiblesTab({ onAddNFT }) { const collectibles = useSelector(getCollectibles); const collectibleContracts = useSelector(getCollectibleContracts); const useCollectibleDetection = useSelector(getUseCollectibleDetection); const history = useHistory(); const newNFTsDetected = false; const t = useI18nContext(); const collections = {}; const dispatch = useDispatch(); collectibles.forEach((collectible) => { if (collections[collectible.address]) { collections[collectible.address].collectibles.push(collectible); } else { const collectionContract = collectibleContracts.find( ({ address }) => address === collectible.address, ); collections[collectible.address] = { collectionName: collectionContract?.name || collectible.name, collectionImage: collectionContract?.logo || collectible.collectionImage, collectibles: [collectible], }; } }); return (
{collectibles.length > 0 ? ( dispatch(detectCollectibles())} onEnableAutoDetect={() => history.push(EXPERIMENTAL_ROUTE)} /> ) : ( {newNFTsDetected ? : null} {t('noNFTs')} {t('missingNFT')} )}
); } CollectiblesTab.propTypes = { onAddNFT: PropTypes.func.isRequired, };