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 } from '@blockworks-foundation/mango-client' interface MarketNavItemProps { market: any clearSearchString?: () => void buttonRef?: RefObject } const MarketNavItem: FunctionComponent = ({ market, clearSearchString, buttonRef, }) => { const { asPath } = useRouter() const router = useRouter() const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) 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 (clearSearchString) { clearSearchString() } } const getMarketLeverage = (market) => { if (!mangoGroup) return 1 const ws = getWeights(mangoGroup, market.marketIndex, 'Init') const w = market.name.includes('PERP') ? ws.perpAssetWeight : ws.spotAssetWeight return Math.round((100 * -1) / (w.toNumber() - 1)) / 100 } return (
) } export default MarketNavItem