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' } return { status: 'error', message: 'Invalid initial probability' }
const ante = FIXED_ANTE // data.ante 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 ( if (
ante === undefined || ante === undefined ||
ante < MINIMUM_ANTE || ante < MINIMUM_ANTE ||
ante > creator.balance || (ante > creator.balance && !isFree) ||
isNaN(ante) || isNaN(ante) ||
!isFinite(ante) !isFinite(ante)
) )
@ -108,15 +116,6 @@ export const createContract = functions
tags ?? [] 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) if (!isFree && ante) await chargeUser(creator.id, ante)
await contractRef.create(contract) await contractRef.create(contract)

View File

@ -99,7 +99,7 @@ export function NewContract(props: { question: string; tag?: string }) {
ante !== undefined && ante !== undefined &&
ante !== null && ante !== null &&
ante >= MINIMUM_ANTE && ante >= MINIMUM_ANTE &&
ante <= balance && (ante <= balance || deservesDailyFreeMarket) &&
// closeTime must be in the future // closeTime must be in the future
closeTime && closeTime &&
closeTime > Date.now() closeTime > Date.now()