Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/ui/views/Dashboard/components/DashboardPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const DashboardPanel: React.FC<{ onSettingClick?(): void }> = ({
const { t } = useTranslation();
const history = useHistory();
usePerpsDefaultAccount();
const { perpsPositionInfo, isFetching } = usePerpsHomePnl();
const { perpsPositionInfo, isFetching, positionPnl } = usePerpsHomePnl();
// useCheckBridgePendingItem();

const [badgeModalVisible, setBadgeModalVisible] = useState(false);
Expand Down Expand Up @@ -392,14 +392,25 @@ export const DashboardPanel: React.FC<{ onSettingClick?(): void }> = ({
/>
</div>
) : perpsPositionInfo?.assetPositions?.length ? (
// <div
// className={clsx(
// 'absolute bottom-[6px] text-[11px] leading-[13px] font-medium text-r-blue-default'
// )}
// >
// {t('page.dashboard.home.panel.perpsPositions', {
// count: perpsPositionInfo?.assetPositions?.length,
// })}
// </div>
<div
className={clsx(
'absolute bottom-[6px] text-[11px] leading-[13px] font-medium text-r-blue-default'
'absolute bottom-[6px] text-[11px] leading-[13px] font-medium',
positionPnl && positionPnl > 0
? 'text-r-green-default'
: 'text-r-red-default'
)}
>
{t('page.dashboard.home.panel.perpsPositions', {
count: perpsPositionInfo?.assetPositions?.length,
})}
{positionPnl && positionPnl >= 0 ? '+' : '-'}$
{splitNumberByStep(Math.abs(positionPnl || 0).toFixed(2))}
</div>
) : +(perpsPositionInfo?.marginSummary?.accountValue || '') ? (
<div
Expand Down
8 changes: 8 additions & 0 deletions src/ui/views/Perps/hooks/usePerpsHomePnl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useRabbySelector } from '@/ui/store';
import { usePerpsClearHouseState } from './usePerpsClearingHouseState';
import { useMemo } from 'react';

export const usePerpsHomePnl = () => {
const perpsState = useRabbySelector((state) => state.perps);
Expand All @@ -9,8 +10,15 @@ export const usePerpsHomePnl = () => {
address: perpsAccount?.address,
});

const pnl = useMemo(() => {
return data?.assetPositions.reduce((acc, item) => {
return acc + Number(item.position.unrealizedPnl);
}, 0);
}, [data]);

return {
perpsPositionInfo: data,
isFetching,
positionPnl: pnl,
};
};
Loading