diff --git a/common/calculate-cpmm.ts b/common/calculate-cpmm.ts index 493b5fa9..b5153355 100644 --- a/common/calculate-cpmm.ts +++ b/common/calculate-cpmm.ts @@ -123,6 +123,7 @@ export function calculateCpmmAmountToProb( prob: number, outcome: 'YES' | 'NO' ) { + if (prob <= 0 || prob >= 1 || isNaN(prob)) return Infinity if (outcome === 'NO') prob = 1 - prob // First, find an upper bound that leads to a more extreme probability than prob. diff --git a/web/components/amount-input.tsx b/web/components/amount-input.tsx index a31957cb..426a9371 100644 --- a/web/components/amount-input.tsx +++ b/web/components/amount-input.tsx @@ -41,7 +41,7 @@ export function AmountInput(props: { {label} = highLimitProb - const betDisabled = isSubmitting || !betAmount || rangeError || error + const outOfRangeError = + (lowLimitProb !== undefined && + (lowLimitProb <= 0 || lowLimitProb >= 100)) || + (highLimitProb !== undefined && + (highLimitProb <= 0 || highLimitProb >= 100)) + + const initialLow = initialProb * 0.9 + const initialHigh = initialProb + (1 - initialProb) * 0.1 + const lowPlaceholder = Math.round( + isPseudoNumeric ? getMappedValue(contract)(initialLow) : initialLow * 100 + ).toString() + const highPlaceholder = Math.round( + isPseudoNumeric ? getMappedValue(contract)(initialHigh) : initialHigh * 100 + ).toString() const hasYesLimitBet = lowLimitProb !== undefined && !!betAmount const hasNoLimitBet = highLimitProb !== undefined && !!betAmount const hasTwoBets = hasYesLimitBet && hasNoLimitBet - const yesLimitProb = (lowLimitProb ?? initialProb * 100) / 100 - const noLimitProb = (highLimitProb ?? initialProb * 100) / 100 + const betDisabled = + isSubmitting || + !betAmount || + rangeError || + outOfRangeError || + error || + (!hasYesLimitBet && !hasNoLimitBet) - const shares = Math.min( - (betAmount ?? 0) / yesLimitProb, - (betAmount ?? 0) / (1 - noLimitProb) - ) - const yesAmount = shares * yesLimitProb - const noAmount = shares * (1 - noLimitProb) + const yesLimitProb = + lowLimitProb === undefined ? undefined : lowLimitProb / 100 + const noLimitProb = + highLimitProb === undefined ? undefined : highLimitProb / 100 + + const shares = + yesLimitProb !== undefined && noLimitProb !== undefined + ? Math.min( + (betAmount ?? 0) / yesLimitProb, + (betAmount ?? 0) / (1 - noLimitProb) + ) + : (betAmount ?? 0) / (yesLimitProb ?? 1 - (noLimitProb ?? 1)) + + const yesAmount = shares * (yesLimitProb ?? 1) + const noAmount = shares * (1 - (noLimitProb ?? 1)) const profitIfBothFilled = shares - (yesAmount + noAmount) @@ -466,7 +493,7 @@ function LimitOrderPanel(props: { 'YES', yesAmount, contract, - yesLimitProb, + Math.min(yesLimitProb ?? initialLow, 0.999), unfilledBets as LimitBet[] ) const yesReturnPercent = formatPercent(yesReturn) @@ -480,7 +507,7 @@ function LimitOrderPanel(props: { 'NO', noAmount, contract, - noLimitProb, + Math.max(noLimitProb ?? initialHigh, 0.01), unfilledBets as LimitBet[] ) const noReturnPercent = formatPercent(noReturn) @@ -488,8 +515,8 @@ function LimitOrderPanel(props: { return (
- Bet only when the {isPseudoNumeric ? 'value' : 'probability'} reaches - Low or High limit. + Bet when the {isPseudoNumeric ? 'value' : 'probability'} reaches Low + and/or High limit.
@@ -500,7 +527,7 @@ function LimitOrderPanel(props: { prob={lowLimitProb} setProb={setLowLimitProb} isSubmitting={isSubmitting} - placeholder={''} + placeholder={lowPlaceholder} /> @@ -510,7 +537,7 @@ function LimitOrderPanel(props: { prob={highLimitProb} setProb={setHighLimitProb} isSubmitting={isSubmitting} - placeholder={''} + placeholder={highPlaceholder} /> @@ -520,6 +547,11 @@ function LimitOrderPanel(props: { Low limit must be less than High limit )} + {outOfRangeError && ( +
+ Limit is out of range +
+ )}
Max amount* @@ -534,36 +566,35 @@ function LimitOrderPanel(props: { /> - {hasYesLimitBet && ( + {(hasTwoBets || (hasYesLimitBet && yesBet.amount !== 0)) && (
{isPseudoNumeric ? ( - 'Bought now' + ) : ( - <> - bought now - - )} + + )}{' '} + current fill
- {formatMoney(yesBet.amount)}/ + {formatMoney(yesBet.amount)} of{' '} {formatMoney(yesBet.orderAmount ?? 0)}
)} - {hasNoLimitBet && ( + {(hasTwoBets || (hasNoLimitBet && noBet.amount !== 0)) && (
{isPseudoNumeric ? ( - 'Bought now' + ) : ( - <> - bought now - - )} + + )}{' '} + current fill
- {formatMoney(noBet.amount)}/{formatMoney(noBet.orderAmount ?? 0)} + {formatMoney(noBet.amount)} of{' '} + {formatMoney(noBet.orderAmount ?? 0)}
)} diff --git a/web/components/bucket-input.tsx b/web/components/bucket-input.tsx index 85a872b9..19dacd65 100644 --- a/web/components/bucket-input.tsx +++ b/web/components/bucket-input.tsx @@ -9,8 +9,9 @@ export function BucketInput(props: { contract: NumericContract | PseudoNumericContract isSubmitting?: boolean onBucketChange: (value?: number, bucket?: string) => void + placeholder?: string }) { - const { contract, isSubmitting, onBucketChange } = props + const { contract, isSubmitting, onBucketChange, placeholder } = props const [numberString, setNumberString] = useState('') @@ -39,7 +40,7 @@ export function BucketInput(props: { error={undefined} disabled={isSubmitting} numberString={numberString} - label="" + placeholder={placeholder} /> ) } diff --git a/web/components/number-input.tsx b/web/components/number-input.tsx index d7159fab..0b48df6e 100644 --- a/web/components/number-input.tsx +++ b/web/components/number-input.tsx @@ -9,8 +9,8 @@ export function NumberInput(props: { numberString: string onChange: (newNumberString: string) => void error: string | undefined - label: string disabled?: boolean + placeholder?: string className?: string inputClassName?: string // Needed to focus the amount input @@ -21,8 +21,8 @@ export function NumberInput(props: { numberString, onChange, error, - label, disabled, + placeholder, className, inputClassName, inputRef, @@ -32,16 +32,17 @@ export function NumberInput(props: { return (