import { PerpMarket } from '@blockworks-foundation/mango-v4' import { useTranslation } from 'next-i18next' import { useTheme } from 'next-themes' import { useViewport } from '../../hooks/useViewport' import mangoStore from '@store/mangoStore' import { COLORS } from '../../styles/colors' import { formatFixedDecimals } from '../../utils/numbers' import { breakpoints } from '../../utils/theme' import ContentBox from '../shared/ContentBox' import Change from '../shared/Change' import MarketLogos from '@components/trade/MarketLogos' import dynamic from 'next/dynamic' import { useCoingecko } from 'hooks/useCoingecko' import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements' import { usePerpFundingRate } from '@components/trade/PerpFundingRate' const SimpleAreaChart = dynamic( () => import('@components/shared/SimpleAreaChart'), { ssr: false } ) const PerpMarketsTable = () => { const { t } = useTranslation(['common', 'trade']) const { isLoading: loadingPrices, data: coingeckoPrices } = useCoingecko() const perpMarkets = mangoStore((s) => s.perpMarkets) const { theme } = useTheme() const { width } = useViewport() const showTableView = width ? width > breakpoints.md : false const rate = usePerpFundingRate() return ( {showTableView ? ( {perpMarkets.map((market) => { const symbol = market.name.split('-')[0] const coingeckoData = coingeckoPrices.find((asset) => symbol === 'soETH' ? asset.symbol === 'ETH' : asset.symbol === symbol ) const change = coingeckoData ? ((coingeckoData.prices[coingeckoData.prices.length - 1][1] - coingeckoData.prices[0][1]) / coingeckoData.prices[0][1]) * 100 : 0 const chartData = coingeckoData ? coingeckoData.prices : undefined let fundingRate if (rate.isSuccess && market instanceof PerpMarket) { const marketRate = rate?.data?.find( (r) => r.market_index === market.perpMarketIndex ) fundingRate = marketRate ? `${marketRate.funding_rate_hourly.toFixed(4)}%` : '–' } else { fundingRate = '–' } return ( ) })}
{t('market')} {t('price')} {t('trade:funding-rate')} {t('trade:open-interest')} {t('rolling-change')}

{market.name}

{formatFixedDecimals(market.uiPrice, true)}

{!loadingPrices ? ( chartData !== undefined ? ( = 0 ? COLORS.UP[theme] : COLORS.DOWN[theme] } data={chartData} height={40} name={symbol} width={104} xKey="0" yKey="1" /> ) : symbol === 'USDC' || symbol === 'USDT' ? null : (

{t('unavailable')}

) ) : (
)}

{fundingRate}

${market.openInterest.toString()}

) : (
{perpMarkets.map((market) => { return ( ) })}
)}
) } export default PerpMarketsTable const MobilePerpMarketItem = ({ market }: { market: PerpMarket }) => { const { t } = useTranslation('common') const { isLoading: loadingPrices, data: coingeckoPrices } = useCoingecko() const { theme } = useTheme() // const rate = usePerpFundingRate() const symbol = market.name.split('-')[0] const coingeckoData = coingeckoPrices.find((asset) => symbol === 'soETH' ? asset.symbol === 'ETH' : asset.symbol === symbol ) const change = coingeckoData ? ((coingeckoData.prices[coingeckoData.prices.length - 1][1] - coingeckoData.prices[0][1]) / coingeckoData.prices[0][1]) * 100 : 0 const chartData = coingeckoData ? coingeckoData.prices : undefined // let fundingRate // if ( // rate.isSuccess // // && bids instanceof BookSide && // // asks instanceof BookSide // ) { // const marketRate = rate.data.find( // (r) => r.market_index === market.perpMarketIndex // ) // fundingRate = `${marketRate?.funding_apr.toFixed(2)}%` // } else { // fundingRate = '–' // } return (

{market.name}

{formatFixedDecimals(market.uiPrice, true)}

{!loadingPrices ? ( chartData !== undefined ? ( = 0 ? COLORS.UP[theme] : COLORS.DOWN[theme]} data={chartData} height={40} name={market.name} width={104} xKey="0" yKey="1" /> ) : symbol === 'USDC' || symbol === 'USDT' ? null : (

{t('unavailable')}

) ) : (
)}
) }