From d10bb3dd7879c9cb232788f21af753b294fa91f7 Mon Sep 17 00:00:00 2001 From: Thigazhezhilan J Date: Tue, 7 Apr 2026 09:51:52 +0530 Subject: [PATCH] Fix live portfolio summary for sold positions --- src/components/landing/PortfolioSection.tsx | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/landing/PortfolioSection.tsx b/src/components/landing/PortfolioSection.tsx index d7051951..e3d3e3bb 100644 --- a/src/components/landing/PortfolioSection.tsx +++ b/src/components/landing/PortfolioSection.tsx @@ -187,6 +187,14 @@ function getEffectiveQuantity(item: any) { return firstNumber(item?.effective_quantity, getSettledQuantity(item) + getT1Quantity(item)); } +function getNetQuantity(item: any) { + const parsed = Number(item?.net_quantity); + if (Number.isFinite(parsed)) { + return parsed; + } + return getEffectiveQuantity(item); +} + function getAveragePrice(item: any) { return firstNumber(item?.average_price, item?.avg_price); } @@ -198,16 +206,20 @@ function getLastPrice(item: any) { function getDisplayPnl(item: any) { return firstNumber( item?.display_pnl, - getEffectiveQuantity(item) * (getLastPrice(item) - getAveragePrice(item)), + getNetQuantity(item) * (getLastPrice(item) - getAveragePrice(item)), ); } function getHoldingValue(item: any) { + const netQuantity = getNetQuantity(item); + if (Number.isFinite(Number(item?.net_quantity)) && netQuantity <= 0) { + return 0; + } const brokerValue = Number(item?.holding_value); if (Number.isFinite(brokerValue) && brokerValue >= 0) { return brokerValue; } - return Math.abs(getEffectiveQuantity(item)) * Math.abs(getLastPrice(item)); + return Math.max(netQuantity, 0) * Math.abs(getLastPrice(item)); } function getPortfolioItemKey(item: any, idx: number) { @@ -216,7 +228,9 @@ function getPortfolioItemKey(item: any, idx: number) { function renderPortfolioRows(items: any[]) { return items.map((item, idx) => { - const qty = getEffectiveQuantity(item); + const qty = Number.isFinite(Number(item?.net_quantity)) + ? getNetQuantity(item) + : getEffectiveQuantity(item); const settledQty = getSettledQuantity(item); const t1Qty = getT1Quantity(item); const avg = getAveragePrice(item); @@ -730,7 +744,7 @@ export default function PortfolioSection() { [holdings], ); const activePositionCount = useMemo( - () => positions.filter((item) => getEffectiveQuantity(item) !== 0).length, + () => positions.filter((item) => getNetQuantity(item) !== 0).length, [positions], );