Set min and max for contract
This commit is contained in:
parent
ca7e9541d7
commit
89ebf344df
|
@ -41,6 +41,8 @@ export const createContract = functions
|
|||
ante: number
|
||||
closeTime: number
|
||||
tags?: string[]
|
||||
min?: number
|
||||
max?: number
|
||||
},
|
||||
context
|
||||
) => {
|
||||
|
@ -50,7 +52,8 @@ export const createContract = functions
|
|||
const creator = await getUser(userId)
|
||||
if (!creator) return { status: 'error', message: 'User not found' }
|
||||
|
||||
let { question, description, initialProb, closeTime, tags } = data
|
||||
let { question, description, initialProb, closeTime, tags, min, max } =
|
||||
data
|
||||
|
||||
if (!question || typeof question != 'string')
|
||||
return { status: 'error', message: 'Missing or invalid question field' }
|
||||
|
@ -121,8 +124,8 @@ export const createContract = functions
|
|||
closeTime,
|
||||
tags ?? [],
|
||||
100,
|
||||
0,
|
||||
100
|
||||
min ?? 0,
|
||||
max ?? 100
|
||||
)
|
||||
|
||||
if (!isFree && ante) await chargeUser(creator.id, ante)
|
||||
|
|
|
@ -19,6 +19,7 @@ import { Row } from '../components/layout/row'
|
|||
import { MAX_DESCRIPTION_LENGTH, outcomeType } from '../../common/contract'
|
||||
import { formatMoney } from '../../common/util/format'
|
||||
import { useHasCreatedContractToday } from '../hooks/use-has-created-contract-today'
|
||||
import { removeUndefinedProps } from '../../common/util/object'
|
||||
|
||||
export default function Create() {
|
||||
const [question, setQuestion] = useState('')
|
||||
|
@ -66,6 +67,8 @@ export function NewContract(props: { question: string; tag?: string }) {
|
|||
|
||||
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
||||
const [initialProb, setInitialProb] = useState(50)
|
||||
const [min, setMin] = useState<number | undefined>()
|
||||
const [max, setMax] = useState<number | undefined>()
|
||||
const [description, setDescription] = useState('')
|
||||
const [tagText, setTagText] = useState<string>(tag ?? '')
|
||||
const tags = parseWordsAsTags(tagText)
|
||||
|
@ -110,7 +113,8 @@ export function NewContract(props: { question: string; tag?: string }) {
|
|||
|
||||
setIsSubmitting(true)
|
||||
|
||||
const result: any = await createContract({
|
||||
const result: any = await createContract(
|
||||
removeUndefinedProps({
|
||||
question,
|
||||
outcomeType,
|
||||
description,
|
||||
|
@ -118,7 +122,10 @@ export function NewContract(props: { question: string; tag?: string }) {
|
|||
ante,
|
||||
closeTime,
|
||||
tags,
|
||||
}).then((r) => r.data || {})
|
||||
min,
|
||||
max,
|
||||
})
|
||||
).then((r) => r.data || {})
|
||||
|
||||
if (result.status !== 'success') {
|
||||
console.log('error creating contract', result)
|
||||
|
@ -191,6 +198,43 @@ export function NewContract(props: { question: string; tag?: string }) {
|
|||
</div>
|
||||
)}
|
||||
|
||||
{outcomeType === 'NUMERIC' && (
|
||||
<div className="form-control">
|
||||
<label className="label">
|
||||
<span className="mb-1">Value range (min, max)</span>
|
||||
</label>
|
||||
|
||||
<Row className="gap-2">
|
||||
<input
|
||||
type="number"
|
||||
className="input input-bordered"
|
||||
placeholder="MIN"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onChange={(e) =>
|
||||
setMin(isNaN(+e.target.value) ? undefined : +e.target.value)
|
||||
}
|
||||
min={0}
|
||||
max={Number.MAX_SAFE_INTEGER}
|
||||
disabled={isSubmitting}
|
||||
value={min}
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
className="input input-bordered"
|
||||
placeholder="MAX"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onChange={(e) =>
|
||||
setMax(isNaN(+e.target.value) ? undefined : +e.target.value)
|
||||
}
|
||||
min={0}
|
||||
max={Number.MAX_SAFE_INTEGER}
|
||||
disabled={isSubmitting}
|
||||
value={max}
|
||||
/>
|
||||
</Row>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Spacer h={4} />
|
||||
|
||||
<div className="form-control mb-1 items-start">
|
||||
|
|
Loading…
Reference in New Issue
Block a user