Show just payout column for resolved markets, tweak calculation and resolved labels.
This commit is contained in:
parent
743616449f
commit
83b4cc38b3
|
@ -10,8 +10,12 @@ import { Col } from './layout/col'
|
||||||
import { Spacer } from './layout/spacer'
|
import { Spacer } from './layout/spacer'
|
||||||
import { Contract, path } from '../lib/firebase/contracts'
|
import { Contract, path } from '../lib/firebase/contracts'
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
import { calculateWinnings, currentValue } from '../lib/calculation/contract'
|
|
||||||
import { UserLink } from './user-page'
|
import { UserLink } from './user-page'
|
||||||
|
import {
|
||||||
|
calculatePayout,
|
||||||
|
currentValue,
|
||||||
|
resolvedPayout,
|
||||||
|
} from '../lib/calculation/contract'
|
||||||
|
|
||||||
export function BetsList(props: { user: User }) {
|
export function BetsList(props: { user: User }) {
|
||||||
const { user } = props
|
const { user } = props
|
||||||
|
@ -48,13 +52,15 @@ function MyContractBets(props: { contractId: string; bets: Bet[] }) {
|
||||||
|
|
||||||
const betsTotal = _.sumBy(bets, (bet) => bet.amount)
|
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) =>
|
const yesWinnings = _.sumBy(bets, (bet) =>
|
||||||
calculateWinnings(contract, bet, 'YES')
|
calculatePayout(contract, bet, 'YES')
|
||||||
)
|
)
|
||||||
const noWinnings = _.sumBy(bets, (bet) =>
|
const noWinnings = _.sumBy(bets, (bet) =>
|
||||||
calculateWinnings(contract, bet, 'NO')
|
calculatePayout(contract, bet, 'NO')
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -70,46 +76,42 @@ function MyContractBets(props: { contractId: string; bets: Bet[] }) {
|
||||||
<UserLink displayName={contract.creatorName} />
|
<UserLink displayName={contract.creatorName} />
|
||||||
</div>
|
</div>
|
||||||
{resolution && <div>•</div>}
|
{resolution && <div>•</div>}
|
||||||
{resolution === 'YES' && (
|
<div>
|
||||||
<div className="text-primary">Resolved YES</div>
|
Resolved {resolution === 'YES' && <YesLabel />}
|
||||||
)}
|
{resolution === 'NO' && <NoLabel />}
|
||||||
{resolution === 'NO' && (
|
{resolution === 'CANCEL' && <CancelLabel />}
|
||||||
<div className="text-red-400">Resolved NO</div>
|
</div>
|
||||||
)}
|
|
||||||
{resolution === 'CANCEL' && (
|
|
||||||
<div className="text-yellow-400">Resolved CANCEL</div>
|
|
||||||
)}
|
|
||||||
</Row>
|
</Row>
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Spacer h={6} />
|
<Spacer h={6} />
|
||||||
|
|
||||||
<Row className="gap-8 ">
|
<Row className="gap-8">
|
||||||
<Col>
|
<Col>
|
||||||
<div className="text-sm text-gray-500">Total bets</div>
|
<div className="text-sm text-gray-500">Total bets</div>
|
||||||
<div className="">{formatMoney(betsTotal)}</div>
|
<div>{formatMoney(betsTotal)}</div>
|
||||||
</Col>
|
</Col>
|
||||||
{resolution ? (
|
{resolution ? (
|
||||||
<>
|
<>
|
||||||
<Col>
|
<Col>
|
||||||
<div className="text-sm text-gray-500">Winnings</div>
|
<div className="text-sm text-gray-500">Winnings</div>
|
||||||
<div className="">{formatMoney(yesWinnings)}</div>
|
<div>{formatMoney(betsPayout)}</div>
|
||||||
</Col>
|
</Col>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{/* <Col>
|
|
||||||
<div className="text-sm text-gray-500">Current value</div>
|
|
||||||
<div className="">{formatMoney(betsValue)}</div>
|
|
||||||
</Col> */}
|
|
||||||
<Col>
|
<Col>
|
||||||
<div className="text-sm text-primary">If YES</div>
|
<div className="text-sm text-gray-500">
|
||||||
<div className="">{formatMoney(yesWinnings)}</div>
|
If <YesLabel />
|
||||||
|
</div>
|
||||||
|
<div>{formatMoney(yesWinnings)}</div>
|
||||||
</Col>
|
</Col>
|
||||||
<Col>
|
<Col>
|
||||||
<div className="text-sm text-red-400">If NO</div>
|
<div className="text-sm text-gray-500">
|
||||||
<div className="">{formatMoney(noWinnings)}</div>
|
If <NoLabel />
|
||||||
|
</div>
|
||||||
|
<div>{formatMoney(noWinnings)}</div>
|
||||||
</Col>
|
</Col>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -125,6 +127,8 @@ function MyContractBets(props: { contractId: string; bets: Bet[] }) {
|
||||||
function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) {
|
function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) {
|
||||||
const { contract, bets } = props
|
const { contract, bets } = props
|
||||||
|
|
||||||
|
const { isResolved } = contract
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="table table-zebra table-compact text-gray-500 w-full">
|
<table className="table table-zebra table-compact text-gray-500 w-full">
|
||||||
|
@ -134,8 +138,8 @@ function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) {
|
||||||
<th>Outcome</th>
|
<th>Outcome</th>
|
||||||
<th>Bet</th>
|
<th>Bet</th>
|
||||||
<th>Probability</th>
|
<th>Probability</th>
|
||||||
<th>Est. max payout</th>
|
{!isResolved && <th>Est. max payout</th>}
|
||||||
<th>Current value</th>
|
<th>{isResolved ? <>Payout</> : <>Current value</>}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -151,6 +155,7 @@ function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) {
|
||||||
function BetRow(props: { bet: Bet; contract: Contract }) {
|
function BetRow(props: { bet: Bet; contract: Contract }) {
|
||||||
const { bet, contract } = props
|
const { bet, contract } = props
|
||||||
const { amount, outcome, createdTime, probBefore, probAfter, dpmWeight } = bet
|
const { amount, outcome, createdTime, probBefore, probAfter, dpmWeight } = bet
|
||||||
|
const { isResolved } = contract
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -160,8 +165,26 @@ function BetRow(props: { bet: Bet; contract: Contract }) {
|
||||||
<td>
|
<td>
|
||||||
{formatPercent(probBefore)} → {formatPercent(probAfter)}
|
{formatPercent(probBefore)} → {formatPercent(probAfter)}
|
||||||
</td>
|
</td>
|
||||||
<td>{formatMoney(amount + dpmWeight)}</td>
|
{!isResolved && <td>{formatMoney(amount + dpmWeight)}</td>}
|
||||||
<td>{formatMoney(currentValue(contract, bet))}</td>
|
<td>
|
||||||
|
{formatMoney(
|
||||||
|
isResolved
|
||||||
|
? resolvedPayout(contract, bet)
|
||||||
|
: currentValue(contract, bet)
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function YesLabel() {
|
||||||
|
return <span className="text-primary">YES</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
function NoLabel() {
|
||||||
|
return <span className="text-red-400">NO</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
function CancelLabel() {
|
||||||
|
return <span className="text-yellow-400">CANCEL</span>
|
||||||
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ export function getDpmWeight(
|
||||||
: (bet * Math.pow(yesPot, 2)) / (Math.pow(noPot, 2) + bet * noPot)
|
: (bet * Math.pow(yesPot, 2)) / (Math.pow(noPot, 2) + bet * noPot)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateWinnings(
|
export function calculatePayout(
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
bet: Bet,
|
bet: Bet,
|
||||||
outcome: 'YES' | 'NO' | 'CANCEL'
|
outcome: 'YES' | 'NO' | 'CANCEL'
|
||||||
|
@ -57,11 +57,16 @@ export function calculateWinnings(
|
||||||
|
|
||||||
return (1 - fees) * (dpmWeight / dpmWeights[outcome]) * potSize + amount
|
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) {
|
export function currentValue(contract: Contract, bet: Bet) {
|
||||||
const prob = getProbability(contract.pot)
|
const prob = getProbability(contract.pot)
|
||||||
const yesWinnings = calculateWinnings(contract, bet, 'YES')
|
const yesPayout = calculatePayout(contract, bet, 'YES')
|
||||||
const noWinnings = calculateWinnings(contract, bet, 'NO')
|
const noPayout = calculatePayout(contract, bet, 'NO')
|
||||||
|
|
||||||
return prob * yesWinnings + (1 - prob) * noWinnings
|
return prob * yesPayout + (1 - prob) * noPayout
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user