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 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,
}
}

View File

@ -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 && (
<>
<button