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

View File

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