diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx
index cecb4bc5..07d64230 100644
--- a/web/components/bets-list.tsx
+++ b/web/components/bets-list.tsx
@@ -10,8 +10,12 @@ import { Col } from './layout/col'
import { Spacer } from './layout/spacer'
import { Contract, path } from '../lib/firebase/contracts'
import { Row } from './layout/row'
-import { calculateWinnings, currentValue } from '../lib/calculation/contract'
import { UserLink } from './user-page'
+import {
+ calculatePayout,
+ currentValue,
+ resolvedPayout,
+} from '../lib/calculation/contract'
export function BetsList(props: { user: User }) {
const { user } = props
@@ -48,13 +52,15 @@ function MyContractBets(props: { contractId: string; bets: Bet[] }) {
const betsTotal = _.sumBy(bets, (bet) => bet.amount)
- const betsValue = _.sumBy(bets, (bet) => currentValue(contract, bet))
+ const betsPayout = resolution
+ ? _.sumBy(bets, (bet) => resolvedPayout(contract, bet))
+ : 0
const yesWinnings = _.sumBy(bets, (bet) =>
- calculateWinnings(contract, bet, 'YES')
+ calculatePayout(contract, bet, 'YES')
)
const noWinnings = _.sumBy(bets, (bet) =>
- calculateWinnings(contract, bet, 'NO')
+ calculatePayout(contract, bet, 'NO')
)
return (
@@ -70,46 +76,42 @@ function MyContractBets(props: { contractId: string; bets: Bet[] }) {
{resolution &&
•
}
- {resolution === 'YES' && (
- Resolved YES
- )}
- {resolution === 'NO' && (
- Resolved NO
- )}
- {resolution === 'CANCEL' && (
- Resolved CANCEL
- )}
+
+ Resolved {resolution === 'YES' && }
+ {resolution === 'NO' && }
+ {resolution === 'CANCEL' && }
+
-
+
Total bets
- {formatMoney(betsTotal)}
+ {formatMoney(betsTotal)}
{resolution ? (
<>
Winnings
- {formatMoney(yesWinnings)}
+ {formatMoney(betsPayout)}
>
) : (
<>
- {/*
- Current value
- {formatMoney(betsValue)}
- */}
- If YES
- {formatMoney(yesWinnings)}
+
+ If
+
+ {formatMoney(yesWinnings)}
- If NO
- {formatMoney(noWinnings)}
+
+ If
+
+ {formatMoney(noWinnings)}
>
)}
@@ -125,6 +127,8 @@ function MyContractBets(props: { contractId: string; bets: Bet[] }) {
function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) {
const { contract, bets } = props
+ const { isResolved } = contract
+
return (
@@ -134,8 +138,8 @@ function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) {
Outcome |
Bet |
Probability |
- Est. max payout |
- Current value |
+ {!isResolved && Est. max payout | }
+ {isResolved ? <>Payout> : <>Current value>} |
@@ -151,6 +155,7 @@ function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) {
function BetRow(props: { bet: Bet; contract: Contract }) {
const { bet, contract } = props
const { amount, outcome, createdTime, probBefore, probAfter, dpmWeight } = bet
+ const { isResolved } = contract
return (
@@ -160,8 +165,26 @@ function BetRow(props: { bet: Bet; contract: Contract }) {
{formatPercent(probBefore)} → {formatPercent(probAfter)}
|
- {formatMoney(amount + dpmWeight)} |
- {formatMoney(currentValue(contract, bet))} |
+ {!isResolved && {formatMoney(amount + dpmWeight)} | }
+
+ {formatMoney(
+ isResolved
+ ? resolvedPayout(contract, bet)
+ : currentValue(contract, bet)
+ )}
+ |
)
}
+
+function YesLabel() {
+ return YES
+}
+
+function NoLabel() {
+ return NO
+}
+
+function CancelLabel() {
+ return CANCEL
+}
diff --git a/web/lib/calculation/contract.ts b/web/lib/calculation/contract.ts
index 88ef49ab..6a13227e 100644
--- a/web/lib/calculation/contract.ts
+++ b/web/lib/calculation/contract.ts
@@ -34,7 +34,7 @@ export function getDpmWeight(
: (bet * Math.pow(yesPot, 2)) / (Math.pow(noPot, 2) + bet * noPot)
}
-export function calculateWinnings(
+export function calculatePayout(
contract: Contract,
bet: Bet,
outcome: 'YES' | 'NO' | 'CANCEL'
@@ -57,11 +57,16 @@ export function calculateWinnings(
return (1 - fees) * (dpmWeight / dpmWeights[outcome]) * potSize + amount
}
+export function resolvedPayout(contract: Contract, bet: Bet) {
+ if (contract.resolution)
+ return calculatePayout(contract, bet, contract.resolution)
+ throw new Error('Contract was not resolved')
+}
export function currentValue(contract: Contract, bet: Bet) {
const prob = getProbability(contract.pot)
- const yesWinnings = calculateWinnings(contract, bet, 'YES')
- const noWinnings = calculateWinnings(contract, bet, 'NO')
+ const yesPayout = calculatePayout(contract, bet, 'YES')
+ const noPayout = calculatePayout(contract, bet, 'NO')
- return prob * yesWinnings + (1 - prob) * noWinnings
+ return prob * yesPayout + (1 - prob) * noPayout
}