import { ElementTitle } from './styles' import useMangoStore from '../stores/useMangoStore' import { i80f48ToPercent, floorToDecimal } from '../utils/index' import Tooltip from './Tooltip' import { getMarketIndexBySymbol, nativeI80F48ToUi, } from '@blockworks-foundation/mango-client' import { useViewport } from '../hooks/useViewport' import { breakpoints } from './TradePageGrid' import { useTranslation } from 'next-i18next' export default function MarketBalances() { const { t } = useTranslation('common') const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) const mangoGroupConfig = useMangoStore((s) => s.selectedMangoGroup.config) const mangoGroupCache = useMangoStore((s) => s.selectedMangoGroup.cache) const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current) const selectedMarket = useMangoStore((s) => s.selectedMarket.current) const marketConfig = useMangoStore((s) => s.selectedMarket.config) const setMangoStore = useMangoStore((s) => s.set) const price = useMangoStore((s) => s.tradeForm.price) const connected = useMangoStore((s) => s.wallet.connected) const isLoading = useMangoStore((s) => s.selectedMangoAccount.initialLoad) const baseSymbol = marketConfig.baseSymbol const { width } = useViewport() const isMobile = width ? width < breakpoints.sm : false const handleSizeClick = (size, symbol) => { const step = selectedMarket.minOrderSize const marketIndex = getMarketIndexBySymbol( mangoGroupConfig, marketConfig.baseSymbol ) const priceOrDefault = price ? price : mangoGroup.getPrice(marketIndex, mangoGroupCache).toNumber() if (symbol === 'USDC') { const baseSize = Math.floor(size / priceOrDefault / step) * step setMangoStore((state) => { state.tradeForm.baseSize = baseSize state.tradeForm.quoteSize = (baseSize * priceOrDefault).toFixed(2) state.tradeForm.side = 'buy' }) } else { const roundedSize = Math.round(size / step) * step const quoteSize = roundedSize * priceOrDefault setMangoStore((state) => { state.tradeForm.baseSize = roundedSize state.tradeForm.quoteSize = quoteSize.toFixed(2) state.tradeForm.side = 'sell' }) } } if (!mangoGroup || !selectedMarket) return null return (