mango-ui-v3/pages/stats.tsx

101 lines
3.1 KiB
TypeScript
Raw Normal View History

2022-04-03 15:47:16 -07:00
import { useState } from 'react'
import TopBar from '../components/TopBar'
import PageBodyContainer from '../components/PageBodyContainer'
2021-09-26 06:20:51 -07:00
import StatsTotals from '../components/stats_page/StatsTotals'
import StatsAssets from '../components/stats_page/StatsAssets'
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'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import { useTranslation } from 'next-i18next'
export async function getStaticProps({ locale }) {
return {
props: {
...(await serverSideTranslations(locale, ['common'])),
// Will be passed to the page component as props
},
}
}
2021-04-07 16:06:02 -07:00
export default function StatsPage() {
const { t } = useTranslation('common')
const TABS = [
'Totals',
'Assets',
'Perps',
// 'Markets',
// 'Liquidations',
]
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 py-4 sm:flex-row md:pb-4 md:pt-10">
2022-02-20 19:55:13 -08:00
<h1>{t('stats')}</h1>
</div>
2022-03-21 17:20:41 -07:00
<div className="md:rounded-lg md:bg-th-bkg-2 md:p-6">
{!isMobile ? (
<Tabs
activeTab={activeTab}
onChange={handleTabChange}
tabs={TABS}
/>
) : (
<SwipeableTabs
onChange={handleChangeViewIndex}
tabs={TABS}
tabIndex={viewIndex}
/>
)}
{!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} />
}
}