import React from 'react' import Link from 'next/link' import { EyeIcon, EyeOffIcon } from '@heroicons/react/outline' import { ChevronRightIcon } from '@heroicons/react/solid' import Modal from './Modal' import useLocalStorageState from '../hooks/useLocalStorageState' import useMangoStore from '../stores/useMangoStore' import { formatUsdValue } from '../utils' import { LinkButton } from './Button' import { useTranslation } from 'next-i18next' const MarketsModal = ({ isOpen, markets, onClose, }: { isOpen: boolean markets: Array onClose?: (x?) => void }) => { const { t } = useTranslation('common') const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache) const [hiddenMarkets, setHiddenMarkets] = useLocalStorageState( 'hiddenMarkets', [] ) const handleHideShowMarket = (asset) => { if (hiddenMarkets.includes(asset)) { setHiddenMarkets(hiddenMarkets.filter((m) => m !== asset)) } else { setHiddenMarkets(hiddenMarkets.concat(asset)) } } return (
{t('markets')}
{hiddenMarkets.length === 0 ? ( setHiddenMarkets(markets.map((mkt) => mkt.baseAsset)) } > {t('hide-all')} ) : ( setHiddenMarkets([])} > {t('show-all')} )}
{markets.map((mkt) => (
{mkt.baseAsset}
{hiddenMarkets.includes(mkt.baseAsset) ? ( handleHideShowMarket(mkt.baseAsset)} /> ) : ( handleHideShowMarket(mkt.baseAsset)} /> )}
{/*
Markets
Price 24h Change 24h Vol
*/}
{mkt.markets.map((m) => (
{m.name}
{mangoGroup && mangoCache ? formatUsdValue( mangoGroup .getPrice(m.marketIndex, mangoCache) .toNumber() ) : null} {/* +2.44% $233m */}
))}
))}
) } export default React.memo(MarketsModal)