mango-ui-v3/pages/perp/[market].tsx

62 lines
1.9 KiB
TypeScript
Raw Normal View History

import { useEffect } from 'react'
import { useRouter } from 'next/router'
import useMangoGroupConfig from '../../hooks/useMangoGroupConfig'
import useMangoStore from '../../stores/useMangoStore'
import {
getMarketByBaseSymbolAndKind,
getMarketIndexBySymbol,
} from '@blockworks-foundation/mango-client'
import TopBar from '../../components/TopBar'
import TradePageGrid from '../../components/TradePageGrid'
import MarketSelect from '../../components/MarketSelect'
import MarketHeader from '../../components/MarketHeader'
const PerpMarket = () => {
const groupConfig = useMangoGroupConfig()
const setMangoStore = useMangoStore((s) => s.set)
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache)
2021-08-14 13:05:31 -07:00
const marketConfig = useMangoStore((s) => s.selectedMarket.config)
const router = useRouter()
const { market } = router.query
useEffect(() => {
if (market && mangoGroup) {
const newMarket = getMarketByBaseSymbolAndKind(
groupConfig,
market.toString().toUpperCase(),
'perp'
)
const marketIndex = getMarketIndexBySymbol(
groupConfig,
market.toString().toUpperCase()
)
2021-08-14 13:05:31 -07:00
setMangoStore((state) => {
state.selectedMarket.kind = 'perp'
2021-08-14 13:05:31 -07:00
if (newMarket.name !== marketConfig.name) {
state.selectedMarket.current = null
2021-08-14 13:05:31 -07:00
state.selectedMarket.config = newMarket
2021-08-18 13:15:17 -07:00
state.tradeForm.price =
state.tradeForm.tradeType === 'Limit'
? mangoGroup.getPrice(marketIndex, mangoCache).toFixed(2)
: ''
2021-08-14 13:05:31 -07:00
}
})
}
}, [market, mangoGroup])
return (
<div className={`bg-th-bkg-1 text-th-fgd-1 transition-all `}>
<TopBar />
<MarketSelect />
<MarketHeader />
2021-07-19 20:04:26 -07:00
<div className={`min-h-screen p-1 sm:px-2 sm:py-1 md:px-2 md:py-1`}>
<TradePageGrid />
</div>
</div>
)
}
export default PerpMarket