check if NaN when updating user balances
This commit is contained in:
parent
a150be88e2
commit
3f0002f9e8
|
@ -122,6 +122,11 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
totalBets: newTotalBets,
|
totalBets: newTotalBets,
|
||||||
answers: [...(contract.answers ?? []), answer],
|
answers: [...(contract.answers ?? []), answer],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!isFinite(newBalance)) {
|
||||||
|
throw new Error('Invalid user balance for ' + user.username)
|
||||||
|
}
|
||||||
|
|
||||||
transaction.update(userDoc, { balance: newBalance })
|
transaction.update(userDoc, { balance: newBalance })
|
||||||
|
|
||||||
return { status: 'success', answerId, betId: newBetDoc.id, answer }
|
return { status: 'success', answerId, betId: newBetDoc.id, answer }
|
||||||
|
|
|
@ -132,6 +132,10 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!isFinite(newBalance)) {
|
||||||
|
throw new Error('Invalid user balance for ' + user.username)
|
||||||
|
}
|
||||||
|
|
||||||
transaction.update(userDoc, { balance: newBalance })
|
transaction.update(userDoc, { balance: newBalance })
|
||||||
|
|
||||||
return { status: 'success', betId: newBetDoc.id }
|
return { status: 'success', betId: newBetDoc.id }
|
||||||
|
|
|
@ -78,6 +78,11 @@ export const redeemShares = async (userId: string, contractId: string) => {
|
||||||
const user = userSnap.data() as User
|
const user = userSnap.data() as User
|
||||||
|
|
||||||
const newBalance = user.balance + netAmount
|
const newBalance = user.balance + netAmount
|
||||||
|
|
||||||
|
if (!isFinite(newBalance)) {
|
||||||
|
throw new Error('Invalid user balance for ' + user.username)
|
||||||
|
}
|
||||||
|
|
||||||
transaction.update(userDoc, { balance: newBalance })
|
transaction.update(userDoc, { balance: newBalance })
|
||||||
|
|
||||||
transaction.create(yesDoc, yesBet)
|
transaction.create(yesDoc, yesBet)
|
||||||
|
|
|
@ -67,6 +67,9 @@ export const sellBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
newBetDoc.id
|
newBetDoc.id
|
||||||
) as any)
|
) as any)
|
||||||
|
|
||||||
|
if (!isFinite(newBalance)) {
|
||||||
|
throw new Error('Invalid user balance for ' + user.username)
|
||||||
|
}
|
||||||
transaction.update(userDoc, { balance: newBalance })
|
transaction.update(userDoc, { balance: newBalance })
|
||||||
|
|
||||||
transaction.update(betDoc, { isSold: true })
|
transaction.update(betDoc, { isSold: true })
|
||||||
|
|
Loading…
Reference in New Issue
Block a user