Don't show sell button if you have sold all your shares

This commit is contained in:
James Grugett 2022-06-21 10:14:53 -05:00
parent d4f2a81735
commit 9a97da72d8
2 changed files with 11 additions and 7 deletions

View File

@ -142,6 +142,10 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
const profit = payout + saleValue + redeemed - totalInvested const profit = payout + saleValue + redeemed - totalInvested
const profitPercent = (profit / totalInvested) * 100 const profitPercent = (profit / totalInvested) * 100
const hasShares = Object.values(totalShares).some(
(shares) => shares > 0
)
return { return {
invested: Math.max(0, currentInvested), invested: Math.max(0, currentInvested),
payout, payout,
@ -149,6 +153,7 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
profit, profit,
profitPercent, profitPercent,
totalShares, totalShares,
hasShares,
} }
} }
@ -160,6 +165,7 @@ export function getContractBetNullMetrics() {
profit: 0, profit: 0,
profitPercent: 0, profitPercent: 0,
totalShares: {} as { [outcome: string]: number }, totalShares: {} as { [outcome: string]: number },
hasShares: false,
} }
} }

View File

@ -129,13 +129,10 @@ export function BetsList(props: { user: User; hideBetsBefore?: number }) {
.filter((c) => { .filter((c) => {
if (filter === 'all') return true if (filter === 'all') return true
const { totalShares } = contractsMetrics[c.id] const { hasShares } = contractsMetrics[c.id]
const hasSoldAll = Object.values(totalShares).every(
(shares) => shares === 0
)
if (filter === 'sold') return hasSoldAll if (filter === 'sold') return !hasShares
return !hasSoldAll return hasShares
}) })
const unsettled = contracts.filter( const unsettled = contracts.filter(
@ -373,6 +370,7 @@ export function BetsSummary(props: {
const isClosed = closeTime && Date.now() > closeTime const isClosed = closeTime && Date.now() > closeTime
const bets = props.bets.filter((b) => !b.isAnte) const bets = props.bets.filter((b) => !b.isAnte)
const { hasShares } = getContractBetMetrics(contract, bets)
const excludeSalesAndAntes = bets.filter( const excludeSalesAndAntes = bets.filter(
(b) => !b.isAnte && !b.isSold && !b.sale (b) => !b.isAnte && !b.isSold && !b.sale
@ -448,7 +446,7 @@ export function BetsSummary(props: {
isBinary && isBinary &&
!isClosed && !isClosed &&
!resolution && !resolution &&
invested > 0 && hasShares &&
user && ( user && (
<> <>
<button <button