diff --git a/common/calculate.ts b/common/calculate.ts index d22f507f..43b04af8 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -131,9 +131,13 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { let loan = 0 let saleValue = 0 let redeemed = 0 + const totalShares: { [outcome: string]: number } = {} for (const bet of yourBets) { - const { isSold, sale, amount, loanAmount, isRedemption } = bet + const { isSold, sale, amount, loanAmount, isRedemption, shares, outcome } = + bet + totalShares[outcome] = (totalShares[outcome] ?? 0) + shares + if (isSold) { totalInvested += amount } else if (sale) { @@ -165,6 +169,7 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { netPayout, profit, profitPercent, + totalShares, } } @@ -175,6 +180,7 @@ export function getContractBetNullMetrics() { netPayout: 0, profit: 0, profitPercent: 0, + totalShares: {} as { [outcome: string]: number }, } } diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index c979899f..9ec28b14 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -125,13 +125,13 @@ export function BetsList(props: { user: User }) { .filter((c) => { if (filter === 'all') return true - const metrics = contractsMetrics[c.id] + const { totalShares } = contractsMetrics[c.id] + const hasSoldAll = Object.values(totalShares).every( + (shares) => shares === 0 + ) - // Filter for contracts you sold out of. - if (filter === 'sold') return metrics.payout === 0 - - // Filter for contracts where you currently have shares. - return metrics.payout > 0 + if (filter === 'sold') return hasSoldAll + return !hasSoldAll }) const [settled, unsettled] = partition(