diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index d58141a5..a30d508d 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -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)) diff --git a/web/pages/create.tsx b/web/pages/create.tsx index ec86a277..5e50bbbb 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -180,6 +180,11 @@ export function NewContract(props: { min < initialValue && initialValue < max)) + const [errorText, setErrorText] = useState('') + 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: { - + {errorText}