mango-v4-ui/components/shared/PnlTooltipContent.tsx

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-07-03 05:29:10 -07:00
import { useTranslation } from 'next-i18next'
import { formatCurrencyValue } from 'utils/numbers'
2023-08-09 20:29:17 -07:00
import FormatNumericValue from './FormatNumericValue'
2023-07-03 05:29:10 -07:00
2023-08-09 21:45:30 -07:00
const getPnlColor = (pnl: number) => {
return pnl < 0 ? 'text-th-down' : pnl > 0 ? 'text-th-up' : 'text-th-fgd-3'
}
2023-07-03 05:29:10 -07:00
const PnlTooltipContent = ({
unrealizedPnl,
realizedPnl,
totalPnl,
unsettledPnl,
2023-08-09 20:29:17 -07:00
roe,
2023-07-03 05:29:10 -07:00
}: {
unrealizedPnl: number
realizedPnl: number
totalPnl: number
unsettledPnl: number
2023-08-09 20:29:17 -07:00
roe: number
2023-07-03 05:29:10 -07:00
}) => {
const { t } = useTranslation(['common', 'trade'])
return (
2023-08-09 21:45:30 -07:00
<div className="w-44">
<div className="mb-3 space-y-1">
2023-07-03 05:29:10 -07:00
<div className="flex justify-between">
<p className="mr-3">{t('trade:unrealized-pnl')}</p>
2023-08-09 21:45:30 -07:00
<span className={`font-mono ${getPnlColor(unrealizedPnl)}`}>
2023-07-03 05:29:10 -07:00
{formatCurrencyValue(unrealizedPnl, 2)}
</span>
</div>
<div className="flex justify-between border-b border-th-bkg-4 pb-3">
2023-07-03 05:29:10 -07:00
<p className="mr-3">{t('trade:realized-pnl')}</p>
2023-08-09 21:45:30 -07:00
<span className={`font-mono ${getPnlColor(realizedPnl)}`}>
2023-07-03 05:29:10 -07:00
{formatCurrencyValue(realizedPnl, 2)}
</span>
</div>
2023-08-09 21:45:30 -07:00
<div className="flex justify-between pt-1.5">
2023-07-03 05:29:10 -07:00
<p className="mr-3">{t('trade:total-pnl')}</p>
2023-08-09 21:45:30 -07:00
<span className={`font-mono ${getPnlColor(totalPnl)}`}>
2023-07-03 05:29:10 -07:00
{formatCurrencyValue(totalPnl, 2)}
</span>
</div>
<div className="flex justify-between border-b border-th-bkg-4 pb-3">
2023-08-09 20:29:17 -07:00
<p className="mr-3">{t('trade:return-on-equity')}</p>
2023-08-09 21:45:30 -07:00
<span className={`font-mono ${getPnlColor(roe)}`}>
2023-08-09 20:29:17 -07:00
<FormatNumericValue classNames="text-xs" value={roe} decimals={2} />
2023-08-09 21:45:30 -07:00
%
</span>
</div>
<div className="flex justify-between pt-1.5">
<p className="mr-3">
{t('trade:unsettled')} {t('pnl')}
</p>
<span className={`font-mono ${getPnlColor(unsettledPnl)}`}>
{formatCurrencyValue(unsettledPnl, 2)}
2023-08-09 20:29:17 -07:00
</span>
</div>
2023-07-03 05:29:10 -07:00
</div>
<a
href="https://docs.mango.markets/mango-markets/settle-pnl"
target="_blank"
rel="noopener noreferrer"
>
{t('learn-more')}
</a>
2023-08-09 21:45:30 -07:00
</div>
2023-07-03 05:29:10 -07:00
)
}
export default PnlTooltipContent