2022-09-15 20:40:30 -07:00
|
|
|
import { useCallback, useEffect, useState } from 'react'
|
2022-09-15 18:58:35 -07:00
|
|
|
// import { useTranslation } from 'next-i18next'
|
2022-09-13 23:24:26 -07:00
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
import ReactGridLayout, { Responsive, WidthProvider } from 'react-grid-layout'
|
|
|
|
|
2022-09-12 08:53:57 -07:00
|
|
|
import mangoStore from '@store/mangoStore'
|
2022-09-13 23:24:26 -07:00
|
|
|
import { GRID_LAYOUT_KEY } from 'utils/constants'
|
|
|
|
import useLocalStorageState from 'hooks/useLocalStorageState'
|
|
|
|
import { breakpoints } from 'utils/theme'
|
2022-09-15 18:58:35 -07:00
|
|
|
// import { useViewport } from 'hooks/useViewport'
|
2022-09-13 23:24:26 -07:00
|
|
|
import Orderbook from './Orderbook'
|
|
|
|
import AdvancedMarketHeader from './AdvancedMarketHeader'
|
|
|
|
import AdvancedTradeForm from './AdvancedTradeForm'
|
|
|
|
import BalanceAndOpenOrders from './BalanceAndOpenOrders'
|
|
|
|
|
|
|
|
const ResponsiveGridLayout = WidthProvider(Responsive)
|
2022-09-12 08:53:57 -07:00
|
|
|
|
2022-09-13 23:24:26 -07:00
|
|
|
const TradingViewChart = dynamic(() => import('./TradingViewChart'), {
|
|
|
|
ssr: false,
|
|
|
|
})
|
|
|
|
|
|
|
|
const gridBreakpoints = {
|
|
|
|
// sm: breakpoints.sm,
|
2022-09-15 20:40:30 -07:00
|
|
|
md: breakpoints.md,
|
|
|
|
lg: breakpoints.lg,
|
2022-09-13 23:24:26 -07:00
|
|
|
xl: breakpoints.xl,
|
|
|
|
xxl: breakpoints['2xl'],
|
|
|
|
xxxl: breakpoints['3xl'],
|
|
|
|
}
|
|
|
|
const totalCols = 24
|
2022-09-12 08:53:57 -07:00
|
|
|
const TradeAdvancedPage = () => {
|
2022-09-15 18:58:35 -07:00
|
|
|
// const { height } = useViewport()
|
2022-09-13 23:24:26 -07:00
|
|
|
const [currentBreakpoint, setCurrentBreakpoint] = useState<string>()
|
2022-09-15 18:58:35 -07:00
|
|
|
const [orderbookDepth, setOrderbookDepth] = useState(6)
|
2022-09-13 23:24:26 -07:00
|
|
|
const { uiLocked } = mangoStore((s) => s.settings)
|
|
|
|
|
2022-09-15 18:58:35 -07:00
|
|
|
const defaultLayouts = {
|
|
|
|
xxxl: [
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'market-header', x: 0, y: 0, w: 16, h: 48 },
|
2022-09-15 18:58:35 -07:00
|
|
|
{ i: 'tv-chart', x: 0, y: 1, w: 16, h: 676 },
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'balances', x: 0, y: 2, w: 20, h: 468 },
|
2022-09-15 18:58:35 -07:00
|
|
|
{ i: 'orderbook', x: 16, y: 1, w: 4, h: 724 },
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'trade-form', x: 20, y: 1, w: 4, h: 1193 },
|
2022-09-15 18:58:35 -07:00
|
|
|
],
|
|
|
|
xxl: [
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'market-header', x: 0, y: 0, w: 15, h: 48 },
|
2022-09-15 18:58:35 -07:00
|
|
|
{ i: 'tv-chart', x: 0, y: 1, w: 15, h: 576 },
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'balances', x: 0, y: 2, w: 19, h: 468 },
|
2022-09-15 18:58:35 -07:00
|
|
|
{ i: 'orderbook', x: 15, y: 1, w: 4, h: 624 },
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'trade-form', x: 19, y: 1, w: 5, h: 1093 },
|
2022-09-15 18:58:35 -07:00
|
|
|
],
|
|
|
|
xl: [
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'market-header', x: 0, y: 0, w: 14, h: 48 },
|
2022-09-15 18:58:35 -07:00
|
|
|
{ i: 'tv-chart', x: 0, y: 1, w: 14, h: 520 },
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'balances', x: 0, y: 2, w: 18, h: 468 },
|
2022-09-15 18:58:35 -07:00
|
|
|
{ i: 'orderbook', x: 14, y: 1, w: 4, h: 568 },
|
2022-09-15 20:40:30 -07:00
|
|
|
{ i: 'trade-form', x: 18, y: 1, w: 6, h: 1037 },
|
|
|
|
],
|
|
|
|
lg: [
|
|
|
|
{ i: 'market-header', x: 0, y: 0, w: 14, h: 48 },
|
|
|
|
{ i: 'tv-chart', x: 0, y: 1, w: 14, h: 520 },
|
|
|
|
{ i: 'balances', x: 0, y: 2, w: 18, h: 468 },
|
|
|
|
{ i: 'orderbook', x: 14, y: 1, w: 4, h: 568 },
|
|
|
|
{ i: 'trade-form', x: 18, y: 1, w: 6, h: 1037 },
|
|
|
|
],
|
|
|
|
md: [
|
|
|
|
{ i: 'market-header', x: 0, y: 0, w: 18, h: 48 },
|
|
|
|
{ i: 'tv-chart', x: 0, y: 1, w: 18, h: 520 },
|
|
|
|
{ i: 'balances', x: 0, y: 2, w: 18, h: 468 },
|
|
|
|
{ i: 'orderbook', x: 18, y: 2, w: 6, h: 469 },
|
|
|
|
{ i: 'trade-form', x: 18, y: 1, w: 6, h: 568 },
|
2022-09-15 18:58:35 -07:00
|
|
|
],
|
|
|
|
}
|
2022-09-13 23:24:26 -07:00
|
|
|
|
2022-09-15 18:58:35 -07:00
|
|
|
// const defaultLayouts: ReactGridLayout.Layouts = useMemo(() => {
|
|
|
|
// const innerHeight = Math.max(height - 36, 800)
|
|
|
|
// const tvChartHeight = 432
|
|
|
|
// const headerHeight = 48
|
|
|
|
// const balancesHeight = innerHeight - tvChartHeight - headerHeight
|
|
|
|
|
|
|
|
// return {
|
|
|
|
// xxxl: [
|
|
|
|
// { i: 'market-header', x: 0, y: 0, w: 16, h: headerHeight },
|
|
|
|
// { i: 'tv-chart', x: 0, y: 1, w: 16, h: tvChartHeight },
|
|
|
|
// { i: 'balances', x: 0, y: 2, w: 16, h: balancesHeight },
|
|
|
|
// { i: 'orderbook', x: 16, y: 1, w: 4, h: innerHeight },
|
|
|
|
// { i: 'trade-form', x: 20, y: 1, w: 4, h: innerHeight },
|
|
|
|
// ],
|
|
|
|
// xxl: [
|
|
|
|
// { i: 'market-header', x: 0, y: 0, w: 14, h: headerHeight },
|
|
|
|
// { i: 'tv-chart', x: 0, y: 1, w: 14, h: tvChartHeight },
|
|
|
|
// { i: 'balances', x: 0, y: 2, w: 14, h: balancesHeight },
|
|
|
|
// { i: 'orderbook', x: 14, y: 1, w: 5, h: innerHeight },
|
|
|
|
// { i: 'trade-form', x: 20, y: 1, w: 5, h: innerHeight },
|
|
|
|
// ],
|
|
|
|
// xl: [
|
|
|
|
// { i: 'market-header', x: 0, y: 0, w: 14, h: headerHeight },
|
|
|
|
// { i: 'tv-chart', x: 0, y: 1, w: 14, h: tvChartHeight },
|
|
|
|
// { i: 'balances', x: 0, y: 2, w: 14, h: balancesHeight },
|
|
|
|
// { i: 'orderbook', x: 14, y: 1, w: 5, h: innerHeight },
|
|
|
|
// { i: 'trade-form', x: 20, y: 1, w: 5, h: innerHeight },
|
|
|
|
// ],
|
|
|
|
// }
|
|
|
|
// }, [height])
|
2022-09-13 23:24:26 -07:00
|
|
|
|
|
|
|
const [savedLayouts, setSavedLayouts] = useLocalStorageState(
|
|
|
|
GRID_LAYOUT_KEY,
|
|
|
|
defaultLayouts
|
|
|
|
)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const adjustOrderBook = (
|
|
|
|
layouts: ReactGridLayout.Layouts,
|
|
|
|
breakpoint?: string | null
|
|
|
|
) => {
|
|
|
|
const bp = 'xxl'
|
|
|
|
const orderbookLayout = layouts[bp].find((obj) => {
|
|
|
|
return obj.i === 'orderbook'
|
|
|
|
})
|
|
|
|
let depth = orderbookLayout!.h / 24 / 2 - 2
|
|
|
|
const maxNum = Math.max(1, depth)
|
|
|
|
if (typeof maxNum === 'number') {
|
|
|
|
depth = Math.round(maxNum)
|
|
|
|
}
|
|
|
|
|
|
|
|
setOrderbookDepth(depth)
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustOrderBook(defaultLayouts, currentBreakpoint)
|
|
|
|
}, [currentBreakpoint, defaultLayouts])
|
|
|
|
|
|
|
|
const onLayoutChange = useCallback((layouts: ReactGridLayout.Layouts) => {
|
|
|
|
if (layouts) {
|
|
|
|
setSavedLayouts(layouts)
|
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const onBreakpointChange = useCallback((newBreakpoint: string) => {
|
|
|
|
setCurrentBreakpoint(newBreakpoint)
|
|
|
|
}, [])
|
2022-09-12 08:53:57 -07:00
|
|
|
|
|
|
|
return (
|
2022-09-15 18:58:35 -07:00
|
|
|
<div className="">
|
2022-09-13 23:24:26 -07:00
|
|
|
<ResponsiveGridLayout
|
|
|
|
// layouts={savedLayouts ? savedLayouts : defaultLayouts}
|
|
|
|
layouts={defaultLayouts}
|
|
|
|
breakpoints={gridBreakpoints}
|
|
|
|
cols={{
|
|
|
|
xxxl: totalCols,
|
|
|
|
xxl: totalCols,
|
|
|
|
xl: totalCols,
|
|
|
|
lg: totalCols,
|
|
|
|
md: totalCols,
|
|
|
|
sm: totalCols,
|
|
|
|
}}
|
|
|
|
rowHeight={1}
|
|
|
|
isDraggable={!uiLocked}
|
|
|
|
isResizable={!uiLocked}
|
|
|
|
onBreakpointChange={(newBreakpoint) =>
|
|
|
|
onBreakpointChange(newBreakpoint)
|
|
|
|
}
|
|
|
|
onLayoutChange={(layout, layouts) => onLayoutChange(layouts)}
|
|
|
|
measureBeforeMount
|
2022-09-15 18:58:35 -07:00
|
|
|
containerPadding={[0, 0]}
|
2022-09-13 23:24:26 -07:00
|
|
|
margin={[0, 0]}
|
|
|
|
>
|
|
|
|
<div key="market-header" className="z-10">
|
|
|
|
<AdvancedMarketHeader />
|
|
|
|
</div>
|
2022-09-14 20:08:42 -07:00
|
|
|
<div
|
|
|
|
key="tv-chart"
|
|
|
|
className="h-full border border-x-0 border-th-bkg-3"
|
|
|
|
>
|
2022-09-13 23:24:26 -07:00
|
|
|
<div className={`relative h-full overflow-auto`}>
|
|
|
|
<TradingViewChart />
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-15 18:58:35 -07:00
|
|
|
<div key="balances" className="h-full">
|
2022-09-13 23:24:26 -07:00
|
|
|
<BalanceAndOpenOrders />
|
|
|
|
</div>
|
2022-09-15 18:58:35 -07:00
|
|
|
<div
|
|
|
|
key="orderbook"
|
|
|
|
className="border border-t-0 border-r-0 border-th-bkg-3"
|
|
|
|
>
|
2022-09-14 21:51:19 -07:00
|
|
|
<div className="flex h-[49px] items-center border-b border-th-bkg-3 px-4 ">
|
|
|
|
<h2 className="text-sm text-th-fgd-3">Orderbook</h2>
|
|
|
|
</div>
|
2022-09-13 23:24:26 -07:00
|
|
|
<div className="flex items-center justify-between px-4 py-2 text-xs text-th-fgd-4">
|
|
|
|
<div>Size</div>
|
|
|
|
<div>Price</div>
|
|
|
|
</div>
|
|
|
|
<div className="hide-scroll h-full overflow-y-scroll">
|
|
|
|
<Orderbook depth={orderbookDepth} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-14 20:08:42 -07:00
|
|
|
<div
|
|
|
|
key="trade-form"
|
2022-09-15 18:58:35 -07:00
|
|
|
className="border border-r-0 border-t-0 border-th-bkg-3"
|
2022-09-14 20:08:42 -07:00
|
|
|
>
|
2022-09-13 23:24:26 -07:00
|
|
|
<AdvancedTradeForm />
|
|
|
|
</div>
|
|
|
|
</ResponsiveGridLayout>
|
2022-09-12 08:53:57 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TradeAdvancedPage
|