From 814c4aa01db3fc8c69ab6808fb7af55a3a987e31 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Tue, 16 Aug 2022 15:44:58 -0500 Subject: [PATCH] Change limit prob validation to be only on Binary markets (not numeric) --- functions/src/place-bet.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index 8fb5179d..3591598f 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -30,15 +30,7 @@ const bodySchema = z.object({ const binarySchema = z.object({ outcome: z.enum(['YES', 'NO']), - limitProb: z - .number() - .gte(0.001) - .lte(0.999) - .refine( - (p) => Math.round(p * 100) === p * 100, - 'limitProb must be in increments of 0.01 (i.e. whole percentage points)' - ) - .optional(), + limitProb: z.number().gte(0.001).lte(0.999).optional(), }) const freeResponseSchema = z.object({ @@ -92,6 +84,15 @@ export const placebet = newEndpoint({}, async (req, auth) => { ) { const { outcome, limitProb } = validate(binarySchema, req.body) + if (limitProb !== undefined && outcomeType === 'BINARY') { + const isRounded = Math.round(limitProb * 100) === limitProb * 100 + if (!isRounded) + throw new APIError( + 400, + 'limitProb must be in increments of 0.01 (i.e. whole percentage points)' + ) + } + const unfilledBetsSnap = await trans.get( getUnfilledBetsQuery(contractDoc) )