Show api error on create contract

This commit is contained in:
Ian Philips 2022-07-26 16:44:51 -07:00
parent f32e995baa
commit 013ff1d941
2 changed files with 16 additions and 3 deletions

View File

@ -2,8 +2,8 @@ import * as admin from 'firebase-admin'
import { z } from 'zod'
import {
CPMMBinaryContract,
Contract,
CPMMBinaryContract,
FreeResponseContract,
MAX_QUESTION_LENGTH,
MAX_TAG_LENGTH,
@ -97,7 +97,12 @@ export const createmarket = newEndpoint({}, async (req, auth) => {
initialProb = getPseudoProbability(initialValue, min, max, isLogScale) * 100
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') {
;({ initialProb } = validate(binarySchema, req.body))

View File

@ -180,6 +180,11 @@ export function NewContract(props: {
min < initialValue &&
initialValue < max))
const [errorText, setErrorText] = useState<string>('')
useEffect(() => {
setErrorText('')
}, [isValid])
const descriptionPlaceholder =
outcomeType === 'BINARY'
? `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))
} catch (e) {
console.error('error creating contract', e, (e as any).details)
setErrorText(
(e as any).details || (e as any).message || 'Error creating contract'
)
setIsSubmitting(false)
}
}
@ -413,7 +421,7 @@ export function NewContract(props: {
</div>
<Spacer h={6} />
<span className={'text-error'}>{errorText}</span>
<Row className="items-end justify-between">
<div className="form-control mb-1 items-start">
<label className="label mb-1 gap-2">