From d7793841d14fdde6cd406244de59ce8630858b4e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 27 Aug 2022 17:13:29 -0500 Subject: [PATCH] Fix NaN invested (floating point error) --- common/calculate.ts | 2 ++ web/components/bets-list.tsx | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common/calculate.ts b/common/calculate.ts index 758fc3cd..da4ce13a 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -140,6 +140,8 @@ function getCpmmInvested(yourBets: Bet[]) { const sortedBets = sortBy(yourBets, 'createdTime') for (const bet of sortedBets) { const { outcome, shares, amount } = bet + if (floatingEqual(shares, 0)) continue + if (amount > 0) { totalShares[outcome] = (totalShares[outcome] ?? 0) + shares totalSpent[outcome] = (totalSpent[outcome] ?? 0) + amount diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index 1a31a900..4ac873b4 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -405,7 +405,8 @@ export function BetsSummary(props: { const isClosed = closeTime && Date.now() > closeTime const bets = props.bets.filter((b) => !b.isAnte) - const { hasShares } = getContractBetMetrics(contract, bets) + const { hasShares, invested, profitPercent, payout, profit, totalShares } = + getContractBetMetrics(contract, bets) const excludeSalesAndAntes = bets.filter( (b) => !b.isAnte && !b.isSold && !b.sale @@ -416,8 +417,6 @@ export function BetsSummary(props: { const noWinnings = sumBy(excludeSalesAndAntes, (bet) => calculatePayout(contract, bet, 'NO') ) - const { invested, profitPercent, payout, profit, totalShares } = - getContractBetMetrics(contract, bets) const [showSellModal, setShowSellModal] = useState(false) const user = useUser()