2021-04-02 11:26:21 -07:00
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
import { Responsive, WidthProvider } from 'react-grid-layout'
|
|
|
|
|
|
|
|
const TVChartContainer = dynamic(
|
|
|
|
() => import('../components/TradingView/index'),
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
2021-04-17 17:04:18 -07:00
|
|
|
import { useEffect, useState } from 'react'
|
2021-04-02 11:26:21 -07:00
|
|
|
import FloatingElement from '../components/FloatingElement'
|
2021-06-17 14:07:10 -07:00
|
|
|
import Orderbook from '../components/Orderbook'
|
2021-08-16 10:00:43 -07:00
|
|
|
import AccountInfo from './AccountInfo'
|
2021-08-14 11:16:15 -07:00
|
|
|
import MarketPosition from './MarketPosition'
|
2021-06-17 15:37:03 -07:00
|
|
|
import TradeForm from './TradeForm'
|
2021-06-18 08:17:49 -07:00
|
|
|
import UserInfo from './UserInfo'
|
2021-07-19 10:13:03 -07:00
|
|
|
import RecentMarketTrades from './RecentMarketTrades'
|
2021-04-13 09:51:42 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-04-16 13:17:33 -07:00
|
|
|
import useLocalStorageState from '../hooks/useLocalStorageState'
|
2021-04-02 11:26:21 -07:00
|
|
|
|
|
|
|
const ResponsiveGridLayout = WidthProvider(Responsive)
|
|
|
|
|
2021-04-22 05:33:35 -07:00
|
|
|
export const defaultLayouts = {
|
2021-04-05 07:32:11 -07:00
|
|
|
xl: [
|
2021-05-01 21:31:55 -07:00
|
|
|
{ i: 'tvChart', x: 0, y: 0, w: 6, h: 30 },
|
|
|
|
{ i: 'orderbook', x: 6, y: 0, w: 3, h: 17 },
|
2021-07-21 09:34:59 -07:00
|
|
|
{ i: 'tradeForm', x: 9, y: 1, w: 3, h: 14 },
|
2021-05-01 21:31:55 -07:00
|
|
|
{ i: 'marketTrades', x: 6, y: 1, w: 3, h: 13 },
|
2021-08-16 06:31:25 -07:00
|
|
|
{ i: 'marketPosition', x: 9, y: 3, w: 3, h: 13 },
|
2021-06-12 10:46:06 -07:00
|
|
|
{ i: 'userInfo', x: 0, y: 2, w: 9, h: 19 },
|
2021-08-16 10:00:43 -07:00
|
|
|
{ i: 'accountInfo', x: 9, y: 4, w: 3, h: 15 },
|
2021-04-05 07:32:11 -07:00
|
|
|
],
|
|
|
|
lg: [
|
2021-08-16 06:31:25 -07:00
|
|
|
{ i: 'tvChart', x: 0, y: 0, w: 8, h: 28, minW: 2 },
|
|
|
|
{ i: 'marketPosition', x: 8, y: 0, w: 4, h: 13, minW: 2 },
|
2021-08-16 10:00:43 -07:00
|
|
|
{ i: 'accountInfo', x: 8, y: 1, w: 4, h: 15, minW: 2 },
|
2021-05-01 21:31:55 -07:00
|
|
|
{ i: 'orderbook', x: 0, y: 2, w: 4, h: 17, minW: 2 },
|
|
|
|
{ i: 'tradeForm', x: 4, y: 2, w: 4, h: 17, minW: 3 },
|
|
|
|
{ i: 'marketTrades', x: 8, y: 2, w: 4, h: 17, minW: 2 },
|
2021-06-12 10:46:06 -07:00
|
|
|
{ i: 'userInfo', x: 0, y: 3, w: 12, h: 19, minW: 6 },
|
2021-05-01 21:31:55 -07:00
|
|
|
],
|
|
|
|
md: [
|
2021-08-16 06:31:25 -07:00
|
|
|
{ i: 'tvChart', x: 0, y: 0, w: 8, h: 28, minW: 2 },
|
|
|
|
{ i: 'marketPosition', x: 8, y: 0, w: 4, h: 13, minW: 2 },
|
2021-08-16 10:00:43 -07:00
|
|
|
{ i: 'accountInfo', x: 8, y: 1, w: 4, h: 15, minW: 2 },
|
2021-05-01 21:31:55 -07:00
|
|
|
{ i: 'orderbook', x: 0, y: 2, w: 4, h: 17, minW: 2 },
|
|
|
|
{ i: 'tradeForm', x: 4, y: 2, w: 4, h: 17, minW: 3 },
|
|
|
|
{ i: 'marketTrades', x: 8, y: 2, w: 4, h: 17, minW: 2 },
|
2021-06-12 10:46:06 -07:00
|
|
|
{ i: 'userInfo', x: 0, y: 3, w: 12, h: 19, minW: 6 },
|
2021-05-01 21:31:55 -07:00
|
|
|
],
|
|
|
|
sm: [
|
|
|
|
{ i: 'tvChart', x: 0, y: 0, w: 12, h: 25, minW: 6 },
|
2021-07-20 07:21:58 -07:00
|
|
|
{ i: 'marketPosition', x: 0, y: 1, w: 6, h: 15, minW: 2 },
|
2021-08-16 10:00:43 -07:00
|
|
|
{ i: 'accountInfo', x: 6, y: 1, w: 6, h: 15, minW: 2 },
|
2021-05-01 21:31:55 -07:00
|
|
|
{ i: 'tradeForm', x: 0, y: 2, w: 12, h: 13, minW: 3 },
|
|
|
|
{ i: 'orderbook', x: 0, y: 3, w: 6, h: 17, minW: 3 },
|
|
|
|
{ i: 'marketTrades', x: 6, y: 3, w: 6, h: 17, minW: 2 },
|
2021-06-12 10:46:06 -07:00
|
|
|
{ i: 'userInfo', x: 0, y: 4, w: 12, h: 19, minW: 6 },
|
2021-05-01 21:31:55 -07:00
|
|
|
],
|
|
|
|
xs: [
|
|
|
|
{ i: 'tvChart', x: 0, y: 0, w: 0, h: 0, minW: 6 },
|
2021-08-16 06:31:25 -07:00
|
|
|
{ i: 'marketPosition', x: 0, y: 1, w: 6, h: 13, minW: 2 },
|
2021-08-16 10:00:43 -07:00
|
|
|
{ i: 'accountInfo', x: 0, y: 2, w: 6, h: 15, minW: 2 },
|
2021-05-01 21:31:55 -07:00
|
|
|
{ i: 'tradeForm', x: 0, y: 3, w: 12, h: 13, minW: 3 },
|
|
|
|
{ i: 'orderbook', x: 0, y: 4, w: 6, h: 17, minW: 3 },
|
|
|
|
{ i: 'marketTrades', x: 0, y: 5, w: 6, h: 17, minW: 2 },
|
2021-06-12 10:46:06 -07:00
|
|
|
{ i: 'userInfo', x: 0, y: 6, w: 12, h: 19, minW: 6 },
|
2021-04-05 07:32:11 -07:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-08-16 10:00:43 -07:00
|
|
|
export const GRID_LAYOUT_KEY = 'mangoSavedLayouts-3.0.6'
|
2021-05-01 21:31:55 -07:00
|
|
|
|
2021-04-02 11:26:21 -07:00
|
|
|
const TradePageGrid = () => {
|
2021-04-13 09:51:42 -07:00
|
|
|
const { uiLocked } = useMangoStore((s) => s.settings)
|
2021-04-16 13:17:33 -07:00
|
|
|
const [savedLayouts, setSavedLayouts] = useLocalStorageState(
|
2021-05-01 21:31:55 -07:00
|
|
|
GRID_LAYOUT_KEY,
|
2021-04-16 13:17:33 -07:00
|
|
|
defaultLayouts
|
|
|
|
)
|
|
|
|
|
2021-04-16 14:54:46 -07:00
|
|
|
const onLayoutChange = (layouts) => {
|
2021-04-16 14:40:20 -07:00
|
|
|
if (layouts) {
|
|
|
|
setSavedLayouts(layouts)
|
|
|
|
}
|
2021-04-16 13:17:33 -07:00
|
|
|
}
|
2021-04-13 09:51:42 -07:00
|
|
|
|
2021-04-17 17:04:18 -07:00
|
|
|
const [mounted, setMounted] = useState(false)
|
|
|
|
useEffect(() => setMounted(true), [])
|
|
|
|
if (!mounted) return null
|
2021-08-16 10:00:43 -07:00
|
|
|
|
2021-04-02 11:26:21 -07:00
|
|
|
return (
|
|
|
|
<ResponsiveGridLayout
|
|
|
|
className="layout"
|
2021-08-04 11:31:32 -07:00
|
|
|
layouts={savedLayouts || defaultLayouts}
|
2021-04-17 17:04:18 -07:00
|
|
|
breakpoints={{ xl: 1600, lg: 1200, md: 1110, sm: 768, xs: 0 }}
|
2021-05-01 21:31:55 -07:00
|
|
|
cols={{ xl: 12, lg: 12, md: 12, sm: 12, xs: 1 }}
|
2021-04-05 12:03:20 -07:00
|
|
|
rowHeight={15}
|
2021-04-13 09:51:42 -07:00
|
|
|
isDraggable={!uiLocked}
|
|
|
|
isResizable={!uiLocked}
|
2021-04-16 14:54:46 -07:00
|
|
|
onLayoutChange={(layout, layouts) => onLayoutChange(layouts)}
|
2021-04-02 11:26:21 -07:00
|
|
|
>
|
2021-04-05 12:03:20 -07:00
|
|
|
<div key="tvChart">
|
2021-04-24 15:23:01 -07:00
|
|
|
<FloatingElement className="pl-0">
|
2021-04-02 11:26:21 -07:00
|
|
|
<TVChartContainer />
|
|
|
|
</FloatingElement>
|
|
|
|
</div>
|
2021-06-18 15:38:09 -07:00
|
|
|
<div key="orderbook">
|
|
|
|
<Orderbook />
|
|
|
|
</div>
|
|
|
|
<div key="tradeForm">
|
|
|
|
<TradeForm />
|
|
|
|
</div>
|
2021-08-16 10:00:43 -07:00
|
|
|
<div key="accountInfo">
|
|
|
|
<AccountInfo />
|
2021-06-20 11:08:14 -07:00
|
|
|
</div>
|
2021-06-18 08:17:49 -07:00
|
|
|
<div key="userInfo">
|
|
|
|
<UserInfo />
|
|
|
|
</div>
|
2021-08-14 11:16:15 -07:00
|
|
|
<div key="marketPosition">
|
2021-07-20 07:21:58 -07:00
|
|
|
<MarketPosition />
|
2021-07-21 09:34:59 -07:00
|
|
|
</div>
|
2021-07-19 10:13:03 -07:00
|
|
|
<div key="marketTrades">
|
|
|
|
<RecentMarketTrades />
|
|
|
|
</div>
|
2021-04-02 11:26:21 -07:00
|
|
|
</ResponsiveGridLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TradePageGrid
|