From 9a97da72d8e3dbcf80ca23860d3631512b1027ca Mon Sep 17 00:00:00 2001 From: James Grugett Date: Tue, 21 Jun 2022 10:14:53 -0500 Subject: [PATCH] Don't show sell button if you have sold all your shares --- common/calculate.ts | 6 ++++++ web/components/bets-list.tsx | 12 +++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/calculate.ts b/common/calculate.ts index b7d79f2f..a0574c10 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -142,6 +142,10 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { const profit = payout + saleValue + redeemed - totalInvested const profitPercent = (profit / totalInvested) * 100 + const hasShares = Object.values(totalShares).some( + (shares) => shares > 0 + ) + return { invested: Math.max(0, currentInvested), payout, @@ -149,6 +153,7 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { profit, profitPercent, totalShares, + hasShares, } } @@ -160,6 +165,7 @@ export function getContractBetNullMetrics() { profit: 0, profitPercent: 0, totalShares: {} as { [outcome: string]: number }, + hasShares: false, } } diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index 95fa6e21..f41f89b6 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -129,13 +129,10 @@ export function BetsList(props: { user: User; hideBetsBefore?: number }) { .filter((c) => { if (filter === 'all') return true - const { totalShares } = contractsMetrics[c.id] - const hasSoldAll = Object.values(totalShares).every( - (shares) => shares === 0 - ) + const { hasShares } = contractsMetrics[c.id] - if (filter === 'sold') return hasSoldAll - return !hasSoldAll + if (filter === 'sold') return !hasShares + return hasShares }) const unsettled = contracts.filter( @@ -373,6 +370,7 @@ export function BetsSummary(props: { const isClosed = closeTime && Date.now() > closeTime const bets = props.bets.filter((b) => !b.isAnte) + const { hasShares } = getContractBetMetrics(contract, bets) const excludeSalesAndAntes = bets.filter( (b) => !b.isAnte && !b.isSold && !b.sale @@ -448,7 +446,7 @@ export function BetsSummary(props: { isBinary && !isClosed && !resolution && - invested > 0 && + hasShares && user && ( <>