mango-ui-v3/components/stats_page/StatsAssets.tsx

132 lines
4.4 KiB
TypeScript
Raw Normal View History

import { useState } from 'react'
2021-06-10 18:07:32 -07:00
import Chart from '../Chart'
import Select from '../Select'
import { useTranslation } from 'next-i18next'
2021-08-30 11:41:42 -07:00
export default function StatsAssets({ latestStats, stats }) {
const { t } = useTranslation('common')
const [selectedAsset, setSelectedAsset] = useState<string>('BTC')
2021-08-29 21:56:27 -07:00
const selectedStatsData = stats.filter((stat) => stat.name === selectedAsset)
return (
<>
2021-12-07 20:00:02 -08:00
<div className="flex flex-row-reverse items-center md:items-stretch justify-between md:flex-col mb-4">
<Select
value={selectedAsset}
onChange={(a) => setSelectedAsset(a)}
className="w-24 md:hidden"
>
<div className="space-y-2">
{latestStats.map((stat) => (
<Select.Option
key={stat.name}
value={stat.name}
className={`bg-th-bkg-1 relative rounded-md w-full px-3 py-3 cursor-pointer default-transition flex hover:bg-th-bkg-3 focus:outline-none`}
>
<div className="flex items-center justify-between w-full">
{stat.name}
</div>
</Select.Option>
))}
</div>
</Select>
2021-12-08 03:40:41 -08:00
<div className="bg-th-bkg-3 hidden md:flex mb-4 md:mb-6 md:-mt-6 md:-mx-6 px-3 md:px-4 py-2 rounded-md md:rounded-none md:rounded-t-md">
2021-12-07 20:00:02 -08:00
{latestStats.map((stat, index) => (
<div
2021-12-07 20:00:02 -08:00
className={`md:px-2 py-1 text-xs md:text-sm ${
index > 0 ? 'ml-4 md:ml-2' : null
} rounded-md cursor-pointer default-transition
${
selectedAsset === stat.name
? `text-th-primary`
: `text-th-fgd-3 hover:text-th-fgd-1`
}
`}
2021-08-30 11:41:42 -07:00
onClick={() => setSelectedAsset(stat.name)}
key={stat.name as string}
>
2021-08-30 11:41:42 -07:00
{stat.name}
</div>
))}
</div>
2021-12-07 20:00:02 -08:00
<div className="flex items-center text-xl text-th-fgd-1">
<img
width="24"
height="24"
src={`/assets/icons/${selectedAsset
.split(/-|\//)[0]
.toLowerCase()}.svg`}
className="mr-2.5"
/>
{selectedAsset}
</div>
</div>
<div className="grid grid-flow-col grid-cols-1 grid-rows-4 md:grid-cols-2 md:grid-rows-2 gap-2 sm:gap-4">
<div
2022-01-06 18:35:48 -08:00
className="border border-th-bkg-3 relative md:mb-0 p-4 rounded-md"
style={{ height: '330px' }}
>
2021-06-10 18:07:32 -07:00
<Chart
title={t('total-deposits')}
xAxis="time"
yAxis="totalDeposits"
data={selectedStatsData}
2021-06-11 06:39:44 -07:00
labelFormat={(x) =>
2021-08-30 11:41:42 -07:00
x.toLocaleString(undefined, { maximumFractionDigits: 2 })
2021-06-11 06:39:44 -07:00
}
2021-06-10 18:07:32 -07:00
type="area"
/>
</div>
<div
2022-01-06 18:35:48 -08:00
className="border border-th-bkg-3 relative p-4 rounded-md"
style={{ height: '330px' }}
>
2021-06-10 18:07:32 -07:00
<Chart
title={t('deposit-interest')}
xAxis="time"
2021-08-30 11:41:42 -07:00
yAxis="depositRate"
data={selectedStatsData}
labelFormat={(x) => `${(x * 100).toFixed(5)}%`}
tickFormat={(x) =>
(x * 100).toLocaleString(undefined, { maximumFractionDigits: 4 })
}
2021-06-10 18:07:32 -07:00
type="bar"
/>
</div>
<div
2022-01-06 18:35:48 -08:00
className="border border-th-bkg-3 relative md:mb-0 p-4 rounded-md"
style={{ height: '330px' }}
>
2021-06-10 18:07:32 -07:00
<Chart
title={t('total-borrows')}
xAxis="time"
yAxis="totalBorrows"
data={selectedStatsData}
2021-06-11 06:39:44 -07:00
labelFormat={(x) =>
2021-08-30 11:41:42 -07:00
x.toLocaleString(undefined, { maximumFractionDigits: 2 })
2021-06-11 06:39:44 -07:00
}
2021-06-10 18:07:32 -07:00
type="area"
/>
</div>
<div
2022-01-06 18:35:48 -08:00
className="border border-th-bkg-3 relative p-4 rounded-md"
style={{ height: '330px' }}
>
2021-06-10 18:07:32 -07:00
<Chart
title={t('borrow-interest')}
xAxis="time"
2021-08-30 11:41:42 -07:00
yAxis="borrowRate"
data={selectedStatsData}
labelFormat={(x) => `${(x * 100).toFixed(5)}%`}
tickFormat={(x) =>
(x * 100).toLocaleString(undefined, { maximumFractionDigits: 4 })
}
2021-06-10 18:07:32 -07:00
type="bar"
/>
</div>
</div>
2021-08-30 11:41:42 -07:00
</>
)
}