mango-ui-v3/components/stats-page/StatsAssets.tsx

111 lines
3.3 KiB
TypeScript
Raw Normal View History

import { useState } from 'react'
2021-06-10 18:07:32 -07:00
import Chart from '../Chart'
const icons = {
BTC: '/assets/icons/btc.svg',
ETH: '/assets/icons/eth.svg',
SOL: '/assets/icons/sol.svg',
SRM: '/assets/icons/srm.svg',
USDT: '/assets/icons/usdt.svg',
USDC: '/assets/icons/usdc.svg',
2021-08-30 11:41:42 -07:00
MNGO: '/assets/icons/mngo.svg',
}
2021-08-30 11:41:42 -07:00
export default function StatsAssets({ latestStats, stats }) {
const [selectedAsset, setSelectedAsset] = useState<string>('BTC')
2021-08-29 21:56:27 -07:00
const selectedStatsData = stats.filter((stat) => stat.name === selectedAsset)
return (
<>
2021-06-10 18:07:32 -07:00
<div className="flex flex-col-reverse items-center sm:flex-row sm:justify-between sm:h-12 mb-4 w-full">
2021-08-30 11:41:42 -07:00
<div className="flex items-center text-xl text-th-fgd-1">
<img
src={icons[selectedAsset]}
alt={icons[selectedAsset]}
width="24"
height="24"
className="mr-2.5"
/>
{selectedAsset}
</div>
2021-06-10 18:07:32 -07:00
<div className="flex pb-4 sm:pb-0">
{latestStats.map((stat) => (
<div
className={`px-2 py-1 ml-2 rounded-md cursor-pointer default-transition bg-th-bkg-3
${
2021-08-30 11:41:42 -07:00
selectedAsset === stat.name
2021-06-10 18:07:32 -07:00
? `ring-1 ring-inset ring-th-primary text-th-primary`
: `text-th-fgd-1 opacity-50 hover:opacity-100`
}
`}
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>
</div>
<div className="grid grid-flow-col grid-cols-1 grid-rows-4 md:grid-cols-2 md:grid-rows-2 gap-4 pb-8">
<div
className="border border-th-bkg-3 relative md:mb-0 p-4 rounded-md"
style={{ height: '300px' }}
>
2021-06-10 18:07:32 -07:00
<Chart
title="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
className="border border-th-bkg-3 relative p-4 rounded-md"
style={{ height: '300px' }}
>
2021-06-10 18:07:32 -07:00
<Chart
title="Deposit Interest"
xAxis="time"
2021-08-30 11:41:42 -07:00
yAxis="depositRate"
data={selectedStatsData}
labelFormat={(x) => `${(x * 100).toFixed(5)}%`}
2021-06-10 18:07:32 -07:00
type="bar"
/>
</div>
<div
className="border border-th-bkg-3 relative md:mb-0 p-4 rounded-md"
style={{ height: '300px' }}
>
2021-06-10 18:07:32 -07:00
<Chart
title="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
className="border border-th-bkg-3 relative p-4 rounded-md"
style={{ height: '300px' }}
>
2021-06-10 18:07:32 -07:00
<Chart
title="Borrow Interest"
xAxis="time"
2021-08-30 11:41:42 -07:00
yAxis="borrowRate"
data={selectedStatsData}
labelFormat={(x) => `${(x * 100).toFixed(5)}%`}
2021-06-10 18:07:32 -07:00
type="bar"
/>
</div>
</div>
2021-08-30 11:41:42 -07:00
</>
)
}