import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { 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 { COLORS, TYPOGRAPHY, TEXT_ALIGN, JUSTIFY_CONTENT, FLEX_DIRECTION, ALIGN_ITEMS, DISPLAY, BLOCK_SIZES, SIZES, FLEX_WRAP, } from '../../../helpers/constants/design-system'; import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { getEnvironmentType } from '../../../../app/scripts/lib/util'; import { getIpfsGateway } from '../../../selectors'; import { ASSET_ROUTE } from '../../../helpers/constants/routes'; import { getAssetImageURL } from '../../../helpers/utils/util'; const width = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP ? BLOCK_SIZES.ONE_THIRD : BLOCK_SIZES.ONE_SIXTH; export default function CollectiblesItems({ onAddNFT, onRefreshList, collections, useCollectibleDetection, onEnableAutoDetect, }) { const t = useI18nContext(); const defaultDropdownState = {}; const ipfsGateway = useSelector(getIpfsGateway); Object.keys(collections).forEach((key) => { defaultDropdownState[key] = true; }); const history = useHistory(); const [dropdownState, setDropdownState] = useState(defaultDropdownState); return (
<> {Object.keys(collections).map((key, index) => { const { collectibles, collectionName, collectionImage, } = collections[key]; const isExpanded = dropdownState[key]; return (
{collectionImage ? ( ) : (
{collectionName[0]}
)} {`${collectionName} (${collectibles.length})`}
{ setDropdownState((_dropdownState) => ({ ..._dropdownState, [key]: !isExpanded, })); }} />
{isExpanded ? ( {collectibles.map((collectible, i) => { const { image, address, tokenId } = collectible; const collectibleImage = getAssetImageURL( image, ipfsGateway, ); return ( history.push( `${ASSET_ROUTE}/${address}/${tokenId}`, ) } className="collectibles-items__image" src={collectibleImage} /> ); })} ) : null}
); })} {t('missingNFT')} {' '} {useCollectibleDetection ? ( ) : ( )} {t('or')}
); } CollectiblesItems.propTypes = { onAddNFT: PropTypes.func.isRequired, onRefreshList: PropTypes.func.isRequired, collections: PropTypes.array, useCollectibleDetection: PropTypes.bool.isRequired, onEnableAutoDetect: PropTypes.func.isRequired, };