mango-v4-ui/components/trade/TradeAdvancedPage.tsx

208 lines
6.1 KiB
TypeScript
Raw Normal View History

2022-11-19 11:20:36 -08:00
import { useMemo } from 'react'
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-12-20 01:13:24 -08:00
// import { IS_ONBOARDED_KEY } from 'utils/constants'
// import useLocalStorageState from 'hooks/useLocalStorageState'
2022-09-13 23:24:26 -07:00
import { breakpoints } from 'utils/theme'
2022-09-16 03:49:10 -07:00
import { useViewport } from 'hooks/useViewport'
2022-09-13 23:24:26 -07:00
import AdvancedMarketHeader from './AdvancedMarketHeader'
import AdvancedTradeForm from './AdvancedTradeForm'
import TradeInfoTabs from './TradeInfoTabs'
2022-09-16 03:49:10 -07:00
import MobileTradeAdvancedPage from './MobileTradeAdvancedPage'
2022-09-20 13:05:50 -07:00
import OrderbookAndTrades from './OrderbookAndTrades'
2022-12-20 01:13:24 -08:00
// import { useWallet } from '@solana/wallet-adapter-react'
// import TradeOnboardingTour from '@components/tours/TradeOnboardingTour'
2022-11-29 20:01:55 -08:00
import FavoriteMarketsBar from './FavoriteMarketsBar'
2022-09-13 23:24:26 -07:00
2022-12-06 09:35:15 -08:00
const TradingChartContainer = dynamic(() => import('./TradingChartContainer'), {
ssr: false,
})
2022-09-13 23:24:26 -07:00
2022-09-19 22:01:23 -07:00
const ResponsiveGridLayout = WidthProvider(Responsive)
2022-09-17 06:03:46 -07:00
const sidebarWidth = 63
2022-09-19 22:01:23 -07:00
const totalCols = 24
2022-09-13 23:24:26 -07:00
const gridBreakpoints = {
2022-09-17 06:03:46 -07:00
md: breakpoints.md - sidebarWidth,
lg: breakpoints.lg - sidebarWidth,
xl: breakpoints.xl - sidebarWidth,
xxl: breakpoints['2xl'] - sidebarWidth,
xxxl: breakpoints['3xl'] - sidebarWidth,
2022-09-13 23:24:26 -07:00
}
2022-09-16 03:49:10 -07:00
2022-09-19 22:01:23 -07:00
const getHeight = (
pageHeight: number,
minHeight: number,
remainingRowHeight: number
) => {
return Math.max(minHeight, pageHeight - remainingRowHeight)
2022-09-16 03:49:10 -07:00
}
2022-09-12 08:53:57 -07:00
const TradeAdvancedPage = () => {
2022-09-16 03:49:10 -07:00
const { height, width } = useViewport()
2022-09-13 23:24:26 -07:00
const { uiLocked } = mangoStore((s) => s.settings)
2022-09-16 03:49:10 -07:00
const showMobileView = width <= breakpoints.md
2022-12-20 01:13:24 -08:00
// const tourSettings = mangoStore((s) => s.settings.tours)
// const { connected } = useWallet()
// const [isOnboarded] = useLocalStorageState(IS_ONBOARDED_KEY)
2022-09-13 23:24:26 -07:00
2022-09-19 22:01:23 -07:00
const defaultLayouts: ReactGridLayout.Layouts = useMemo(() => {
const topnavbarHeight = 67
2022-11-19 17:40:06 -08:00
const innerHeight = Math.max(height - topnavbarHeight, 1000)
2022-09-19 22:01:23 -07:00
const marketHeaderHeight = 48
return {
xxxl: [
{ i: 'market-header', x: 0, y: 0, w: 16, h: marketHeaderHeight },
2022-09-29 13:27:11 -07:00
{ i: 'tv-chart', x: 0, y: 1, w: 16, h: 640 },
2022-09-19 22:01:23 -07:00
{
i: 'balances',
x: 0,
y: 2,
w: 16,
2022-10-23 04:38:48 -07:00
h: getHeight(innerHeight, 0, 640 + marketHeaderHeight),
2022-09-19 22:01:23 -07:00
},
{
i: 'orderbook',
x: 16,
y: 0,
w: 4,
2022-10-23 04:38:48 -07:00
h: getHeight(innerHeight, 0, 0),
2022-09-19 22:01:23 -07:00
},
{ i: 'trade-form', x: 20, y: 0, w: 4, h: getHeight(innerHeight, 0, 0) },
],
xxl: [
{ i: 'market-header', x: 0, y: 0, w: 15, h: marketHeaderHeight },
2023-01-24 10:08:35 -08:00
{ i: 'tv-chart', x: 0, y: 1, w: 15, h: 488 },
2022-09-19 22:01:23 -07:00
{
i: 'balances',
x: 0,
y: 2,
w: 15,
2023-01-24 10:08:35 -08:00
h: getHeight(innerHeight, 0, 488 + marketHeaderHeight),
2022-09-19 22:01:23 -07:00
},
{
i: 'orderbook',
x: 15,
y: 0,
w: 4,
2022-10-23 04:38:48 -07:00
h: getHeight(innerHeight, 0, 0),
2022-09-19 22:01:23 -07:00
},
{ i: 'trade-form', x: 19, y: 0, w: 5, h: getHeight(innerHeight, 0, 0) },
],
xl: [
2023-01-19 13:25:19 -08:00
{ i: 'market-header', x: 0, y: 0, w: 15, h: marketHeaderHeight },
{ i: 'tv-chart', x: 0, y: 1, w: 15, h: 488 },
2022-09-19 22:01:23 -07:00
{
i: 'balances',
x: 0,
y: 2,
2023-01-19 13:25:19 -08:00
w: 15,
2022-10-23 04:38:48 -07:00
h: getHeight(innerHeight, 0, 488 + marketHeaderHeight),
2022-09-19 22:01:23 -07:00
},
{
i: 'orderbook',
2023-01-19 13:25:19 -08:00
x: 15,
2022-09-19 22:01:23 -07:00
y: 0,
2023-01-19 13:25:19 -08:00
w: 4,
2022-10-23 04:38:48 -07:00
h: getHeight(innerHeight, 0, 0),
},
{
i: 'trade-form',
x: 19,
y: 0,
w: 5,
h: getHeight(innerHeight, 0, 0),
2022-09-19 22:01:23 -07:00
},
],
lg: [
{ i: 'market-header', x: 0, y: 0, w: 13, h: marketHeaderHeight },
2023-01-24 10:08:35 -08:00
{ i: 'tv-chart', x: 0, y: 1, w: 13, h: 456 },
2022-09-19 22:01:23 -07:00
{
i: 'balances',
x: 0,
y: 2,
w: 13,
2023-01-24 10:08:35 -08:00
h: getHeight(innerHeight, 0, 456 + marketHeaderHeight),
2022-09-19 22:01:23 -07:00
},
{
i: 'orderbook',
x: 13,
2022-09-19 22:01:23 -07:00
y: 0,
w: 5,
2022-10-23 04:38:48 -07:00
h: getHeight(innerHeight, 0, 0),
2022-09-19 22:01:23 -07:00
},
2022-11-25 02:10:23 -08:00
{ i: 'trade-form', x: 18, y: 0, w: 6, h: getHeight(innerHeight, 0, 0) },
2022-09-19 22:01:23 -07:00
],
md: [
{ i: 'market-header', x: 0, y: 0, w: 17, h: marketHeaderHeight },
2022-11-14 02:18:38 -08:00
{ i: 'tv-chart', x: 0, y: 1, w: 17, h: 464 },
{ i: 'balances', x: 0, y: 2, w: 17, h: 428 + marketHeaderHeight },
{ i: 'orderbook', x: 18, y: 2, w: 7, h: 428 + marketHeaderHeight },
2022-12-21 20:19:00 -08:00
{ i: 'trade-form', x: 18, y: 1, w: 7, h: 492 + marketHeaderHeight },
2022-09-19 22:01:23 -07:00
],
}
}, [height])
2022-09-13 23:24:26 -07:00
2022-09-16 03:49:10 -07:00
return showMobileView ? (
<MobileTradeAdvancedPage />
) : (
2022-09-21 21:25:24 -07:00
<>
2022-11-29 20:01:55 -08:00
<FavoriteMarketsBar />
2022-09-21 21:25:24 -07:00
<ResponsiveGridLayout
onBreakpointChange={(bp) => console.log('bp: ', bp)}
2022-09-21 21:25:24 -07:00
// 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}
containerPadding={[0, 0]}
margin={[0, 0]}
2022-09-22 21:08:56 -07:00
useCSSTransforms
2022-09-16 03:49:10 -07:00
>
2022-09-21 21:25:24 -07:00
<div key="market-header" className="z-10">
<AdvancedMarketHeader />
</div>
<div
key="tv-chart"
className="h-full border border-x-0 border-th-bkg-3"
>
<div className={`relative h-full overflow-auto`}>
2022-12-06 09:35:15 -08:00
<TradingChartContainer />
2022-09-21 21:25:24 -07:00
</div>
</div>
<div key="balances">
2022-09-30 05:55:28 -07:00
<TradeInfoTabs />
2022-09-21 21:25:24 -07:00
</div>
<div
className="border-l border-b border-th-bkg-3 lg:border-b-0 lg:border-l-0"
2022-09-21 21:25:24 -07:00
key="trade-form"
>
<AdvancedTradeForm />
</div>
<div
key="orderbook"
2022-10-25 19:01:45 -07:00
className="overflow-hidden border-l border-th-bkg-3 lg:border-r"
2022-09-21 21:25:24 -07:00
>
<OrderbookAndTrades />
</div>
</ResponsiveGridLayout>
2022-12-20 01:13:24 -08:00
{/* {!tourSettings?.trade_tour_seen && isOnboarded && connected ? (
2022-09-21 21:25:24 -07:00
<TradeOnboardingTour />
2022-12-20 01:13:24 -08:00
) : null} */}
2022-09-21 21:25:24 -07:00
</>
2022-09-12 08:53:57 -07:00
)
}
export default TradeAdvancedPage