2022-09-01 10:33:29 -07:00
|
|
|
import {
|
|
|
|
HealthType,
|
|
|
|
toUiDecimalsForQuote,
|
|
|
|
} from '@blockworks-foundation/mango-v4'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
|
|
import AccountActions from './AccountActions'
|
2022-09-12 08:53:57 -07:00
|
|
|
import mangoStore, { PerformanceDataItem } from '@store/mangoStore'
|
2023-01-23 17:26:14 -08:00
|
|
|
import { formatNumericValue } from '../../utils/numbers'
|
2022-09-01 10:33:29 -07:00
|
|
|
import FlipNumbers from 'react-flip-numbers'
|
2022-10-10 14:15:35 -07:00
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
const SimpleAreaChart = dynamic(
|
|
|
|
() => import('@components/shared/SimpleAreaChart'),
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
2022-09-01 10:33:29 -07:00
|
|
|
import { COLORS } from '../../styles/colors'
|
|
|
|
import { useTheme } from 'next-themes'
|
|
|
|
import { IconButton } from '../shared/Button'
|
2022-09-06 21:36:35 -07:00
|
|
|
import {
|
|
|
|
ArrowsPointingOutIcon,
|
2023-01-15 21:13:34 -08:00
|
|
|
ChartBarIcon,
|
|
|
|
ClockIcon,
|
2022-09-06 21:36:35 -07:00
|
|
|
} from '@heroicons/react/20/solid'
|
2022-09-01 10:33:29 -07:00
|
|
|
import { Transition } from '@headlessui/react'
|
|
|
|
import AccountTabs from './AccountTabs'
|
|
|
|
import SheenLoader from '../shared/SheenLoader'
|
|
|
|
import AccountChart from './AccountChart'
|
2022-11-18 09:09:39 -08:00
|
|
|
import useMangoAccount from '../../hooks/useMangoAccount'
|
2022-10-05 22:11:28 -07:00
|
|
|
import Change from '../shared/Change'
|
2022-09-14 08:30:02 -07:00
|
|
|
import Tooltip from '@components/shared/Tooltip'
|
2022-12-20 01:13:24 -08:00
|
|
|
import {
|
|
|
|
ANIMATION_SETTINGS_KEY,
|
|
|
|
// IS_ONBOARDED_KEY
|
|
|
|
} from 'utils/constants'
|
2023-01-26 14:52:40 -08:00
|
|
|
// import { useWallet } from '@solana/wallet-adapter-react'
|
2022-09-21 21:25:24 -07:00
|
|
|
import useLocalStorageState from 'hooks/useLocalStorageState'
|
2022-12-20 01:13:24 -08:00
|
|
|
// import AccountOnboardingTour from '@components/tours/AccountOnboardingTour'
|
2022-11-20 16:50:25 -08:00
|
|
|
import dayjs from 'dayjs'
|
2022-11-24 18:39:14 -08:00
|
|
|
import { INITIAL_ANIMATION_SETTINGS } from '@components/settings/AnimationSettings'
|
2022-12-21 03:07:17 -08:00
|
|
|
import { useViewport } from 'hooks/useViewport'
|
|
|
|
import { breakpoints } from 'utils/theme'
|
2023-01-14 13:50:45 -08:00
|
|
|
import useMangoGroup from 'hooks/useMangoGroup'
|
2023-01-15 21:13:34 -08:00
|
|
|
import PnlHistoryModal from '@components/modals/PnlHistoryModal'
|
2023-01-23 17:26:14 -08:00
|
|
|
import FormatNumericValue from '@components/shared/FormatNumericValue'
|
2022-09-01 10:33:29 -07:00
|
|
|
|
|
|
|
const AccountPage = () => {
|
2023-01-16 20:59:51 -08:00
|
|
|
const { t } = useTranslation(['common', 'account'])
|
2023-01-26 14:52:40 -08:00
|
|
|
// const { connected } = useWallet()
|
2023-01-14 13:50:45 -08:00
|
|
|
const { group } = useMangoGroup()
|
2023-01-26 14:52:40 -08:00
|
|
|
const { mangoAccount, mangoAccountAddress, initialLoad } = useMangoAccount()
|
2023-01-03 14:20:00 -08:00
|
|
|
const actions = mangoStore.getState().actions
|
2023-01-15 21:13:34 -08:00
|
|
|
const performanceInitialLoad = mangoStore(
|
|
|
|
(s) => s.mangoAccount.performance.initialLoad
|
2022-09-01 10:33:29 -07:00
|
|
|
)
|
2023-01-15 21:13:34 -08:00
|
|
|
const performanceData = mangoStore((s) => s.mangoAccount.performance.data)
|
2022-09-01 10:33:29 -07:00
|
|
|
const totalInterestData = mangoStore(
|
2023-01-15 21:13:34 -08:00
|
|
|
(s) => s.mangoAccount.interestTotals.data
|
2022-09-01 10:33:29 -07:00
|
|
|
)
|
|
|
|
const [chartToShow, setChartToShow] = useState<
|
|
|
|
'account-value' | 'cumulative-interest-value' | 'pnl' | ''
|
|
|
|
>('')
|
|
|
|
const [oneDayPerformanceData, setOneDayPerformanceData] = useState<
|
|
|
|
PerformanceDataItem[]
|
|
|
|
>([])
|
|
|
|
const [showExpandChart, setShowExpandChart] = useState<boolean>(false)
|
2023-01-15 21:13:34 -08:00
|
|
|
const [showPnlHistory, setShowPnlHistory] = useState<boolean>(false)
|
2022-09-01 10:33:29 -07:00
|
|
|
const { theme } = useTheme()
|
2022-12-21 03:07:17 -08:00
|
|
|
const { width } = useViewport()
|
2023-01-06 02:43:07 -08:00
|
|
|
const isMobile = width ? width < breakpoints.md : false
|
2022-12-20 01:13:24 -08:00
|
|
|
// const tourSettings = mangoStore((s) => s.settings.tours)
|
|
|
|
// const [isOnBoarded] = useLocalStorageState(IS_ONBOARDED_KEY)
|
2022-11-23 18:30:20 -08:00
|
|
|
const [animationSettings] = useLocalStorageState(
|
|
|
|
ANIMATION_SETTINGS_KEY,
|
|
|
|
INITIAL_ANIMATION_SETTINGS
|
|
|
|
)
|
2022-09-01 10:33:29 -07:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-26 14:52:40 -08:00
|
|
|
if (mangoAccountAddress || (!initialLoad && !mangoAccountAddress)) {
|
2023-01-18 20:16:43 -08:00
|
|
|
const set = mangoStore.getState().set
|
|
|
|
set((s) => {
|
|
|
|
s.mangoAccount.performance.initialLoad = false
|
|
|
|
})
|
|
|
|
setOneDayPerformanceData([])
|
2023-01-05 20:01:03 -08:00
|
|
|
actions.fetchAccountPerformance(mangoAccountAddress, 1)
|
|
|
|
actions.fetchAccountInterestTotals(mangoAccountAddress)
|
2022-09-01 10:33:29 -07:00
|
|
|
}
|
2023-01-26 14:52:40 -08:00
|
|
|
}, [actions, initialLoad, mangoAccountAddress])
|
2022-09-01 10:33:29 -07:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-18 20:16:43 -08:00
|
|
|
if (
|
|
|
|
performanceData.length &&
|
|
|
|
performanceInitialLoad &&
|
|
|
|
!oneDayPerformanceData.length
|
|
|
|
) {
|
2022-09-01 10:33:29 -07:00
|
|
|
setOneDayPerformanceData(performanceData)
|
|
|
|
}
|
2023-01-18 20:16:43 -08:00
|
|
|
}, [performanceInitialLoad, oneDayPerformanceData, performanceData])
|
2022-09-01 10:33:29 -07:00
|
|
|
|
|
|
|
const onHoverMenu = (open: boolean, action: string) => {
|
|
|
|
if (
|
|
|
|
(!open && action === 'onMouseEnter') ||
|
|
|
|
(open && action === 'onMouseLeave')
|
|
|
|
) {
|
|
|
|
setShowExpandChart(!open)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleShowAccountValueChart = () => {
|
|
|
|
setChartToShow('account-value')
|
|
|
|
setShowExpandChart(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleHideChart = () => {
|
|
|
|
const set = mangoStore.getState().set
|
|
|
|
set((s) => {
|
2023-01-15 21:13:34 -08:00
|
|
|
s.mangoAccount.performance.data = oneDayPerformanceData
|
2022-09-01 10:33:29 -07:00
|
|
|
})
|
|
|
|
setChartToShow('')
|
|
|
|
}
|
|
|
|
|
2023-01-16 02:07:46 -08:00
|
|
|
const handleCloseDailyPnlModal = () => {
|
|
|
|
const set = mangoStore.getState().set
|
|
|
|
set((s) => {
|
|
|
|
s.mangoAccount.performance.data = oneDayPerformanceData
|
|
|
|
})
|
|
|
|
setShowPnlHistory(false)
|
|
|
|
}
|
|
|
|
|
2022-11-20 16:50:25 -08:00
|
|
|
const accountValue = useMemo(() => {
|
|
|
|
if (!group || !mangoAccount) return 0.0
|
2022-12-27 15:15:57 -08:00
|
|
|
return toUiDecimalsForQuote(mangoAccount.getEquity(group).toNumber())
|
2022-11-20 16:50:25 -08:00
|
|
|
}, [group, mangoAccount])
|
|
|
|
|
2022-12-30 12:39:05 -08:00
|
|
|
const leverage = useMemo(() => {
|
|
|
|
if (!group || !mangoAccount) return 0
|
|
|
|
const assetsValue = toUiDecimalsForQuote(
|
|
|
|
mangoAccount.getAssetsValue(group).toNumber()
|
|
|
|
)
|
|
|
|
|
|
|
|
if (isNaN(assetsValue / accountValue)) {
|
|
|
|
return 0
|
2023-01-11 15:03:11 -08:00
|
|
|
} else {
|
|
|
|
return Math.abs(1 - assetsValue / accountValue)
|
|
|
|
}
|
2022-12-30 12:39:05 -08:00
|
|
|
}, [mangoAccount, group, accountValue])
|
|
|
|
|
2023-01-18 20:16:43 -08:00
|
|
|
const [accountPnl, accountValueChange, oneDayPnlChange] = useMemo(() => {
|
2023-01-16 02:07:46 -08:00
|
|
|
if (
|
|
|
|
accountValue &&
|
|
|
|
oneDayPerformanceData.length &&
|
|
|
|
performanceData.length
|
|
|
|
) {
|
2023-01-18 20:16:43 -08:00
|
|
|
const accountPnl = performanceData[performanceData.length - 1].pnl
|
|
|
|
const accountValueChange =
|
|
|
|
accountValue - oneDayPerformanceData[0].account_equity
|
2022-11-19 03:28:06 -08:00
|
|
|
const startDayPnl = oneDayPerformanceData[0].pnl
|
2023-01-15 21:13:34 -08:00
|
|
|
const endDayPnl =
|
|
|
|
oneDayPerformanceData[oneDayPerformanceData.length - 1].pnl
|
2023-01-18 20:16:43 -08:00
|
|
|
const oneDayPnlChange = endDayPnl - startDayPnl
|
|
|
|
|
|
|
|
return [accountPnl, accountValueChange, oneDayPnlChange]
|
2022-10-04 22:12:52 -07:00
|
|
|
}
|
2023-01-18 20:16:43 -08:00
|
|
|
return [0, 0, 0]
|
|
|
|
}, [accountValue, oneDayPerformanceData, performanceData])
|
2022-10-04 22:12:52 -07:00
|
|
|
|
2022-09-01 10:33:29 -07:00
|
|
|
const interestTotalValue = useMemo(() => {
|
|
|
|
if (totalInterestData.length) {
|
|
|
|
return totalInterestData.reduce(
|
|
|
|
(a, c) => a + c.borrow_interest_usd + c.deposit_interest_usd,
|
|
|
|
0
|
|
|
|
)
|
|
|
|
}
|
2022-10-06 16:06:49 -07:00
|
|
|
return 0.0
|
2022-09-01 10:33:29 -07:00
|
|
|
}, [totalInterestData])
|
|
|
|
|
2022-10-05 03:16:32 -07:00
|
|
|
const oneDayInterestChange = useMemo(() => {
|
2023-01-18 20:16:43 -08:00
|
|
|
if (oneDayPerformanceData.length) {
|
2022-11-19 03:28:06 -08:00
|
|
|
const startDayInterest =
|
|
|
|
oneDayPerformanceData[0].borrow_interest_cumulative_usd +
|
|
|
|
oneDayPerformanceData[0].deposit_interest_cumulative_usd
|
|
|
|
|
|
|
|
const latest = oneDayPerformanceData.length - 1
|
|
|
|
|
|
|
|
const endDayInterest =
|
|
|
|
oneDayPerformanceData[latest].borrow_interest_cumulative_usd +
|
|
|
|
oneDayPerformanceData[latest].deposit_interest_cumulative_usd
|
|
|
|
|
|
|
|
return endDayInterest - startDayInterest
|
2022-10-05 03:16:32 -07:00
|
|
|
}
|
|
|
|
return 0.0
|
2023-01-18 20:16:43 -08:00
|
|
|
}, [oneDayPerformanceData])
|
2022-10-05 03:16:32 -07:00
|
|
|
|
2022-09-01 10:33:29 -07:00
|
|
|
const maintHealth = useMemo(() => {
|
2022-10-07 05:22:18 -07:00
|
|
|
return group && mangoAccount
|
|
|
|
? mangoAccount.getHealthRatioUi(group, HealthType.maint)
|
|
|
|
: 0
|
2022-10-07 13:02:11 -07:00
|
|
|
}, [mangoAccount, group])
|
2022-09-01 10:33:29 -07:00
|
|
|
|
2022-10-05 03:16:32 -07:00
|
|
|
const handleChartToShow = (
|
2022-10-06 05:08:29 -07:00
|
|
|
chartName: 'pnl' | 'cumulative-interest-value'
|
2022-10-05 03:16:32 -07:00
|
|
|
) => {
|
2022-10-06 05:08:29 -07:00
|
|
|
if (
|
|
|
|
(chartName === 'cumulative-interest-value' && interestTotalValue > 1) ||
|
|
|
|
interestTotalValue < -1
|
|
|
|
) {
|
|
|
|
setChartToShow(chartName)
|
|
|
|
}
|
|
|
|
if (chartName === 'pnl' && performanceData.length > 4) {
|
|
|
|
setChartToShow(chartName)
|
|
|
|
}
|
2022-10-03 15:45:46 -07:00
|
|
|
}
|
|
|
|
|
2022-11-20 16:50:25 -08:00
|
|
|
const latestAccountData = useMemo(() => {
|
|
|
|
if (!accountValue || !performanceData.length) return []
|
|
|
|
const latestIndex = performanceData.length - 1
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
account_equity: accountValue,
|
|
|
|
time: dayjs(Date.now()).toISOString(),
|
|
|
|
borrow_interest_cumulative_usd:
|
|
|
|
performanceData[latestIndex].borrow_interest_cumulative_usd,
|
|
|
|
deposit_interest_cumulative_usd:
|
|
|
|
performanceData[latestIndex].deposit_interest_cumulative_usd,
|
|
|
|
pnl: performanceData[latestIndex].pnl,
|
|
|
|
spot_value: performanceData[latestIndex].spot_value,
|
|
|
|
transfer_balance: performanceData[latestIndex].transfer_balance,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}, [accountValue, performanceData])
|
|
|
|
|
2022-09-01 10:33:29 -07:00
|
|
|
return !chartToShow ? (
|
|
|
|
<>
|
2022-12-29 16:31:13 -08:00
|
|
|
<div className="flex flex-col border-b-0 border-th-bkg-3 px-6 py-3 lg:flex-row lg:items-center lg:justify-between lg:border-b">
|
2023-01-06 02:43:07 -08:00
|
|
|
<div className="flex flex-col md:flex-row md:items-center md:space-x-6">
|
2022-09-21 21:25:24 -07:00
|
|
|
<div id="account-step-three">
|
2023-01-23 14:52:59 -08:00
|
|
|
<Tooltip
|
|
|
|
maxWidth="20rem"
|
|
|
|
placement="bottom-start"
|
|
|
|
content="The value of your assets (deposits) minus the value of your liabilities (borrows)."
|
|
|
|
delay={250}
|
|
|
|
>
|
|
|
|
<p className="tooltip-underline mb-2 text-base">
|
|
|
|
{t('account-value')}
|
|
|
|
</p>
|
|
|
|
</Tooltip>
|
2022-12-13 02:49:56 -08:00
|
|
|
<div className="mb-2 flex items-center font-display text-5xl text-th-fgd-1">
|
2023-01-23 14:52:59 -08:00
|
|
|
{animationSettings['number-scroll'] ? (
|
|
|
|
group && mangoAccount ? (
|
|
|
|
<FlipNumbers
|
|
|
|
height={48}
|
|
|
|
width={35}
|
|
|
|
play
|
|
|
|
delay={0.05}
|
|
|
|
duration={1}
|
2023-01-23 17:26:14 -08:00
|
|
|
numbers={formatNumericValue(accountValue, 2, true)}
|
2023-01-23 14:52:59 -08:00
|
|
|
/>
|
2022-11-23 18:30:20 -08:00
|
|
|
) : (
|
2023-01-23 14:52:59 -08:00
|
|
|
<FlipNumbers
|
|
|
|
height={48}
|
|
|
|
width={36}
|
|
|
|
play
|
|
|
|
delay={0.05}
|
|
|
|
duration={1}
|
|
|
|
numbers={'$0.00'}
|
|
|
|
/>
|
2022-11-23 18:30:20 -08:00
|
|
|
)
|
2022-09-01 10:33:29 -07:00
|
|
|
) : (
|
2023-01-23 17:26:14 -08:00
|
|
|
<FormatNumericValue
|
|
|
|
value={accountValue}
|
|
|
|
isUsd={true}
|
|
|
|
decimals={2}
|
|
|
|
/>
|
2022-09-01 10:33:29 -07:00
|
|
|
)}
|
|
|
|
</div>
|
2022-11-20 03:13:44 -08:00
|
|
|
<div className="flex items-center space-x-1.5">
|
2023-01-23 17:26:14 -08:00
|
|
|
<Change change={accountValueChange} prefix="$" />
|
2022-11-20 01:08:12 -08:00
|
|
|
<p className="text-th-fgd-4">{t('today')}</p>
|
|
|
|
</div>
|
2022-09-01 10:33:29 -07:00
|
|
|
</div>
|
2023-01-16 02:07:46 -08:00
|
|
|
{performanceInitialLoad ? (
|
2023-01-23 14:52:59 -08:00
|
|
|
oneDayPerformanceData.length ? (
|
2022-09-01 10:33:29 -07:00
|
|
|
<div
|
2023-01-22 16:34:52 -08:00
|
|
|
className="relative mt-4 flex h-40 items-end md:mt-0 md:h-24 md:w-48"
|
2022-09-01 10:33:29 -07:00
|
|
|
onMouseEnter={() =>
|
|
|
|
onHoverMenu(showExpandChart, 'onMouseEnter')
|
|
|
|
}
|
|
|
|
onMouseLeave={() =>
|
|
|
|
onHoverMenu(showExpandChart, 'onMouseLeave')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<SimpleAreaChart
|
|
|
|
color={
|
|
|
|
accountValueChange >= 0
|
2022-11-30 19:32:32 -08:00
|
|
|
? COLORS.UP[theme]
|
|
|
|
: COLORS.DOWN[theme]
|
2022-09-01 10:33:29 -07:00
|
|
|
}
|
2023-01-16 02:07:46 -08:00
|
|
|
data={oneDayPerformanceData.concat(latestAccountData)}
|
2022-09-01 10:33:29 -07:00
|
|
|
name="accountValue"
|
|
|
|
xKey="time"
|
|
|
|
yKey="account_equity"
|
|
|
|
/>
|
|
|
|
<Transition
|
|
|
|
appear={true}
|
|
|
|
className="absolute right-2 bottom-2"
|
2022-12-21 03:07:17 -08:00
|
|
|
show={showExpandChart || isMobile}
|
2022-09-01 10:33:29 -07:00
|
|
|
enter="transition ease-in duration-300"
|
|
|
|
enterFrom="opacity-0 scale-75"
|
|
|
|
enterTo="opacity-100 scale-100"
|
|
|
|
leave="transition ease-out duration-200"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
className="text-th-fgd-3"
|
|
|
|
hideBg
|
|
|
|
onClick={() => handleShowAccountValueChart()}
|
|
|
|
>
|
2022-09-06 21:36:35 -07:00
|
|
|
<ArrowsPointingOutIcon className="h-5 w-5" />
|
2022-09-01 10:33:29 -07:00
|
|
|
</IconButton>
|
|
|
|
</Transition>
|
|
|
|
</div>
|
|
|
|
) : null
|
2023-01-16 02:07:46 -08:00
|
|
|
) : mangoAccountAddress ? (
|
2023-01-06 02:43:07 -08:00
|
|
|
<SheenLoader className="mt-4 flex flex-1 md:mt-0">
|
|
|
|
<div className="h-40 w-full rounded-md bg-th-bkg-2 md:h-24 md:w-48" />
|
2022-09-01 10:33:29 -07:00
|
|
|
</SheenLoader>
|
2023-01-16 02:07:46 -08:00
|
|
|
) : null}
|
2022-09-01 10:33:29 -07:00
|
|
|
</div>
|
2022-12-29 16:31:13 -08:00
|
|
|
<div className="mt-6 mb-1 lg:mt-0 lg:mb-0">
|
2022-09-18 20:53:52 -07:00
|
|
|
<AccountActions />
|
|
|
|
</div>
|
2022-09-01 10:33:29 -07:00
|
|
|
</div>
|
2022-12-30 12:39:05 -08:00
|
|
|
<div className="grid grid-cols-5 border-b border-th-bkg-3">
|
2023-01-06 02:43:07 -08:00
|
|
|
<div className="col-span-5 flex border-t border-th-bkg-3 py-3 pl-6 lg:col-span-1 lg:border-t-0">
|
2022-09-21 21:25:24 -07:00
|
|
|
<div id="account-step-four">
|
2022-09-14 08:30:02 -07:00
|
|
|
<Tooltip
|
2022-09-19 20:12:34 -07:00
|
|
|
maxWidth="20rem"
|
2022-09-25 17:37:04 -07:00
|
|
|
placement="bottom-start"
|
2022-10-05 03:25:47 -07:00
|
|
|
delay={250}
|
2022-09-14 08:30:02 -07:00
|
|
|
content={
|
|
|
|
<div className="flex-col space-y-2 text-sm">
|
2022-09-19 20:12:34 -07:00
|
|
|
<p className="text-xs">
|
|
|
|
Health describes how close your account is to liquidation.
|
|
|
|
The lower your account health is the more likely you are to
|
|
|
|
get liquidated when prices fluctuate.
|
|
|
|
</p>
|
|
|
|
<p className="text-xs font-bold text-th-fgd-1">
|
|
|
|
Your account health is {maintHealth}%
|
|
|
|
</p>
|
|
|
|
<p className="text-xs">
|
|
|
|
<span className="font-bold text-th-fgd-1">Scenario:</span>{' '}
|
|
|
|
If the prices of all your liabilities increase by{' '}
|
2022-09-14 08:30:02 -07:00
|
|
|
{maintHealth}%, even for just a moment, some of your
|
|
|
|
liabilities will be liquidated.
|
2022-09-19 20:12:34 -07:00
|
|
|
</p>
|
|
|
|
<p className="text-xs">
|
|
|
|
<span className="font-bold text-th-fgd-1">Scenario:</span>{' '}
|
|
|
|
If the value of your total collateral decreases by{' '}
|
|
|
|
{((1 - 1 / ((maintHealth || 0) / 100 + 1)) * 100).toFixed(
|
|
|
|
2
|
|
|
|
)}
|
|
|
|
% , some of your liabilities will be liquidated.
|
|
|
|
</p>
|
|
|
|
<p className="text-xs">
|
2022-09-14 08:30:02 -07:00
|
|
|
These are examples. A combination of events can also lead to
|
|
|
|
liquidation.
|
2022-09-19 20:12:34 -07:00
|
|
|
</p>
|
2022-09-14 08:30:02 -07:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
2022-12-12 17:50:10 -08:00
|
|
|
<p className="tooltip-underline text-sm font-normal text-th-fgd-3 xl:text-base">
|
2022-10-04 21:47:50 -07:00
|
|
|
{t('health')}
|
|
|
|
</p>
|
2022-09-14 08:30:02 -07:00
|
|
|
</Tooltip>
|
2022-10-04 21:47:50 -07:00
|
|
|
<p className="mt-1 text-2xl font-bold text-th-fgd-1 lg:text-xl xl:text-2xl">
|
2022-09-14 08:30:02 -07:00
|
|
|
{maintHealth}%
|
|
|
|
</p>
|
2022-09-13 04:27:04 -07:00
|
|
|
</div>
|
2022-09-01 10:33:29 -07:00
|
|
|
</div>
|
2023-01-06 02:43:07 -08:00
|
|
|
<div className="col-span-5 flex border-t border-th-bkg-3 py-3 pl-6 lg:col-span-1 lg:border-l lg:border-t-0">
|
2022-09-21 21:25:24 -07:00
|
|
|
<div id="account-step-five">
|
2022-09-19 20:12:34 -07:00
|
|
|
<Tooltip
|
2023-01-16 20:59:51 -08:00
|
|
|
content={t('account:tooltip-free-collateral')}
|
2022-09-19 20:12:34 -07:00
|
|
|
maxWidth="20rem"
|
2022-10-06 05:08:29 -07:00
|
|
|
placement="bottom"
|
2022-10-05 03:25:47 -07:00
|
|
|
delay={250}
|
2022-09-19 20:12:34 -07:00
|
|
|
>
|
2022-10-04 21:47:50 -07:00
|
|
|
<p className="tooltip-underline text-sm text-th-fgd-3 xl:text-base">
|
2022-09-19 20:12:34 -07:00
|
|
|
{t('free-collateral')}
|
|
|
|
</p>
|
|
|
|
</Tooltip>
|
2022-10-04 21:47:50 -07:00
|
|
|
<p className="mt-1 mb-0.5 text-2xl font-bold text-th-fgd-1 lg:text-xl xl:text-2xl">
|
2023-01-23 17:26:14 -08:00
|
|
|
<FormatNumericValue
|
|
|
|
value={
|
|
|
|
group && mangoAccount
|
|
|
|
? toUiDecimalsForQuote(
|
|
|
|
mangoAccount.getCollateralValue(group)
|
|
|
|
)
|
|
|
|
: 0
|
|
|
|
}
|
|
|
|
decimals={2}
|
|
|
|
isUsd={true}
|
|
|
|
/>
|
2022-09-13 04:27:04 -07:00
|
|
|
</p>
|
2022-10-04 21:47:50 -07:00
|
|
|
<span className="text-xs font-normal text-th-fgd-4">
|
|
|
|
<Tooltip
|
2023-01-16 20:59:51 -08:00
|
|
|
content={t('account:tooltip-total-collateral')}
|
2022-10-04 21:47:50 -07:00
|
|
|
maxWidth="20rem"
|
2022-10-06 05:08:29 -07:00
|
|
|
placement="bottom"
|
2022-10-05 03:25:47 -07:00
|
|
|
delay={250}
|
2022-10-04 21:47:50 -07:00
|
|
|
>
|
2023-01-16 20:59:51 -08:00
|
|
|
<span className="tooltip-underline">{t('total')}</span>:
|
2022-10-05 03:25:47 -07:00
|
|
|
<span className="ml-1 font-mono text-th-fgd-2">
|
2023-01-23 17:26:14 -08:00
|
|
|
<FormatNumericValue
|
|
|
|
value={
|
|
|
|
group && mangoAccount
|
|
|
|
? toUiDecimalsForQuote(
|
|
|
|
mangoAccount.getAssetsValue(group, HealthType.init)
|
|
|
|
)
|
|
|
|
: 0
|
|
|
|
}
|
|
|
|
decimals={2}
|
|
|
|
isUsd={true}
|
|
|
|
/>
|
2022-10-04 21:47:50 -07:00
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
</span>
|
2022-09-13 04:27:04 -07:00
|
|
|
</div>
|
2022-09-01 10:33:29 -07:00
|
|
|
</div>
|
2022-12-30 12:39:05 -08:00
|
|
|
<div className="col-span-5 flex border-t border-th-bkg-3 py-3 pl-6 lg:col-span-1 lg:border-l lg:border-t-0">
|
2022-11-13 19:21:45 -08:00
|
|
|
<div id="account-step-six">
|
2022-10-04 21:47:50 -07:00
|
|
|
<Tooltip
|
2023-01-16 20:59:51 -08:00
|
|
|
content={t('account:tooltip-leverage')}
|
2022-10-04 21:47:50 -07:00
|
|
|
maxWidth="20rem"
|
2022-10-06 05:08:29 -07:00
|
|
|
placement="bottom"
|
2022-10-05 03:25:47 -07:00
|
|
|
delay={250}
|
2022-10-04 21:47:50 -07:00
|
|
|
>
|
|
|
|
<p className="tooltip-underline text-sm text-th-fgd-3 xl:text-base">
|
|
|
|
{t('leverage')}
|
|
|
|
</p>
|
|
|
|
</Tooltip>
|
|
|
|
<p className="mt-1 text-2xl font-bold text-th-fgd-1 lg:text-xl xl:text-2xl">
|
2023-01-23 19:04:05 -08:00
|
|
|
<FormatNumericValue value={leverage} decimals={2} roundUp />x
|
2022-10-04 21:47:50 -07:00
|
|
|
</p>
|
2022-09-13 04:27:04 -07:00
|
|
|
</div>
|
2022-12-30 12:39:05 -08:00
|
|
|
</div>
|
2023-01-15 21:13:34 -08:00
|
|
|
<div className="col-span-5 border-t border-th-bkg-3 py-3 pl-6 pr-4 lg:col-span-1 lg:border-l lg:border-t-0">
|
2022-11-13 19:21:45 -08:00
|
|
|
<div id="account-step-seven" className="flex flex-col items-start">
|
2023-01-15 21:13:34 -08:00
|
|
|
<div className="flex w-full items-center justify-between">
|
2023-01-23 14:52:59 -08:00
|
|
|
<Tooltip
|
|
|
|
content={t('account:tooltip-pnl')}
|
|
|
|
placement="bottom"
|
|
|
|
delay={250}
|
|
|
|
>
|
|
|
|
<p className="tooltip-underline inline text-sm text-th-fgd-3 xl:text-base">
|
|
|
|
{t('pnl')}
|
|
|
|
</p>
|
|
|
|
</Tooltip>
|
2023-01-15 21:13:34 -08:00
|
|
|
{mangoAccountAddress ? (
|
|
|
|
<div className="flex items-center space-x-3">
|
|
|
|
{performanceData.length > 4 ? (
|
2023-01-16 20:59:51 -08:00
|
|
|
<Tooltip content={t('account:pnl-chart')} delay={250}>
|
2023-01-15 21:13:34 -08:00
|
|
|
<IconButton
|
|
|
|
className="text-th-fgd-3"
|
|
|
|
hideBg
|
|
|
|
onClick={() => handleChartToShow('pnl')}
|
|
|
|
>
|
|
|
|
<ChartBarIcon className="h-5 w-5" />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
) : null}
|
2023-01-16 20:59:51 -08:00
|
|
|
<Tooltip content={t('account:pnl-history')} delay={250}>
|
2023-01-15 21:13:34 -08:00
|
|
|
<IconButton
|
|
|
|
className="text-th-fgd-3"
|
|
|
|
hideBg
|
|
|
|
onClick={() => setShowPnlHistory(true)}
|
|
|
|
>
|
|
|
|
<ClockIcon className="h-5 w-5" />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2022-10-06 05:08:29 -07:00
|
|
|
<p className="mt-1 mb-0.5 text-left text-2xl font-bold text-th-fgd-1 lg:text-xl xl:text-2xl">
|
2023-01-23 17:26:14 -08:00
|
|
|
<FormatNumericValue
|
|
|
|
value={accountPnl}
|
|
|
|
decimals={2}
|
|
|
|
isUsd={true}
|
|
|
|
/>
|
2022-09-01 10:33:29 -07:00
|
|
|
</p>
|
2022-11-19 03:28:06 -08:00
|
|
|
<div className="flex space-x-1">
|
2023-01-23 17:26:14 -08:00
|
|
|
<Change change={oneDayPnlChange} prefix="$" size="small" />
|
2022-11-19 03:28:06 -08:00
|
|
|
<p className="text-xs text-th-fgd-4">{t('today')}</p>
|
|
|
|
</div>
|
2022-09-01 10:33:29 -07:00
|
|
|
</div>
|
2023-01-15 21:13:34 -08:00
|
|
|
</div>
|
2023-01-16 02:07:46 -08:00
|
|
|
<div className="col-span-5 border-t border-th-bkg-3 py-3 pl-6 pr-4 text-left lg:col-span-1 lg:border-l lg:border-t-0">
|
2022-11-13 19:21:45 -08:00
|
|
|
<div id="account-step-eight">
|
2023-01-16 02:07:46 -08:00
|
|
|
<div className="flex w-full items-center justify-between">
|
|
|
|
<Tooltip
|
2023-01-16 20:59:51 -08:00
|
|
|
content={t('account:tooltip-total-interest')}
|
2023-01-16 02:07:46 -08:00
|
|
|
maxWidth="20rem"
|
|
|
|
placement="bottom-end"
|
|
|
|
delay={250}
|
|
|
|
>
|
|
|
|
<p className="tooltip-underline text-sm text-th-fgd-3 xl:text-base">
|
|
|
|
{t('total-interest-earned')}
|
|
|
|
</p>
|
|
|
|
</Tooltip>
|
|
|
|
{interestTotalValue > 1 || interestTotalValue < -1 ? (
|
|
|
|
<Tooltip content="Cumulative Interest Chart" delay={250}>
|
|
|
|
<IconButton
|
|
|
|
className="text-th-fgd-3"
|
|
|
|
hideBg
|
|
|
|
onClick={() =>
|
|
|
|
handleChartToShow('cumulative-interest-value')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ChartBarIcon className="h-5 w-5" />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2022-10-06 05:08:29 -07:00
|
|
|
<p className="mt-1 mb-0.5 text-2xl font-bold text-th-fgd-1 lg:text-xl xl:text-2xl">
|
2023-01-23 17:26:14 -08:00
|
|
|
<FormatNumericValue
|
|
|
|
value={interestTotalValue}
|
|
|
|
decimals={2}
|
|
|
|
isUsd={true}
|
|
|
|
/>
|
2022-09-01 10:33:29 -07:00
|
|
|
</p>
|
2022-11-19 03:28:06 -08:00
|
|
|
<div className="flex space-x-1">
|
2023-01-23 17:26:14 -08:00
|
|
|
<Change change={oneDayInterestChange} prefix="$" size="small" />
|
2022-11-19 03:28:06 -08:00
|
|
|
<p className="text-xs text-th-fgd-4">{t('today')}</p>
|
|
|
|
</div>
|
2022-09-01 10:33:29 -07:00
|
|
|
</div>
|
2023-01-16 02:07:46 -08:00
|
|
|
</div>
|
2022-09-01 10:33:29 -07:00
|
|
|
</div>
|
2022-09-18 20:53:52 -07:00
|
|
|
<AccountTabs />
|
2022-12-20 01:13:24 -08:00
|
|
|
{/* {!tourSettings?.account_tour_seen && isOnBoarded && connected ? (
|
2022-09-21 21:25:24 -07:00
|
|
|
<AccountOnboardingTour />
|
2022-12-20 01:13:24 -08:00
|
|
|
) : null} */}
|
2023-01-15 21:13:34 -08:00
|
|
|
{showPnlHistory ? (
|
|
|
|
<PnlHistoryModal
|
|
|
|
pnlChangeToday={oneDayPnlChange}
|
|
|
|
isOpen={showPnlHistory}
|
2023-01-16 02:07:46 -08:00
|
|
|
onClose={handleCloseDailyPnlModal}
|
2023-01-15 21:13:34 -08:00
|
|
|
/>
|
|
|
|
) : null}
|
2022-09-01 10:33:29 -07:00
|
|
|
</>
|
|
|
|
) : (
|
2023-01-08 20:58:01 -08:00
|
|
|
<div className="p-6 pb-0">
|
2022-09-19 16:57:58 -07:00
|
|
|
{chartToShow === 'account-value' ? (
|
|
|
|
<AccountChart
|
|
|
|
chartToShow="account-value"
|
|
|
|
hideChart={handleHideChart}
|
2023-01-15 21:13:34 -08:00
|
|
|
mangoAccountAddress={mangoAccountAddress}
|
2022-09-19 16:57:58 -07:00
|
|
|
yKey="account_equity"
|
|
|
|
/>
|
|
|
|
) : chartToShow === 'pnl' ? (
|
|
|
|
<AccountChart
|
|
|
|
chartToShow="pnl"
|
|
|
|
hideChart={handleHideChart}
|
2023-01-15 21:13:34 -08:00
|
|
|
mangoAccountAddress={mangoAccountAddress}
|
2022-09-19 16:57:58 -07:00
|
|
|
yKey="pnl"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<AccountChart
|
|
|
|
chartToShow="cumulative-interest-value"
|
|
|
|
hideChart={handleHideChart}
|
2023-01-15 21:13:34 -08:00
|
|
|
mangoAccountAddress={mangoAccountAddress}
|
2022-09-19 16:57:58 -07:00
|
|
|
yKey="interest_value"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-09-01 10:33:29 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountPage
|