Bet choice => outcome

This commit is contained in:
James Grugett 2022-07-21 12:48:03 -05:00
parent 8fa9637a6b
commit 78e7862e23

View File

@ -157,7 +157,7 @@ function BuyPanel(props: {
const initialProb = getProbability(contract) const initialProb = getProbability(contract)
const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC' const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC'
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(selected) const [outcome, setOutcome] = useState<'YES' | 'NO' | undefined>(selected)
const [betAmount, setBetAmount] = useState<number | undefined>(undefined) const [betAmount, setBetAmount] = useState<number | undefined>(undefined)
const [error, setError] = useState<string | undefined>() const [error, setError] = useState<string | undefined>()
const [isSubmitting, setIsSubmitting] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false)
@ -173,7 +173,7 @@ function BuyPanel(props: {
}, [selected, focusAmountInput]) }, [selected, focusAmountInput])
function onBetChoice(choice: 'YES' | 'NO') { function onBetChoice(choice: 'YES' | 'NO') {
setBetChoice(choice) setOutcome(choice)
setWasSubmitted(false) setWasSubmitted(false)
focusAmountInput() focusAmountInput()
} }
@ -181,8 +181,8 @@ function BuyPanel(props: {
function onBetChange(newAmount: number | undefined) { function onBetChange(newAmount: number | undefined) {
setWasSubmitted(false) setWasSubmitted(false)
setBetAmount(newAmount) setBetAmount(newAmount)
if (!betChoice) { if (!outcome) {
setBetChoice('YES') setOutcome('YES')
} }
} }
@ -193,8 +193,8 @@ function BuyPanel(props: {
setIsSubmitting(true) setIsSubmitting(true)
placeBet({ placeBet({
outcome,
amount: betAmount, amount: betAmount,
outcome: betChoice,
contractId: contract.id, contractId: contract.id,
}) })
.then((r) => { .then((r) => {
@ -220,7 +220,7 @@ function BuyPanel(props: {
slug: contract.slug, slug: contract.slug,
contractId: contract.id, contractId: contract.id,
amount: betAmount, amount: betAmount,
outcome: betChoice, outcome,
isLimitOrder: false, isLimitOrder: false,
}) })
} }
@ -228,7 +228,7 @@ function BuyPanel(props: {
const betDisabled = isSubmitting || !betAmount || error const betDisabled = isSubmitting || !betAmount || error
const { newPool, newP, newBet } = getBinaryCpmmBetInfo( const { newPool, newP, newBet } = getBinaryCpmmBetInfo(
betChoice ?? 'YES', outcome ?? 'YES',
betAmount ?? 0, betAmount ?? 0,
contract, contract,
undefined, undefined,
@ -256,7 +256,7 @@ function BuyPanel(props: {
<YesNoSelector <YesNoSelector
className="mb-4" className="mb-4"
btnClassName="flex-1" btnClassName="flex-1"
selected={betChoice} selected={outcome}
onSelect={(choice) => onBetChoice(choice)} onSelect={(choice) => onBetChoice(choice)}
isPseudoNumeric={isPseudoNumeric} isPseudoNumeric={isPseudoNumeric}
/> />
@ -294,7 +294,7 @@ function BuyPanel(props: {
'Max payout' 'Max payout'
) : ( ) : (
<> <>
Payout if <BinaryOutcomeLabel outcome={betChoice ?? 'YES'} /> Payout if <BinaryOutcomeLabel outcome={outcome ?? 'YES'} />
</> </>
)} )}
</div> </div>
@ -319,7 +319,7 @@ function BuyPanel(props: {
'btn flex-1', 'btn flex-1',
betDisabled betDisabled
? 'btn-disabled' ? 'btn-disabled'
: betChoice === 'YES' : outcome === 'YES'
? 'btn-primary' ? 'btn-primary'
: 'border-none bg-red-400 hover:bg-red-500', : 'border-none bg-red-400 hover:bg-red-500',
isSubmitting ? 'loading' : '' isSubmitting ? 'loading' : ''
@ -392,13 +392,13 @@ function LimitOrderPanel(props: {
const betsPromise = hasTwoBets const betsPromise = hasTwoBets
? Promise.all([ ? Promise.all([
placeBet({ placeBet({
betChoice: 'YES', outcome: 'YES',
amount: yesAmount, amount: yesAmount,
limitProb: yesLimitProb, limitProb: yesLimitProb,
contractId: contract.id, contractId: contract.id,
}), }),
placeBet({ placeBet({
betChoice: 'NO', outcome: 'NO',
amount: noAmount, amount: noAmount,
limitProb: noLimitProb, limitProb: noLimitProb,
contractId: contract.id, contractId: contract.id,