import { useMemo, useState } from 'react' import AccountActions from './AccountActions' import useMangoGroup from 'hooks/useMangoGroup' import useMangoAccount from 'hooks/useMangoAccount' import { toUiDecimalsForQuote } from '@blockworks-foundation/mango-v4' import useAccountPerformanceData from 'hooks/useAccountPerformanceData' import dayjs from 'dayjs' import AccountHeroStats from './AccountHeroStats' import { useTranslation } from 'react-i18next' import Explore from '@components/explore/Explore' import DetailedAreaOrBarChart from '@components/shared/DetailedAreaOrBarChart' import { formatYAxis } from 'utils/formatting' import { useWallet } from '@solana/wallet-adapter-react' import ConnectEmptyState from '@components/shared/ConnectEmptyState' import CreateAccountModal from '@components/modals/CreateAccountModal' import { FaceSmileIcon } from '@heroicons/react/20/solid' import Button from '@components/shared/Button' const EMPTY_STATE_WRAPPER_CLASSES = 'flex h-[180px] flex-col justify-center pb-4 md:h-full' const DEFAULT_CHART_DATA = [ { account_equity: 0, time: dayjs().subtract(1, 'hour').toISOString(), borrow_interest_cumulative_usd: 0, deposit_interest_cumulative_usd: 0, pnl: 0, spot_value: 0, transfer_balance: 0, }, { account_equity: 0, time: dayjs().toISOString(), borrow_interest_cumulative_usd: 0, deposit_interest_cumulative_usd: 0, pnl: 0, spot_value: 0, transfer_balance: 0, }, ] const AccountOverview = () => { const { t } = useTranslation(['common', 'governance']) const { group } = useMangoGroup() const { mangoAccount, initialLoad } = useMangoAccount() const { connected } = useWallet() const { performanceData, loadingPerformanceData } = useAccountPerformanceData() const [daysToShow, setDaysToShow] = useState('1') const [showCreateAccountModal, setShowCreateAccountModal] = useState(false) const accountValue = useMemo(() => { if (!group || !mangoAccount) return 0 return toUiDecimalsForQuote(mangoAccount.getEquity(group).toNumber()) }, [group, mangoAccount]) const latestAccountData = useMemo(() => { if (!performanceData || !performanceData?.length) return [] const latestDataItem = performanceData[performanceData.length - 1] return [ { account_equity: accountValue, time: dayjs().toISOString(), borrow_interest_cumulative_usd: latestDataItem.borrow_interest_cumulative_usd, deposit_interest_cumulative_usd: latestDataItem.deposit_interest_cumulative_usd, pnl: latestDataItem.pnl, spot_value: latestDataItem.spot_value, transfer_balance: latestDataItem.transfer_balance, }, ] }, [accountValue, performanceData]) const chartData = useMemo(() => { if (performanceData && performanceData?.length) return performanceData.concat(latestAccountData) if (!latestAccountData.length) { return DEFAULT_CHART_DATA } }, [latestAccountData, performanceData]) return ( <>
{mangoAccount || (connected && initialLoad) ? (
`$${formatYAxis(x)}`} title={t('account-value')} xKey="time" yKey="account_equity" isPrivate />
) : connected ? (

Create a Mango Account to get started

) : (
)}
{showCreateAccountModal ? ( setShowCreateAccountModal(false)} /> ) : null} ) } export default AccountOverview