import { FunctionComponent, RefObject } from 'react' import { useRouter } from 'next/router' import { initialMarket } from './SettingsModal' import { FavoriteMarketButton } from './TradeNavMenu' import useMangoStore from '../stores/useMangoStore' import { getWeights, getMarketIndexBySymbol, } from '@blockworks-foundation/mango-client' const getMarketLeverage = (mangoGroup, mangoGroupConfig, market) => { if (!mangoGroup) return 1 const marketIndex = getMarketIndexBySymbol( mangoGroupConfig, market.baseSymbol ) const ws = getWeights(mangoGroup, marketIndex, 'Init') const w = market.name.includes('PERP') ? ws.perpAssetWeight : ws.spotAssetWeight return Math.round((100 * -1) / (w.toNumber() - 1)) / 100 } interface MarketNavItemProps { market: any onClick?: () => void buttonRef?: RefObject } const MarketNavItem: FunctionComponent = ({ market, onClick, buttonRef, }) => { const { asPath } = useRouter() const router = useRouter() const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) const mangoGroupConfig = useMangoStore((s) => s.selectedMangoGroup.config) const marketInfo = useMangoStore((s) => s.marketInfo) const mktInfo = marketInfo.find((info) => info.name === market.name) const selectMarket = (market) => { buttonRef?.current?.click() router.push(`/?name=${market.name}`, undefined, { shallow: true }) if (onClick) { onClick() } } return (
) } export default MarketNavItem