From ca8420d61be323b3317a27484bbca1dfa1b6d770 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Fri, 29 Apr 2022 07:34:36 -0600 Subject: [PATCH] Allow free daily market with M-zsh --- functions/src/create-contract.ts | 19 +++++++++---------- web/pages/create.tsx | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index e45e7497..781337f7 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -72,11 +72,19 @@ export const createContract = functions return { status: 'error', message: 'Invalid initial probability' } const ante = FIXED_ANTE // data.ante + // uses utc time on server: + const today = new Date().setHours(0, 0, 0, 0) + const userContractsCreatedTodaySnapshot = await firestore + .collection(`contracts`) + .where('creatorId', '==', userId) + .where('createdTime', '>=', today) + .get() + const isFree = userContractsCreatedTodaySnapshot.size === 0 if ( ante === undefined || ante < MINIMUM_ANTE || - ante > creator.balance || + (ante > creator.balance && !isFree) || isNaN(ante) || !isFinite(ante) ) @@ -108,15 +116,6 @@ export const createContract = functions tags ?? [] ) - // uses utc time on server: - const today = new Date().setHours(0, 0, 0, 0) - const userContractsCreatedTodaySnapshot = await firestore - .collection(`contracts`) - .where('creatorId', '==', userId) - .where('createdTime', '>=', today) - .get() - const isFree = userContractsCreatedTodaySnapshot.size === 0 - if (!isFree && ante) await chargeUser(creator.id, ante) await contractRef.create(contract) diff --git a/web/pages/create.tsx b/web/pages/create.tsx index 68a92260..ab614167 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -99,7 +99,7 @@ export function NewContract(props: { question: string; tag?: string }) { ante !== undefined && ante !== null && ante >= MINIMUM_ANTE && - ante <= balance && + (ante <= balance || deservesDailyFreeMarket) && // closeTime must be in the future closeTime && closeTime > Date.now()