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
|
ante: number
|
||||||
closeTime: number
|
closeTime: number
|
||||||
tags?: string[]
|
tags?: string[]
|
||||||
|
min?: number
|
||||||
|
max?: number
|
||||||
},
|
},
|
||||||
context
|
context
|
||||||
) => {
|
) => {
|
||||||
|
@ -50,7 +52,8 @@ export const createContract = functions
|
||||||
const creator = await getUser(userId)
|
const creator = await getUser(userId)
|
||||||
if (!creator) return { status: 'error', message: 'User not found' }
|
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')
|
if (!question || typeof question != 'string')
|
||||||
return { status: 'error', message: 'Missing or invalid question field' }
|
return { status: 'error', message: 'Missing or invalid question field' }
|
||||||
|
@ -121,8 +124,8 @@ export const createContract = functions
|
||||||
closeTime,
|
closeTime,
|
||||||
tags ?? [],
|
tags ?? [],
|
||||||
100,
|
100,
|
||||||
0,
|
min ?? 0,
|
||||||
100
|
max ?? 100
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isFree && ante) await chargeUser(creator.id, ante)
|
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 { MAX_DESCRIPTION_LENGTH, outcomeType } from '../../common/contract'
|
||||||
import { formatMoney } from '../../common/util/format'
|
import { formatMoney } from '../../common/util/format'
|
||||||
import { useHasCreatedContractToday } from '../hooks/use-has-created-contract-today'
|
import { useHasCreatedContractToday } from '../hooks/use-has-created-contract-today'
|
||||||
|
import { removeUndefinedProps } from '../../common/util/object'
|
||||||
|
|
||||||
export default function Create() {
|
export default function Create() {
|
||||||
const [question, setQuestion] = useState('')
|
const [question, setQuestion] = useState('')
|
||||||
|
@ -66,6 +67,8 @@ export function NewContract(props: { question: string; tag?: string }) {
|
||||||
|
|
||||||
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
||||||
const [initialProb, setInitialProb] = useState(50)
|
const [initialProb, setInitialProb] = useState(50)
|
||||||
|
const [min, setMin] = useState<number | undefined>()
|
||||||
|
const [max, setMax] = useState<number | undefined>()
|
||||||
const [description, setDescription] = useState('')
|
const [description, setDescription] = useState('')
|
||||||
const [tagText, setTagText] = useState<string>(tag ?? '')
|
const [tagText, setTagText] = useState<string>(tag ?? '')
|
||||||
const tags = parseWordsAsTags(tagText)
|
const tags = parseWordsAsTags(tagText)
|
||||||
|
@ -110,15 +113,19 @@ export function NewContract(props: { question: string; tag?: string }) {
|
||||||
|
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|
||||||
const result: any = await createContract({
|
const result: any = await createContract(
|
||||||
question,
|
removeUndefinedProps({
|
||||||
outcomeType,
|
question,
|
||||||
description,
|
outcomeType,
|
||||||
initialProb,
|
description,
|
||||||
ante,
|
initialProb,
|
||||||
closeTime,
|
ante,
|
||||||
tags,
|
closeTime,
|
||||||
}).then((r) => r.data || {})
|
tags,
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
})
|
||||||
|
).then((r) => r.data || {})
|
||||||
|
|
||||||
if (result.status !== 'success') {
|
if (result.status !== 'success') {
|
||||||
console.log('error creating contract', result)
|
console.log('error creating contract', result)
|
||||||
|
@ -191,6 +198,43 @@ export function NewContract(props: { question: string; tag?: string }) {
|
||||||
</div>
|
</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} />
|
<Spacer h={4} />
|
||||||
|
|
||||||
<div className="form-control mb-1 items-start">
|
<div className="form-control mb-1 items-start">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user