import { useEffect, useState } from 'react' import { MenuIcon, PlusCircleIcon } from '@heroicons/react/outline' import useMangoGroupConfig from '../hooks/useMangoGroupConfig' import MarketMenuItem from './MarketMenuItem' import { LinkButton } from './Button' import MarketsModal from './MarketsModal' import useLocalStorageState from '../hooks/useLocalStorageState' import { useViewport } from '../hooks/useViewport' import { breakpoints } from './TradePageGrid' import { useTranslation } from 'next-i18next' const MarketSelect = () => { const { t } = useTranslation('common') const [showMarketsModal, setShowMarketsModal] = useState(false) const [hiddenMarkets] = useLocalStorageState('hiddenMarkets', []) const [sortedMarkets, setSortedMarkets] = useState([]) const groupConfig = useMangoGroupConfig() const { width } = useViewport() const isMobile = width ? width < breakpoints.md : false useEffect(() => { const markets = [] const allMarkets = [...groupConfig.spotMarkets, ...groupConfig.perpMarkets] allMarkets.forEach((market) => { const base = market.name.slice(0, -5) const found = markets.find((b) => b.baseAsset === base) if (!found) { markets.push({ baseAsset: base, markets: [market] }) } else { found.markets.push(market) } }) setSortedMarkets(markets) }, [groupConfig]) return (
{isMobile ? ( setShowMarketsModal(true)} /> ) : ( setShowMarketsModal(true)} t={t} /> )}
{sortedMarkets .filter((m) => !hiddenMarkets.includes(m.baseAsset)) .map((s) => ( ))}
{showMarketsModal ? ( setShowMarketsModal(false)} markets={sortedMarkets} /> ) : null}
) } const ShowMarketsButton = ({ onClick, t }) => ( {t('markets').toUpperCase()} ) export default MarketSelect