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,16 +77,18 @@ 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' }
const contractMetrics = getContractBetMetrics(contract, yourBets) if (manaLimitPerUser) {
const currentInvested = contractMetrics.currentInvested const contractMetrics = getContractBetMetrics(contract, yourBets)
console.log('user current invested amount', currentInvested) const currentInvested = contractMetrics.currentInvested
console.log('mana limit:', manaLimitPerUser) console.log('user current invested amount', currentInvested)
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',
message: `Market bet cap is M$${manaLimitPerUser}, you've M$${manaAllowed} left`, message: `Market bet cap is M$${manaLimitPerUser}, you've M$${manaAllowed} left`,
}
} }
} }
} }