fix pnl change today

This commit is contained in:
saml33 2023-07-07 16:00:17 +10:00
parent fc03c5705b
commit aa7b9fc45b
1 changed files with 15 additions and 17 deletions

View File

@ -370,24 +370,22 @@ const AccountPage = () => {
} }
}, [mangoAccount, group, accountValue]) }, [mangoAccount, group, accountValue])
const [accountValueChange, oneDayPnlChange] = useMemo(() => { const [accountValueChange, rollingDailyPnlChange, pnlChangeToday] =
if ( useMemo(() => {
accountValue && if (!accountValue || !accountPnl || !oneDayPerformanceData.length)
oneDayPerformanceData.length && return [0, 0, 0]
performanceData &&
performanceData.length
) {
const accountValueChange = const accountValueChange =
accountValue - oneDayPerformanceData[0].account_equity accountValue - oneDayPerformanceData[0].account_equity
const startDayPnl = oneDayPerformanceData[0].pnl const startHour = oneDayPerformanceData.find((item) => {
const endDayPnl = const itemHour = new Date(item.time).getHours()
oneDayPerformanceData[oneDayPerformanceData.length - 1].pnl return itemHour === 0
const oneDayPnlChange = endDayPnl - startDayPnl })
const startDayPnl = startHour?.pnl
const rollingDailyPnlChange = accountPnl - oneDayPerformanceData[0].pnl
const pnlChangeToday = startDayPnl ? accountPnl - startDayPnl : 0
return [accountValueChange, oneDayPnlChange] return [accountValueChange, rollingDailyPnlChange, pnlChangeToday]
} }, [accountPnl, accountValue, oneDayPerformanceData])
return [0, 0]
}, [accountValue, oneDayPerformanceData, performanceData])
const interestTotalValue = useMemo(() => { const interestTotalValue = useMemo(() => {
if (totalInterestData.length) { if (totalInterestData.length) {
@ -761,7 +759,7 @@ const AccountPage = () => {
/> />
</p> </p>
<div className="flex space-x-1.5"> <div className="flex space-x-1.5">
<Change change={oneDayPnlChange} prefix="$" size="small" /> <Change change={rollingDailyPnlChange} prefix="$" size="small" />
<p className="text-xs text-th-fgd-4">{t('rolling-change')}</p> <p className="text-xs text-th-fgd-4">{t('rolling-change')}</p>
</div> </div>
</div> </div>
@ -910,7 +908,7 @@ const AccountPage = () => {
<PnlHistoryModal <PnlHistoryModal
loading={performanceLoading} loading={performanceLoading}
performanceData={performanceData} performanceData={performanceData}
pnlChangeToday={oneDayPnlChange} pnlChangeToday={pnlChangeToday}
isOpen={showPnlHistory} isOpen={showPnlHistory}
onClose={handleCloseDailyPnlModal} onClose={handleCloseDailyPnlModal}
/> />