Only check stats if mana limit set

This commit is contained in:
Ian Philips 2022-05-09 10:05:53 -04:00
parent 9eabd1a3e8
commit b10e0b31e2

View File

@ -77,12 +77,13 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
if (!answerSnap.exists) if (!answerSnap.exists)
return { status: 'error', message: 'Invalid contract' } return { status: 'error', message: 'Invalid contract' }
if (manaLimitPerUser) {
const contractMetrics = getContractBetMetrics(contract, yourBets) const contractMetrics = getContractBetMetrics(contract, yourBets)
const currentInvested = contractMetrics.currentInvested const currentInvested = contractMetrics.currentInvested
console.log('user current invested amount', currentInvested) console.log('user current invested amount', currentInvested)
console.log('mana limit:', manaLimitPerUser) console.log('mana limit:', manaLimitPerUser)
if (manaLimitPerUser && currentInvested + amount > manaLimitPerUser) { if (currentInvested + amount > manaLimitPerUser) {
const manaAllowed = manaLimitPerUser - currentInvested const manaAllowed = manaLimitPerUser - currentInvested
return { return {
status: 'error', status: 'error',
@ -90,6 +91,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
} }
} }
} }
}
const newBetDoc = firestore const newBetDoc = firestore
.collection(`contracts/${contractId}/bets`) .collection(`contracts/${contractId}/bets`)