diff --git a/common/calculate.ts b/common/calculate.ts index 4adecb54..d3cc3479 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -116,7 +116,6 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { const { resolution } = contract let invested = 0 - let salesInvested = 0 let payout = 0 let loan = 0 let sellProfit = 0 @@ -126,7 +125,7 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { const { isSold, sale, amount, loanAmount, isRedemption } = bet if (isSold) { sellProfit -= amount - salesInvested += amount + invested += amount } else if (sale) { sellProfit += sale.amount } else { @@ -134,6 +133,8 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { redeemed += -1 * amount } else if (amount > 0) { invested += amount + } else { + sellProfit -= amount } loan += loanAmount ?? 0 @@ -143,17 +144,13 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { } } - const investedIncludingSales = invested + salesInvested - - const totalValue = payout + sellProfit + redeemed - const profit = totalValue - invested - const profitPercent = (profit / investedIncludingSales) * 100 + const profit = payout - invested + sellProfit + redeemed + const profitPercent = (profit / invested) * 100 const netInvestment = payout - loan return { invested, payout, - totalValue, profit, profitPercent, netInvestment, @@ -164,7 +161,6 @@ export function getContractBetNullMetrics() { return { invested: 0, payout: 0, - totalValue: 0, profit: 0, profitPercent: 0, netInvestment: 0, diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index cc7f0a6a..e32fc3f3 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -94,7 +94,7 @@ export function BetsList(props: { user: User }) { } const SORTS: Record number> = { profit: (c) => contractsMetrics[c.id].profit, - value: (c) => contractsMetrics[c.id].totalValue, + value: (c) => contractsMetrics[c.id].payout, newest: (c) => Math.max(...contractBets[c.id].map((bet) => bet.createdTime)), resolutionTime: (c) => -(c.resolutionTime ?? c.closeTime ?? Infinity), @@ -215,7 +215,7 @@ function MyContractBets(props: { const isBinary = outcomeType === 'BINARY' const probPercent = getBinaryProbPercent(contract) - const { totalValue, profit, profitPercent } = getContractBetMetrics( + const { payout, profit, profitPercent } = getContractBetMetrics( contract, bets ) @@ -271,7 +271,7 @@ function MyContractBets(props: {
- {formatMoney(metric === 'profit' ? profit : totalValue)} + {formatMoney(metric === 'profit' ? profit : payout)}