2021-06-10 07:09:25 -07:00
|
|
|
import { useState } from 'react'
|
2021-06-10 18:07:32 -07:00
|
|
|
import Chart from '../Chart'
|
2021-09-19 17:36:02 -07:00
|
|
|
import Select from '../Select'
|
2021-10-20 05:42:40 -07:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2021-06-10 07:09:25 -07:00
|
|
|
|
2021-08-30 11:41:42 -07:00
|
|
|
export default function StatsAssets({ latestStats, stats }) {
|
2021-10-20 05:42:40 -07:00
|
|
|
const { t } = useTranslation('common')
|
2021-06-10 07:09:25 -07:00
|
|
|
const [selectedAsset, setSelectedAsset] = useState<string>('BTC')
|
|
|
|
|
2021-08-29 21:56:27 -07:00
|
|
|
const selectedStatsData = stats.filter((stat) => stat.name === selectedAsset)
|
2021-06-10 07:09:25 -07:00
|
|
|
|
|
|
|
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">
|
2021-09-19 17:36:02 -07:00
|
|
|
<Select
|
|
|
|
value={selectedAsset}
|
|
|
|
onChange={(a) => setSelectedAsset(a)}
|
2021-11-03 04:28:58 -07:00
|
|
|
className="w-24 md:hidden"
|
2021-09-19 17:36:02 -07:00
|
|
|
>
|
|
|
|
<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) => (
|
2021-06-10 07:09:25 -07:00
|
|
|
<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-06-10 07:09:25 -07:00
|
|
|
>
|
2021-08-30 11:41:42 -07:00
|
|
|
{stat.name}
|
2021-06-10 07:09:25 -07:00
|
|
|
</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>
|
2021-06-10 07:09:25 -07:00
|
|
|
</div>
|
2021-09-19 17:36:02 -07:00
|
|
|
<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">
|
2021-06-10 07:09:25 -07:00
|
|
|
<div
|
2022-01-06 18:35:48 -08:00
|
|
|
className="border border-th-bkg-3 relative md:mb-0 p-4 rounded-md"
|
2021-10-07 04:34:26 -07:00
|
|
|
style={{ height: '330px' }}
|
2021-06-10 07:09:25 -07:00
|
|
|
>
|
2021-06-10 18:07:32 -07:00
|
|
|
<Chart
|
2021-10-20 05:42:40 -07:00
|
|
|
title={t('total-deposits')}
|
2021-06-10 07:09:25 -07:00
|
|
|
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"
|
2021-06-10 07:09:25 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div
|
2022-01-06 18:35:48 -08:00
|
|
|
className="border border-th-bkg-3 relative p-4 rounded-md"
|
2021-10-07 04:34:26 -07:00
|
|
|
style={{ height: '330px' }}
|
2021-06-10 07:09:25 -07:00
|
|
|
>
|
2021-06-10 18:07:32 -07:00
|
|
|
<Chart
|
2021-10-20 05:42:40 -07:00
|
|
|
title={t('deposit-interest')}
|
2021-06-10 07:09:25 -07:00
|
|
|
xAxis="time"
|
2021-08-30 11:41:42 -07:00
|
|
|
yAxis="depositRate"
|
2021-06-10 07:09:25 -07:00
|
|
|
data={selectedStatsData}
|
|
|
|
labelFormat={(x) => `${(x * 100).toFixed(5)}%`}
|
2021-10-07 04:34:26 -07:00
|
|
|
tickFormat={(x) =>
|
|
|
|
(x * 100).toLocaleString(undefined, { maximumFractionDigits: 4 })
|
|
|
|
}
|
2021-06-10 18:07:32 -07:00
|
|
|
type="bar"
|
2021-06-10 07:09:25 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div
|
2022-01-06 18:35:48 -08:00
|
|
|
className="border border-th-bkg-3 relative md:mb-0 p-4 rounded-md"
|
2021-10-07 04:34:26 -07:00
|
|
|
style={{ height: '330px' }}
|
2021-06-10 07:09:25 -07:00
|
|
|
>
|
2021-06-10 18:07:32 -07:00
|
|
|
<Chart
|
2021-10-20 05:42:40 -07:00
|
|
|
title={t('total-borrows')}
|
2021-06-10 07:09:25 -07:00
|
|
|
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"
|
2021-06-10 07:09:25 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div
|
2022-01-06 18:35:48 -08:00
|
|
|
className="border border-th-bkg-3 relative p-4 rounded-md"
|
2021-10-07 04:34:26 -07:00
|
|
|
style={{ height: '330px' }}
|
2021-06-10 07:09:25 -07:00
|
|
|
>
|
2021-06-10 18:07:32 -07:00
|
|
|
<Chart
|
2021-10-20 05:42:40 -07:00
|
|
|
title={t('borrow-interest')}
|
2021-06-10 07:09:25 -07:00
|
|
|
xAxis="time"
|
2021-08-30 11:41:42 -07:00
|
|
|
yAxis="borrowRate"
|
2021-06-10 07:09:25 -07:00
|
|
|
data={selectedStatsData}
|
|
|
|
labelFormat={(x) => `${(x * 100).toFixed(5)}%`}
|
2021-10-07 04:34:26 -07:00
|
|
|
tickFormat={(x) =>
|
|
|
|
(x * 100).toLocaleString(undefined, { maximumFractionDigits: 4 })
|
|
|
|
}
|
2021-06-10 18:07:32 -07:00
|
|
|
type="bar"
|
2021-06-10 07:09:25 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-30 11:41:42 -07:00
|
|
|
</>
|
|
|
|
)
|
2021-06-10 07:09:25 -07:00
|
|
|
}
|