diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index 05af4aee..e8bd6f20 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -8,6 +8,7 @@ import { Col } from './layout/col' import { Row } from './layout/row' import { Spacer } from './layout/spacer' import { YesNoSelector } from './yes-no-selector' +import { formatMoney } from '../lib/util/format' export function BetPanel(props: { contract: Contract; className?: string }) { const { contract, className } = props @@ -23,6 +24,8 @@ export function BetPanel(props: { contract: Contract; className?: string }) { function onBetChange(str: string) { const amount = parseInt(str) setBetAmount(isNaN(amount) ? undefined : amount) + + setWasSubmitted(false) } async function submitBet() { @@ -48,10 +51,20 @@ export function BetPanel(props: { contract: Contract; className?: string }) { const betDisabled = isSubmitting || wasSubmitted + const initialProb = getProbability(contract.pot, betChoice) + const resultProb = getProbability(contract.pot, betChoice, betAmount) + const dpmWeight = getDpmWeight(contract.pot, betAmount ?? 0, betChoice) + + const estimatedWinnings = Math.floor((betAmount ?? 0) + dpmWeight) + const estimatedReturn = betAmount + ? (estimatedWinnings - betAmount) / betAmount + : 0 + const estimatedReturnPercent = (estimatedReturn * 100).toFixed() + '%' + return ( @@ -60,69 +73,73 @@ export function BetPanel(props: { contract: Contract; className?: string }) { className="p-2" selected={betChoice} onSelect={setBetChoice} - yesLabel="Yes 57" - noLabel="No 43" />
Bet amount
- + +
+ M$ +
onBetChange(e.target.value)} /> -
points
- {!!betAmount && ( - <> + + +
Implied probability
+ +
+ {Math.floor(initialProb * 1000) / 10 + '%'} +
+
+
+ {Math.floor(resultProb * 1000) / 10 + '%'} +
+
+ + + +
Estimated winnings
+
+ {formatMoney(estimatedWinnings)} (+{estimatedReturnPercent}) +
+ + + + + + {wasSubmitted && ( + -
Average price
-
{betChoice === 'YES' ? 0.57 : 0.43} points
+
Bet submitted!
- + -
Estimated winnings
-
- {Math.floor(betAmount / (betChoice === 'YES' ? 0.57 : 0.43))} points -
- - - - - - {wasSubmitted && ( - - - -
Bet submitted!
- - - - - - )} - + )} ) @@ -130,3 +147,29 @@ export function BetPanel(props: { contract: Contract; className?: string }) { const functions = getFunctions() export const placeBet = httpsCallable(functions, 'placeBet') + +const getProbability = ( + pot: { YES: number; NO: number }, + outcome: 'YES' | 'NO', + bet = 0 +) => { + const [yesPot, noPot] = [ + pot.YES + (outcome === 'YES' ? bet : 0), + pot.NO + (outcome === 'NO' ? bet : 0), + ] + const numerator = Math.pow(yesPot, 2) + const denominator = Math.pow(yesPot, 2) + Math.pow(noPot, 2) + return numerator / denominator +} + +const getDpmWeight = ( + pot: { YES: number; NO: number }, + bet: number, + betChoice: 'YES' | 'NO' +) => { + const [yesPot, noPot] = [pot.YES, pot.NO] + + return betChoice === 'YES' + ? (bet * Math.pow(noPot, 2)) / (Math.pow(yesPot, 2) + bet * yesPot) + : (bet * Math.pow(yesPot, 2)) / (Math.pow(noPot, 2) + bet * noPot) +} diff --git a/web/components/header.tsx b/web/components/header.tsx index c8fa559c..7f6fa851 100644 --- a/web/components/header.tsx +++ b/web/components/header.tsx @@ -34,16 +34,16 @@ function SignInLink(props: { darkBackground?: boolean }) { {user ? ( <> - Create a market + Create a market - {user.name} + {user.name} ) : showLogin ? (