create log scale market, validation
This commit is contained in:
parent
301d9d8538
commit
1afe62296e
|
|
@ -28,7 +28,8 @@ export function getNewContract(
|
||||||
// used for numeric markets
|
// used for numeric markets
|
||||||
bucketCount: number,
|
bucketCount: number,
|
||||||
min: number,
|
min: number,
|
||||||
max: number
|
max: number,
|
||||||
|
isLogScale: boolean
|
||||||
) {
|
) {
|
||||||
const tags = parseTags(
|
const tags = parseTags(
|
||||||
`${question} ${description} ${extraTags.map((tag) => `#${tag}`).join(' ')}`
|
`${question} ${description} ${extraTags.map((tag) => `#${tag}`).join(' ')}`
|
||||||
|
|
@ -39,7 +40,7 @@ export function getNewContract(
|
||||||
outcomeType === 'BINARY'
|
outcomeType === 'BINARY'
|
||||||
? getBinaryCpmmProps(initialProb, ante) // getBinaryDpmProps(initialProb, ante)
|
? getBinaryCpmmProps(initialProb, ante) // getBinaryDpmProps(initialProb, ante)
|
||||||
: outcomeType === 'PSEUDO_NUMERIC'
|
: outcomeType === 'PSEUDO_NUMERIC'
|
||||||
? getPseudoNumericCpmmProps(initialProb, ante, min, max, false)
|
? getPseudoNumericCpmmProps(initialProb, ante, min, max, isLogScale)
|
||||||
: outcomeType === 'NUMERIC'
|
: outcomeType === 'NUMERIC'
|
||||||
? getNumericProps(ante, bucketCount, min, max)
|
? getNumericProps(ante, bucketCount, min, max)
|
||||||
: getFreeAnswerProps(ante)
|
: getFreeAnswerProps(ante)
|
||||||
|
|
|
||||||
|
|
@ -49,21 +49,25 @@ const numericSchema = z.object({
|
||||||
min: z.number(),
|
min: z.number(),
|
||||||
max: z.number(),
|
max: z.number(),
|
||||||
initialValue: z.number(),
|
initialValue: z.number(),
|
||||||
|
isLogScale: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const createmarket = newEndpoint(['POST'], async (req, auth) => {
|
export const createmarket = newEndpoint(['POST'], async (req, auth) => {
|
||||||
const { question, description, tags, closeTime, outcomeType, groupId } =
|
const { question, description, tags, closeTime, outcomeType, groupId } =
|
||||||
validate(bodySchema, req.body)
|
validate(bodySchema, req.body)
|
||||||
|
|
||||||
let min, max, initialProb
|
let min, max, initialProb, isLogScale
|
||||||
|
|
||||||
if (outcomeType === 'PSEUDO_NUMERIC' || outcomeType === 'NUMERIC') {
|
if (outcomeType === 'PSEUDO_NUMERIC' || outcomeType === 'NUMERIC') {
|
||||||
let initialValue
|
let initialValue
|
||||||
;({ min, max, initialValue } = validate(numericSchema, req.body))
|
;({ min, max, initialValue, isLogScale } = validate(
|
||||||
|
numericSchema,
|
||||||
|
req.body
|
||||||
|
))
|
||||||
if (max - min <= 0.01 || initialValue < min || initialValue > max)
|
if (max - min <= 0.01 || initialValue < min || initialValue > max)
|
||||||
throw new APIError(400, 'Invalid range.')
|
throw new APIError(400, 'Invalid range.')
|
||||||
|
|
||||||
initialProb = (initialValue - min) / (max - min) * 100
|
initialProb = ((initialValue - min) / (max - min)) * 100
|
||||||
}
|
}
|
||||||
if (outcomeType === 'BINARY') {
|
if (outcomeType === 'BINARY') {
|
||||||
;({ initialProb } = validate(binarySchema, req.body))
|
;({ initialProb } = validate(binarySchema, req.body))
|
||||||
|
|
@ -127,7 +131,8 @@ export const createmarket = newEndpoint(['POST'], async (req, auth) => {
|
||||||
tags ?? [],
|
tags ?? [],
|
||||||
NUMERIC_BUCKET_COUNT,
|
NUMERIC_BUCKET_COUNT,
|
||||||
min ?? 0,
|
min ?? 0,
|
||||||
max ?? 0
|
max ?? 0,
|
||||||
|
isLogScale ?? false
|
||||||
)
|
)
|
||||||
|
|
||||||
if (ante) await chargeUser(user.id, ante, true)
|
if (ante) await chargeUser(user.id, ante, true)
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,12 @@ export function NewContract(props: { question: string; groupId?: string }) {
|
||||||
|
|
||||||
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
||||||
const [initialProb] = useState(50)
|
const [initialProb] = useState(50)
|
||||||
|
|
||||||
const [minString, setMinString] = useState('')
|
const [minString, setMinString] = useState('')
|
||||||
const [maxString, setMaxString] = useState('')
|
const [maxString, setMaxString] = useState('')
|
||||||
|
const [isLogScale, setIsLogScale] = useState(false)
|
||||||
const [initialValueString, setInitialValueString] = useState('')
|
const [initialValueString, setInitialValueString] = useState('')
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -174,6 +177,7 @@ export function NewContract(props: { question: string; groupId?: string }) {
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
initialValue,
|
initialValue,
|
||||||
|
isLogScale,
|
||||||
groupId: selectedGroup?.id,
|
groupId: selectedGroup?.id,
|
||||||
tags: category ? [category] : undefined,
|
tags: category ? [category] : undefined,
|
||||||
})
|
})
|
||||||
|
|
@ -260,12 +264,36 @@ export function NewContract(props: { question: string; groupId?: string }) {
|
||||||
placeholder="MAX"
|
placeholder="MAX"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
onChange={(e) => setMaxString(e.target.value)}
|
onChange={(e) => setMaxString(e.target.value)}
|
||||||
|
onBlur={() => {
|
||||||
|
if (min === undefined || max === undefined) return
|
||||||
|
const lengthDiff = Math.abs(
|
||||||
|
maxString.length - minString.length
|
||||||
|
)
|
||||||
|
if (lengthDiff > 2) {
|
||||||
|
setIsLogScale(true)
|
||||||
|
}
|
||||||
|
}}
|
||||||
min={Number.MIN_SAFE_INTEGER}
|
min={Number.MIN_SAFE_INTEGER}
|
||||||
max={Number.MAX_SAFE_INTEGER}
|
max={Number.MAX_SAFE_INTEGER}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
value={maxString}
|
value={maxString}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
<Row className="mt-1 ml-2 mb-2 items-center">
|
||||||
|
<span className="mr-2 text-sm">Log scale</span>{' '}
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={isLogScale}
|
||||||
|
onChange={() => setIsLogScale(!isLogScale)}
|
||||||
|
/>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
{min !== undefined && max !== undefined && min >= max && (
|
||||||
|
<div className="mt-2 mb-2 text-sm text-red-500">
|
||||||
|
The maximum value must be greater than the minimum.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="form-control mb-2 items-start">
|
<div className="form-control mb-2 items-start">
|
||||||
<label className="label gap-2">
|
<label className="label gap-2">
|
||||||
|
|
@ -285,6 +313,16 @@ export function NewContract(props: { question: string; groupId?: string }) {
|
||||||
value={initialValueString ?? ''}
|
value={initialValueString ?? ''}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
{initialValue !== undefined &&
|
||||||
|
min !== undefined &&
|
||||||
|
max !== undefined &&
|
||||||
|
min < max &&
|
||||||
|
(initialValue < min || initialValue > max) && (
|
||||||
|
<div className="mt-2 mb-2 text-sm text-red-500">
|
||||||
|
Initial value must be in between {min} and {max}.{' '}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user