2023-01-17 15:38:33 -08:00
|
|
|
import mangoStore from '@store/mangoStore'
|
|
|
|
import TotalDepositBorrowCharts from './TotalDepositBorrowCharts'
|
|
|
|
// import { useTranslation } from 'next-i18next'
|
2022-12-30 03:40:52 -08:00
|
|
|
// import { PerpMarket } from '@blockworks-foundation/mango-v4'
|
2022-12-20 00:16:05 -08:00
|
|
|
|
|
|
|
const MangoStats = () => {
|
2023-01-17 15:38:33 -08:00
|
|
|
// const { t } = useTranslation(['common', 'token', 'trade'])
|
2022-12-20 00:16:05 -08:00
|
|
|
const tokenStats = mangoStore((s) => s.tokenStats.data)
|
|
|
|
const loadingStats = mangoStore((s) => s.tokenStats.loading)
|
2022-12-30 03:40:52 -08:00
|
|
|
// const perpStats = mangoStore((s) => s.perpStats.data)
|
|
|
|
// const loadingPerpStats = mangoStore((s) => s.perpStats.loading)
|
|
|
|
// const perpMarkets = mangoStore((s) => s.perpMarkets)
|
2022-12-20 00:16:05 -08:00
|
|
|
|
2022-12-30 03:40:52 -08:00
|
|
|
// const totalFeeValues = useMemo(() => {
|
|
|
|
// if (!perpStats.length) return []
|
|
|
|
// const values = perpStats.reduce((a, c) => {
|
|
|
|
// const hasDate = a.find((d: any) => d.date === c.date_hour)
|
|
|
|
// if (!hasDate) {
|
|
|
|
// a.push({
|
|
|
|
// date: c.date_hour,
|
|
|
|
// feeValue: Math.floor(c.fees_accrued),
|
|
|
|
// })
|
|
|
|
// } else {
|
|
|
|
// hasDate.feeValue = hasDate.feeValue + Math.floor(c.fees_accrued)
|
|
|
|
// }
|
|
|
|
// return a
|
|
|
|
// }, [])
|
|
|
|
// return values.reverse()
|
|
|
|
// }, [perpStats])
|
2022-12-20 00:16:05 -08:00
|
|
|
|
2022-12-30 03:40:52 -08:00
|
|
|
// const totalOpenInterestValues = useMemo(() => {
|
|
|
|
// if (!perpStats) return []
|
|
|
|
// const values = perpStats.reduce((a, c) => {
|
|
|
|
// const hasDate = a.find((d: any) => d.date === c.date_hour)
|
|
|
|
// if (!hasDate) {
|
|
|
|
// a.push({
|
|
|
|
// date: c.date_hour,
|
|
|
|
// openInterest: Math.floor(c.open_interest * c.price),
|
|
|
|
// })
|
|
|
|
// } else {
|
|
|
|
// hasDate.openInterest =
|
|
|
|
// hasDate.openInterest + Math.floor(c.open_interest * c.price)
|
|
|
|
// }
|
|
|
|
// return a
|
|
|
|
// }, [])
|
|
|
|
// return values.reverse()
|
|
|
|
// }, [perpStats])
|
|
|
|
|
|
|
|
// i think c.openInterest below needs some sort of conversion to give the correct number. then this can be added as the current value of the chart
|
2022-12-20 00:16:05 -08:00
|
|
|
|
2022-12-30 03:40:52 -08:00
|
|
|
// const currentTotalOpenInterestValue = useMemo(() => {
|
|
|
|
// if (!perpMarkets.length) return 0
|
|
|
|
// return perpMarkets.reduce((a: number, c: PerpMarket) => {
|
|
|
|
// const value = a + c.openInterest.toNumber() * c.uiPrice
|
|
|
|
// return value
|
|
|
|
// }, 0)
|
|
|
|
// }, [perpMarkets])
|
2022-12-20 00:16:05 -08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="grid grid-cols-2">
|
2023-01-17 15:38:33 -08:00
|
|
|
<TotalDepositBorrowCharts
|
|
|
|
tokenStats={tokenStats}
|
|
|
|
loadingStats={loadingStats}
|
|
|
|
/>
|
2022-12-30 03:40:52 -08:00
|
|
|
{/* uncomment below when perps launch */}
|
|
|
|
|
|
|
|
{/* {loadingPerpStats ? (
|
2022-12-20 00:16:05 -08:00
|
|
|
<div className="col-span-2 border-b border-th-bkg-3 py-4 px-6 md:col-span-1">
|
|
|
|
<SheenLoader className="flex flex-1">
|
|
|
|
<div className="h-96 w-full rounded-lg bg-th-bkg-2" />
|
|
|
|
</SheenLoader>
|
|
|
|
</div>
|
|
|
|
) : totalFeeValues.length ? (
|
|
|
|
<div className="col-span-2 border-b border-th-bkg-3 py-4 px-6 md:col-span-1">
|
|
|
|
<DetailedAreaChart
|
2022-12-30 03:40:52 -08:00
|
|
|
data={totalOpenInterestValues}
|
2022-12-20 00:16:05 -08:00
|
|
|
daysToShow={'999'}
|
|
|
|
heightClass="h-64"
|
|
|
|
prefix="$"
|
2022-12-30 03:40:52 -08:00
|
|
|
tickFormat={(x) => `$${Math.floor(x)}`}
|
2022-12-20 00:16:05 -08:00
|
|
|
title={t('trade:open-interest')}
|
|
|
|
xKey="date"
|
|
|
|
yKey={'openInterest'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
{loadingPerpStats ? (
|
|
|
|
<div className="col-span-2 border-b border-th-bkg-3 py-4 px-6 md:col-span-1 md:border-l md:pl-6">
|
|
|
|
<SheenLoader className="flex flex-1">
|
|
|
|
<div className="h-96 w-full rounded-lg bg-th-bkg-2" />
|
|
|
|
</SheenLoader>
|
|
|
|
</div>
|
|
|
|
) : totalOpenInterestValues.length ? (
|
|
|
|
<div className="col-span-2 border-b border-th-bkg-3 py-4 px-6 md:col-span-1 md:border-l md:pl-6">
|
|
|
|
<DetailedAreaChart
|
|
|
|
data={totalFeeValues}
|
|
|
|
daysToShow={'999'}
|
|
|
|
heightClass="h-64"
|
|
|
|
prefix="$"
|
|
|
|
tickFormat={(x) => `$${x.toFixed(2)}`}
|
2022-12-30 03:40:52 -08:00
|
|
|
title="Perp Fees"
|
2022-12-20 00:16:05 -08:00
|
|
|
xKey="date"
|
|
|
|
yKey={'feeValue'}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-12-30 03:40:52 -08:00
|
|
|
) : null} */}
|
2022-12-20 00:16:05 -08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MangoStats
|