import { useEffect, useState } from 'react' import styled from '@emotion/styled' import useMangoGroupConfig from '../hooks/useMangoGroupConfig' import MarketMenuItem from './MarketMenuItem' import { LinkButton } from './Button' import MarketsModal from './MarketsModal' import useLocalStorageState from '../hooks/useLocalStorageState' const StyledMarketSelectWrapper = styled.div` -ms-overflow-style: none; scrollbar-width: none; ::-webkit-scrollbar { display: none; } ` const StyledArrow = styled.div` width: 0; height: 0; border-top: 20px solid transparent; border-bottom: 20px solid transparent; padding-right: 0.5rem; ` const MarketSelect = () => { const [showMarketsModal, setShowMarketsModal] = useState(false) const [hiddenMarkets] = useLocalStorageState('hiddenMarkets', []) const [sortedMarkets, setSortedMarkets] = useState([]) const groupConfig = useMangoGroupConfig() 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 ( <> setShowMarketsModal(true)} > MARKETS {sortedMarkets .filter((m) => !hiddenMarkets.includes(m.baseAsset)) .map((s) => ( ))} {showMarketsModal ? ( setShowMarketsModal(false)} markets={sortedMarkets} /> ) : null} > ) } export default MarketSelect