2022-04-03 15:47:16 -07:00
|
|
|
import { useState } from 'react'
|
2021-03-30 15:47:08 -07:00
|
|
|
import TopBar from '../components/TopBar'
|
2021-06-10 07:09:25 -07:00
|
|
|
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'
|
2021-09-19 17:36:02 -07:00
|
|
|
import Swipeable from '../components/mobile/Swipeable'
|
|
|
|
import SwipeableTabs from '../components/mobile/SwipeableTabs'
|
2021-09-19 20:21:55 -07:00
|
|
|
import Tabs from '../components/Tabs'
|
|
|
|
import { useViewport } from '../hooks/useViewport'
|
|
|
|
import { breakpoints } from '../components/TradePageGrid'
|
2021-10-20 05:42:40 -07:00
|
|
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2021-03-30 15:47:08 -07:00
|
|
|
|
2021-11-14 10:37:02 -08:00
|
|
|
export async function getStaticProps({ locale }) {
|
2021-10-20 05:42:40 -07:00
|
|
|
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() {
|
2021-10-20 05:42:40 -07:00
|
|
|
const { t } = useTranslation('common')
|
|
|
|
const TABS = [
|
|
|
|
'Totals',
|
|
|
|
'Assets',
|
|
|
|
'Perps',
|
|
|
|
// 'Markets',
|
|
|
|
// 'Liquidations',
|
|
|
|
]
|
2021-08-30 16:47:43 -07:00
|
|
|
const { latestStats, stats, perpStats } = useMangoStats()
|
2021-09-19 17:36:02 -07:00
|
|
|
const [viewIndex, setViewIndex] = useState(0)
|
2021-09-19 20:21:55 -07:00
|
|
|
const [activeTab, setActiveTab] = useState(TABS[0])
|
|
|
|
const { width } = useViewport()
|
|
|
|
const isMobile = width ? width < breakpoints.sm : false
|
2021-04-07 16:06:02 -07:00
|
|
|
|
2021-09-19 17:36:02 -07:00
|
|
|
const handleChangeViewIndex = (index) => {
|
|
|
|
setViewIndex(index)
|
2021-06-10 07:09:25 -07:00
|
|
|
}
|
2021-04-07 16:06:02 -07:00
|
|
|
|
2021-09-19 20:21:55 -07:00
|
|
|
const handleTabChange = (tabName) => {
|
|
|
|
setActiveTab(tabName)
|
|
|
|
}
|
|
|
|
|
2021-04-07 16:06:02 -07:00
|
|
|
return (
|
2021-06-10 07:09:25 -07:00
|
|
|
<div className={`bg-th-bkg-1 text-th-fgd-1 transition-all`}>
|
2021-04-07 16:06:02 -07:00
|
|
|
<TopBar />
|
2021-06-10 07:09:25 -07:00
|
|
|
<PageBodyContainer>
|
2022-03-09 12:53:11 -08:00
|
|
|
<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>
|
2021-04-20 07:19:08 -07:00
|
|
|
</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}
|
|
|
|
/>
|
|
|
|
)}
|
2021-09-19 20:21:55 -07:00
|
|
|
{!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>
|
|
|
|
)}
|
2021-06-10 07:09:25 -07:00
|
|
|
</div>
|
|
|
|
</PageBodyContainer>
|
2021-04-13 09:51:42 -07:00
|
|
|
</div>
|
2021-04-07 16:06:02 -07:00
|
|
|
)
|
|
|
|
}
|
2021-09-19 20:21:55 -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} />
|
|
|
|
}
|
|
|
|
}
|