From 770a8d049c112671f78fe6167dbf77eb4210a694 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 17 Aug 2022 10:55:47 -0500 Subject: [PATCH] Check limit prob with floating equals --- functions/src/place-bet.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index 3591598f..780b50d6 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -82,15 +82,21 @@ export const placebet = newEndpoint({}, async (req, auth) => { (outcomeType == 'BINARY' || outcomeType === 'PSEUDO_NUMERIC') && mechanism == 'cpmm-1' ) { - const { outcome, limitProb } = validate(binarySchema, req.body) + // eslint-disable-next-line prefer-const + let { outcome, limitProb } = validate(binarySchema, req.body) if (limitProb !== undefined && outcomeType === 'BINARY') { - const isRounded = Math.round(limitProb * 100) === limitProb * 100 + const isRounded = floatingEqual( + 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)' ) + + limitProb = Math.round(limitProb * 100) / 100 } const unfilledBetsSnap = await trans.get(