bound initial probability to [0.1, 0.9]

This commit is contained in:
mantikoros 2022-04-28 10:47:18 -04:00
parent 45aa6646fa
commit da153ceea9
2 changed files with 23 additions and 6 deletions

View File

@ -4,8 +4,11 @@ export function ProbabilitySelector(props: {
probabilityInt: number probabilityInt: number
setProbabilityInt: (p: number) => void setProbabilityInt: (p: number) => void
isSubmitting?: boolean isSubmitting?: boolean
minProb?: number
maxProb?: number
}) { }) {
const { probabilityInt, setProbabilityInt, isSubmitting } = props const { probabilityInt, setProbabilityInt, isSubmitting, minProb, maxProb } =
props
return ( return (
<Row className="items-center gap-2"> <Row className="items-center gap-2">
@ -15,19 +18,28 @@ export function ProbabilitySelector(props: {
value={probabilityInt} value={probabilityInt}
className="input input-bordered input-md text-lg" className="input input-bordered input-md text-lg"
disabled={isSubmitting} disabled={isSubmitting}
min={1} min={minProb ?? 1}
max={99} max={maxProb ?? 99}
onChange={(e) => onChange={(e) =>
setProbabilityInt(parseInt(e.target.value.substring(0, 2))) setProbabilityInt(parseInt(e.target.value.substring(0, 2)))
} }
onBlur={() =>
setProbabilityInt(
maxProb && probabilityInt > maxProb
? maxProb
: minProb && probabilityInt < minProb
? minProb
: probabilityInt
)
}
/> />
<span>%</span> <span>%</span>
</label> </label>
<input <input
type="range" type="range"
className="range range-primary" className="range range-primary"
min={1} min={minProb ?? 1}
max={99} max={maxProb ?? 99}
value={probabilityInt} value={probabilityInt}
onChange={(e) => setProbabilityInt(parseInt(e.target.value))} onChange={(e) => setProbabilityInt(parseInt(e.target.value))}
/> />

View File

@ -106,11 +106,14 @@ export function NewContract(props: { question: string; tag?: string }) {
setIsSubmitting(true) setIsSubmitting(true)
const boundedProb =
initialProb > 90 ? 90 : initialProb < 10 ? 10 : initialProb
const result: any = await createContract({ const result: any = await createContract({
question, question,
outcomeType, outcomeType,
description, description,
initialProb, initialProb: boundedProb,
ante, ante,
closeTime, closeTime,
tags, tags,
@ -172,6 +175,8 @@ export function NewContract(props: { question: string; tag?: string }) {
<ProbabilitySelector <ProbabilitySelector
probabilityInt={initialProb} probabilityInt={initialProb}
setProbabilityInt={setInitialProb} setProbabilityInt={setInitialProb}
minProb={10}
maxProb={90}
/> />
</div> </div>
)} )}