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' export function ProbabilityInput(props: { prob: number | undefined onChange: (newProb: number | undefined) => void disabled?: boolean placeholder?: string className?: string inputClassName?: string }) { const { prob, onChange, disabled, placeholder, className, inputClassName } = props const onProbChange = (str: string) => { let prob = parseInt(str.replace(/\D/g, '')) const isInvalid = !str || isNaN(prob) if (prob.toString().length > 2) { if (prob === 100) prob = 99 else if (prob < 1) prob = 1 else prob = +prob.toString().slice(-2) } onChange(isInvalid ? undefined : prob) } return ( ) } 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} placeholder={placeholder} /> ) : ( ) }