2022-08-14 22:43:15 -07:00
|
|
|
import { MangoAccount } from '@blockworks-foundation/mango-v4'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import { useState } from 'react'
|
2022-09-12 08:53:57 -07:00
|
|
|
import mangoStore from '@store/mangoStore'
|
2022-10-10 14:15:35 -07:00
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
const DetailedAreaChart = dynamic(
|
|
|
|
() => import('@components/shared/DetailedAreaChart'),
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
2022-08-14 22:43:15 -07:00
|
|
|
|
2022-08-15 17:16:21 -07:00
|
|
|
const AccountChart = ({
|
|
|
|
chartToShow,
|
2022-08-14 22:43:15 -07:00
|
|
|
data,
|
|
|
|
hideChart,
|
|
|
|
mangoAccount,
|
2022-08-15 17:16:21 -07:00
|
|
|
yKey,
|
2022-08-14 22:43:15 -07:00
|
|
|
}: {
|
2022-08-15 17:16:21 -07:00
|
|
|
chartToShow: string
|
|
|
|
data: Array<any>
|
2022-08-14 22:43:15 -07:00
|
|
|
hideChart: () => void
|
|
|
|
mangoAccount: MangoAccount
|
2022-08-15 17:16:21 -07:00
|
|
|
yKey: string
|
2022-08-14 22:43:15 -07:00
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation('common')
|
|
|
|
const actions = mangoStore((s) => s.actions)
|
|
|
|
const [daysToShow, setDaysToShow] = useState<number>(1)
|
|
|
|
const loading = mangoStore((s) => s.mangoAccount.stats.performance.loading)
|
|
|
|
|
2022-09-07 23:25:32 -07:00
|
|
|
const handleDaysToShow = async (days: number) => {
|
|
|
|
await actions.fetchAccountPerformance(
|
|
|
|
mangoAccount.publicKey.toString(),
|
|
|
|
days
|
|
|
|
)
|
2022-08-14 22:43:15 -07:00
|
|
|
setDaysToShow(days)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DetailedAreaChart
|
2022-08-15 17:16:21 -07:00
|
|
|
data={data}
|
2022-08-14 22:43:15 -07:00
|
|
|
daysToShow={daysToShow}
|
|
|
|
hideChart={hideChart}
|
|
|
|
loading={loading}
|
|
|
|
setDaysToShow={handleDaysToShow}
|
|
|
|
tickFormat={(x) => `$${x.toFixed(2)}`}
|
2022-08-15 17:16:21 -07:00
|
|
|
title={t(chartToShow)}
|
2022-08-14 22:43:15 -07:00
|
|
|
xKey="time"
|
2022-08-15 17:16:21 -07:00
|
|
|
yKey={yKey}
|
2022-08-14 22:43:15 -07:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-08-15 17:16:21 -07:00
|
|
|
export default AccountChart
|