Show bet probability change and payout when creating answer
This commit is contained in:
parent
58cec94b72
commit
0af1fb8d4a
|
@ -156,19 +156,23 @@ export function calculatePayoutAfterCorrectBet(contract: Contract, bet: Bet) {
|
||||||
const { totalShares, pool, totalBets } = contract
|
const { totalShares, pool, totalBets } = contract
|
||||||
const { shares, amount, outcome } = bet
|
const { shares, amount, outcome } = bet
|
||||||
|
|
||||||
|
const prevShares = totalShares[outcome] ?? 0
|
||||||
|
const prevPool = pool[outcome] ?? 0
|
||||||
|
const prevTotalBet = totalBets[outcome] ?? 0
|
||||||
|
|
||||||
const newContract = {
|
const newContract = {
|
||||||
...contract,
|
...contract,
|
||||||
totalShares: {
|
totalShares: {
|
||||||
...totalShares,
|
...totalShares,
|
||||||
[outcome]: totalShares[outcome] + shares,
|
[outcome]: prevShares + shares,
|
||||||
},
|
},
|
||||||
pool: {
|
pool: {
|
||||||
...pool,
|
...pool,
|
||||||
[outcome]: pool[outcome] + amount,
|
[outcome]: prevPool + amount,
|
||||||
},
|
},
|
||||||
totalBets: {
|
totalBets: {
|
||||||
...totalBets,
|
...totalBets,
|
||||||
[outcome]: totalBets[outcome] + amount,
|
[outcome]: prevTotalBet + amount,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -376,6 +376,25 @@ function CreateAnswerInput(props: { contract: Contract }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resultProb = getProbabilityAfterBet(
|
||||||
|
contract.totalShares,
|
||||||
|
'new',
|
||||||
|
betAmount ?? 0
|
||||||
|
)
|
||||||
|
|
||||||
|
const shares = calculateShares(contract.totalShares, betAmount ?? 0, 'new')
|
||||||
|
|
||||||
|
const currentPayout = betAmount
|
||||||
|
? calculatePayoutAfterCorrectBet(contract, {
|
||||||
|
outcome: 'new',
|
||||||
|
amount: betAmount,
|
||||||
|
shares,
|
||||||
|
} as Bet)
|
||||||
|
: 0
|
||||||
|
|
||||||
|
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
|
||||||
|
const currentReturnPercent = (currentReturn * 100).toFixed() + '%'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="gap-4 p-4 bg-gray-50 rounded">
|
<Col className="gap-4 p-4 bg-gray-50 rounded">
|
||||||
<Col className="flex-1 gap-2">
|
<Col className="flex-1 gap-2">
|
||||||
|
@ -390,11 +409,17 @@ function CreateAnswerInput(props: { contract: Contract }) {
|
||||||
/>
|
/>
|
||||||
<div />
|
<div />
|
||||||
<Col
|
<Col
|
||||||
className={clsx('sm:flex-row', text ? 'justify-between' : 'self-end')}
|
className={clsx(
|
||||||
|
'sm:flex-row gap-4',
|
||||||
|
text ? 'justify-between' : 'self-end'
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{text && (
|
{text && (
|
||||||
|
<>
|
||||||
<Col className="gap-2 mt-1">
|
<Col className="gap-2 mt-1">
|
||||||
<div className="text-gray-500 text-sm">Bet amount</div>
|
<div className="text-gray-500 text-sm">
|
||||||
|
Ante bet (cannot be sold)
|
||||||
|
</div>
|
||||||
<AmountInput
|
<AmountInput
|
||||||
amount={betAmount}
|
amount={betAmount}
|
||||||
onChange={setBetAmount}
|
onChange={setBetAmount}
|
||||||
|
@ -404,6 +429,27 @@ function CreateAnswerInput(props: { contract: Contract }) {
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col className="gap-2 mt-1">
|
||||||
|
<div className="text-sm text-gray-500">Implied probability</div>
|
||||||
|
<Row>
|
||||||
|
<div>{formatPercent(0)}</div>
|
||||||
|
<div className="mx-2">→</div>
|
||||||
|
<div>{formatPercent(resultProb)}</div>
|
||||||
|
</Row>
|
||||||
|
<Row className="mt-2 mb-1 items-center gap-2 text-sm text-gray-500">
|
||||||
|
Payout if chosen
|
||||||
|
<InfoTooltip
|
||||||
|
text={`Current payout for ${formatWithCommas(
|
||||||
|
shares
|
||||||
|
)} / ${formatWithCommas(shares)} shares`}
|
||||||
|
/>
|
||||||
|
</Row>
|
||||||
|
<div>
|
||||||
|
{formatMoney(currentPayout)}
|
||||||
|
<span>(+{currentReturnPercent})</span>
|
||||||
|
</div>
|
||||||
|
</Col>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
<button
|
<button
|
||||||
className={clsx(
|
className={clsx(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user