Check creator balance again upon acceptance

This commit is contained in:
Ian Philips 2022-08-05 05:03:47 -06:00
parent f3704633ee
commit d90901b4e3

View File

@ -47,7 +47,7 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => {
const creatorDoc = firestore.doc(`users/${challenge.creatorId}`)
const creatorSnap = await trans.get(creatorDoc)
if (!creatorSnap.exists) throw new APIError(400, 'User not found.')
if (!creatorSnap.exists) throw new APIError(400, 'Creator not found.')
const creator = creatorSnap.data() as User
const {
@ -61,6 +61,9 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => {
if (user.balance < acceptorAmount)
throw new APIError(400, 'Insufficient balance.')
if (creator.balance < creatorAmount)
throw new APIError(400, 'Creator has insufficient balance.')
const contract = anyContract as CPMMBinaryContract
const shares = (1 / creatorOutcomeProb) * creatorAmount
const createdTime = Date.now()