mango-ui-v3/pages/stats.tsx

86 lines
2.7 KiB
TypeScript
Raw Normal View History

import { useState } from 'react'
import TopBar from '../components/TopBar'
import PageBodyContainer from '../components/PageBodyContainer'
import StatsTotals from '../components/stats-page/StatsTotals'
import StatsAssets from '../components/stats-page/StatsAssets'
2021-07-13 06:52:48 -07:00
import StatsPerps from '../components/stats-page/StatsPerps'
2021-08-30 11:41:42 -07:00
import useMangoStats from '../hooks/useMangoStats'
import Swipeable from '../components/mobile/Swipeable'
import SwipeableTabs from '../components/mobile/SwipeableTabs'
import Tabs from '../components/Tabs'
import { useViewport } from '../hooks/useViewport'
import { breakpoints } from '../components/TradePageGrid'
const TABS = [
'Totals',
2021-08-30 11:41:42 -07:00
'Assets',
'Perps',
// 'Markets',
// 'Liquidations',
]
2021-04-07 16:06:02 -07:00
export default function StatsPage() {
const { latestStats, stats, perpStats } = useMangoStats()
const [viewIndex, setViewIndex] = useState(0)
const [activeTab, setActiveTab] = useState(TABS[0])
const { width } = useViewport()
const isMobile = width ? width < breakpoints.sm : false
2021-04-07 16:06:02 -07:00
const handleChangeViewIndex = (index) => {
setViewIndex(index)
}
2021-04-07 16:06:02 -07:00
const handleTabChange = (tabName) => {
setActiveTab(tabName)
}
2021-04-07 16:06:02 -07:00
return (
<div className={`bg-th-bkg-1 text-th-fgd-1 transition-all`}>
2021-04-07 16:06:02 -07:00
<TopBar />
<PageBodyContainer>
<div className="flex flex-col sm:flex-row py-4 md:pb-4 md:pt-10">
<h1 className={`text-th-fgd-1 text-2xl font-semibold`}>Stats</h1>
</div>
{!isMobile ? (
<Tabs activeTab={activeTab} onChange={handleTabChange} tabs={TABS} />
) : (
<SwipeableTabs
onChange={handleChangeViewIndex}
tabs={TABS}
tabIndex={viewIndex}
/>
)}
<div className="bg-th-bkg-2 p-4 sm:p-6 rounded-lg">
{!isMobile ? (
<TabContent
activeTab={activeTab}
latestStats={latestStats}
perpStats={perpStats}
stats={stats}
/>
) : (
<Swipeable index={viewIndex} onChangeIndex={handleChangeViewIndex}>
<StatsTotals latestStats={latestStats} stats={stats} />
<StatsAssets latestStats={latestStats} stats={stats} />
<StatsPerps perpStats={perpStats} />
</Swipeable>
)}
</div>
</PageBodyContainer>
</div>
2021-04-07 16:06:02 -07:00
)
}
const TabContent = ({ activeTab, latestStats, perpStats, stats }) => {
switch (activeTab) {
case 'Totals':
return <StatsTotals latestStats={latestStats} stats={stats} />
case 'Assets':
return <StatsAssets latestStats={latestStats} stats={stats} />
case 'Perps':
return <StatsPerps perpStats={perpStats} />
default:
return <StatsTotals latestStats={latestStats} stats={stats} />
}
}