Show api error on create contract
This commit is contained in:
parent
f32e995baa
commit
013ff1d941
|
@ -2,8 +2,8 @@ import * as admin from 'firebase-admin'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CPMMBinaryContract,
|
|
||||||
Contract,
|
Contract,
|
||||||
|
CPMMBinaryContract,
|
||||||
FreeResponseContract,
|
FreeResponseContract,
|
||||||
MAX_QUESTION_LENGTH,
|
MAX_QUESTION_LENGTH,
|
||||||
MAX_TAG_LENGTH,
|
MAX_TAG_LENGTH,
|
||||||
|
@ -97,7 +97,12 @@ export const createmarket = newEndpoint({}, async (req, auth) => {
|
||||||
initialProb = getPseudoProbability(initialValue, min, max, isLogScale) * 100
|
initialProb = getPseudoProbability(initialValue, min, max, isLogScale) * 100
|
||||||
|
|
||||||
if (initialProb < 1 || initialProb > 99)
|
if (initialProb < 1 || initialProb > 99)
|
||||||
throw new APIError(400, 'Invalid initial value.')
|
if (outcomeType === 'PSEUDO_NUMERIC')
|
||||||
|
throw new APIError(
|
||||||
|
400,
|
||||||
|
`Initial value is too ${initialProb < 1 ? 'low' : 'high'}`
|
||||||
|
)
|
||||||
|
else throw new APIError(400, 'Invalid initial probability.')
|
||||||
}
|
}
|
||||||
if (outcomeType === 'BINARY') {
|
if (outcomeType === 'BINARY') {
|
||||||
;({ initialProb } = validate(binarySchema, req.body))
|
;({ initialProb } = validate(binarySchema, req.body))
|
||||||
|
|
|
@ -180,6 +180,11 @@ export function NewContract(props: {
|
||||||
min < initialValue &&
|
min < initialValue &&
|
||||||
initialValue < max))
|
initialValue < max))
|
||||||
|
|
||||||
|
const [errorText, setErrorText] = useState<string>('')
|
||||||
|
useEffect(() => {
|
||||||
|
setErrorText('')
|
||||||
|
}, [isValid])
|
||||||
|
|
||||||
const descriptionPlaceholder =
|
const descriptionPlaceholder =
|
||||||
outcomeType === 'BINARY'
|
outcomeType === 'BINARY'
|
||||||
? `e.g. This question resolves to "YES" if they receive the majority of votes...`
|
? `e.g. This question resolves to "YES" if they receive the majority of votes...`
|
||||||
|
@ -232,6 +237,9 @@ export function NewContract(props: {
|
||||||
await router.push(contractPath(result as Contract))
|
await router.push(contractPath(result as Contract))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('error creating contract', e, (e as any).details)
|
console.error('error creating contract', e, (e as any).details)
|
||||||
|
setErrorText(
|
||||||
|
(e as any).details || (e as any).message || 'Error creating contract'
|
||||||
|
)
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,7 +421,7 @@ export function NewContract(props: {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Spacer h={6} />
|
<Spacer h={6} />
|
||||||
|
<span className={'text-error'}>{errorText}</span>
|
||||||
<Row className="items-end justify-between">
|
<Row className="items-end justify-between">
|
||||||
<div className="form-control mb-1 items-start">
|
<div className="form-control mb-1 items-start">
|
||||||
<label className="label mb-1 gap-2">
|
<label className="label mb-1 gap-2">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user