2022-09-21 22:28:53 -07:00
|
|
|
import TabButtons from '@components/shared/TabButtons'
|
2023-07-20 17:09:34 -07:00
|
|
|
import { useEffect, useMemo, useState } from 'react'
|
2022-09-20 13:05:50 -07:00
|
|
|
import Orderbook from './Orderbook'
|
|
|
|
import RecentTrades from './RecentTrades'
|
2023-06-29 20:05:41 -07:00
|
|
|
import DepthChart from './DepthChart'
|
2023-07-12 07:37:18 -07:00
|
|
|
import useLocalStorageState from 'hooks/useLocalStorageState'
|
|
|
|
import { DEPTH_CHART_KEY } from 'utils/constants'
|
2023-07-20 17:09:34 -07:00
|
|
|
import { useViewport } from 'hooks/useViewport'
|
|
|
|
import { breakpoints } from 'utils/theme'
|
2022-09-20 13:05:50 -07:00
|
|
|
|
2022-10-25 18:37:59 -07:00
|
|
|
export const TABS: [string, number][] = [
|
2022-10-03 03:38:05 -07:00
|
|
|
['trade:book', 0],
|
2023-07-20 17:09:34 -07:00
|
|
|
['trade:depth', 0],
|
2022-10-03 03:38:05 -07:00
|
|
|
['trade:trades', 0],
|
2022-09-28 13:02:12 -07:00
|
|
|
]
|
|
|
|
|
2023-07-17 18:18:01 -07:00
|
|
|
const OrderbookAndTrades = () => {
|
2022-10-03 03:38:05 -07:00
|
|
|
const [activeTab, setActiveTab] = useState('trade:book')
|
2023-07-12 07:37:18 -07:00
|
|
|
const [showDepthChart] = useLocalStorageState<boolean>(DEPTH_CHART_KEY, false)
|
2023-07-20 17:09:34 -07:00
|
|
|
const { width } = useViewport()
|
|
|
|
const hideDepthTab = width ? width > breakpoints.lg : false
|
|
|
|
|
|
|
|
const tabsToShow = useMemo(() => {
|
|
|
|
if (hideDepthTab) {
|
|
|
|
return TABS.filter((t) => !t[0].includes('depth'))
|
|
|
|
}
|
|
|
|
return TABS
|
|
|
|
}, [hideDepthTab])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (hideDepthTab && activeTab === 'trade:depth') {
|
|
|
|
setActiveTab('trade:book')
|
|
|
|
}
|
|
|
|
}, [activeTab, hideDepthTab])
|
|
|
|
|
2022-09-20 13:05:50 -07:00
|
|
|
return (
|
|
|
|
<div className="hide-scroll h-full">
|
2023-07-20 17:09:34 -07:00
|
|
|
<div className="hide-scroll overflow-x-auto border-b border-th-bkg-3">
|
2022-09-21 22:28:53 -07:00
|
|
|
<TabButtons
|
|
|
|
activeValue={activeTab}
|
|
|
|
onChange={(tab: string) => setActiveTab(tab)}
|
2023-07-20 17:09:34 -07:00
|
|
|
values={tabsToShow}
|
|
|
|
fillWidth={!showDepthChart || !hideDepthTab}
|
|
|
|
showBorders
|
2022-09-21 22:28:53 -07:00
|
|
|
/>
|
2022-09-20 13:05:50 -07:00
|
|
|
</div>
|
2022-10-03 03:38:05 -07:00
|
|
|
<div
|
2023-07-12 07:37:18 -07:00
|
|
|
className={`flex ${activeTab === 'trade:book' ? 'visible' : 'hidden'}`}
|
2023-06-29 20:05:41 -07:00
|
|
|
>
|
2023-07-12 07:37:18 -07:00
|
|
|
{showDepthChart ? (
|
2023-07-17 18:18:01 -07:00
|
|
|
<div className="hidden w-1/2 border-r border-th-bkg-3 lg:block">
|
|
|
|
<DepthChart />
|
2023-07-12 07:37:18 -07:00
|
|
|
</div>
|
|
|
|
) : null}
|
2023-07-17 18:18:01 -07:00
|
|
|
<div className={showDepthChart ? 'w-full lg:w-1/2' : 'w-full'}>
|
|
|
|
<Orderbook />
|
2023-07-12 07:37:18 -07:00
|
|
|
</div>
|
2023-06-29 20:05:41 -07:00
|
|
|
</div>
|
2023-07-20 17:09:34 -07:00
|
|
|
<div
|
|
|
|
className={`h-full ${
|
|
|
|
activeTab === 'trade:depth' ? 'visible' : 'hidden'
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<DepthChart />
|
|
|
|
</div>
|
2022-09-20 13:05:50 -07:00
|
|
|
<div
|
2022-10-03 03:38:05 -07:00
|
|
|
className={`h-full ${
|
|
|
|
activeTab === 'trade:trades' ? 'visible' : 'hidden'
|
|
|
|
}`}
|
2022-09-20 13:05:50 -07:00
|
|
|
>
|
|
|
|
<RecentTrades />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default OrderbookAndTrades
|