Allow free daily market with M-zsh

This commit is contained in:
Ian Philips 2022-04-29 07:34:36 -06:00
parent 2ddd95e904
commit ca8420d61b
2 changed files with 10 additions and 11 deletions

View File

@ -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)

View File

@ -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()