()
+ const [isSubmitting, setIsSubmitting] = useState(false)
+ const [wasSubmitted, setWasSubmitted] = useState(false)
+
+ function onBetChange(newAmount: number | undefined) {
+ setWasSubmitted(false)
+ setBetAmount(newAmount)
+ }
+
+ async function submitBet() {
+ if (!user || !betAmount) return
+
+ const limitProbScaled =
+ lowLimitProb !== undefined ? lowLimitProb / 100 : undefined
+
+ setError(undefined)
+ setIsSubmitting(true)
+
+ placeBet(
+ removeUndefinedProps({
+ amount: betAmount,
+ outcome: betChoice,
+ contractId: contract.id,
+ limitProb: limitProbScaled,
+ })
+ )
+ .then((r) => {
+ console.log('placed bet. Result:', r)
+ setIsSubmitting(false)
+ setWasSubmitted(true)
+ setBetAmount(undefined)
+ if (onBuySuccess) onBuySuccess()
+ })
+ .catch((e) => {
+ if (e instanceof APIError) {
+ setError(e.toString())
+ } else {
+ console.error(e)
+ setError('Error placing bet')
+ }
+ setIsSubmitting(false)
+ })
+
+ track('bet', {
+ location: 'bet panel',
+ outcomeType: contract.outcomeType,
+ slug: contract.slug,
+ contractId: contract.id,
+ amount: betAmount,
+ outcome: betChoice,
+ isLimitOrder: true,
+ limitProb: limitProbScaled,
+ })
+ }
+
+ const betDisabled = isSubmitting || !betAmount || error
+
+ const lowProbFrac = (lowLimitProb ?? initialProb * 100) / 100
+ const {
+ currentPayout: lowPayout,
+ currentReturn: lowReturn,
+ totalFees: lowFees,
+ } = getBinaryBetStats(
+ 'YES',
+ betAmount ?? 0,
+ contract,
+ lowProbFrac,
+ unfilledBets as LimitBet[]
+ )
+ const lowReturnPercent = formatPercent(lowReturn)
+
+ const highProbFrac = (highLimitProb ?? initialProb * 100) / 100
+ const {
+ currentPayout: highPayout,
+ currentReturn: highReturn,
+ totalFees: highFees,
+ } = getBinaryBetStats(
+ 'NO',
+ betAmount ?? 0,
+ contract,
+ highProbFrac,
+ unfilledBets as LimitBet[]
+ )
+ const highReturnPercent = formatPercent(highReturn)
+
+ return (
+ <>
+
+ Trigger when the {isPseudoNumeric ? 'value' : 'probability'} reaches low
+ or high limit.
+
+
+
+
+ Low
+
+
+
+ High
+
+
+
+
+
+ Max amount*
+
+
+
+
+
+
+
+ {isPseudoNumeric ? (
+ 'Max payout'
+ ) : (
+ <>
+ Max payout
+ >
+ )}
+
+
+
+
+
+ {formatMoney(lowPayout)}
+
+ (+{lowReturnPercent})
+
+
+
+
+
+ {isPseudoNumeric ? (
+ 'Max payout'
+ ) : (
+ <>
+ Max payout
+ >
+ )}
+
+
+
+
+
+ {formatMoney(highPayout)}
+
+ (+{highReturnPercent})
+
+
+
+
+
+
+ {user && (
+
+ )}
+
+ {wasSubmitted && Order submitted!
}
+ >
+ )
+}
+
function QuickOrLimitBet(props: {
isLimitOrder: boolean
setIsLimitOrder: (isLimitOrder: boolean) => void
diff --git a/web/components/probability-input.tsx b/web/components/probability-input.tsx
index 15f73799..77d0fe4c 100644
--- a/web/components/probability-input.tsx
+++ b/web/components/probability-input.tsx
@@ -1,4 +1,7 @@
import clsx from 'clsx'
+import { CPMMBinaryContract, PseudoNumericContract } from 'common/contract'
+import { getPseudoProbability } from 'common/pseudo-numeric'
+import { BucketInput } from './bucket-input'
import { Col } from './layout/col'
import { Spacer } from './layout/spacer'
@@ -6,10 +9,12 @@ export function ProbabilityInput(props: {
prob: number | undefined
onChange: (newProb: number | undefined) => void
disabled?: boolean
+ placeholder?: string
className?: string
inputClassName?: string
}) {
- const { prob, onChange, disabled, className, inputClassName } = props
+ const { prob, onChange, disabled, placeholder, className, inputClassName } =
+ props
const onProbChange = (str: string) => {
let prob = parseInt(str.replace(/\D/g, ''))
@@ -35,7 +40,7 @@ export function ProbabilityInput(props: {
min={1}
pattern="[0-9]*"
inputMode="numeric"
- placeholder="0"
+ placeholder={placeholder ?? '0'}
maxLength={2}
value={prob ?? ''}
disabled={disabled}
@@ -47,3 +52,42 @@ export function ProbabilityInput(props: {
)
}
+
+export function ProbabilityOrNumericInput(props: {
+ contract: CPMMBinaryContract | PseudoNumericContract
+ prob: number | undefined
+ setProb: (prob: number | undefined) => void
+ isSubmitting: boolean
+ placeholder?: string
+}) {
+ const { contract, prob, setProb, isSubmitting, placeholder } = props
+ const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC'
+
+ return isPseudoNumeric ? (
+
+ setProb(
+ value === undefined
+ ? undefined
+ : 100 *
+ getPseudoProbability(
+ value,
+ contract.min,
+ contract.max,
+ contract.isLogScale
+ )
+ )
+ }
+ isSubmitting={isSubmitting}
+ />
+ ) : (
+
+ )
+}