Redeem shares of makers after matching with limit bets

This commit is contained in:
James Grugett 2022-07-13 12:51:19 -05:00
parent f1eea66588
commit 50eee33a6e

View File

@ -144,13 +144,20 @@ export const placebet = newEndpoint({}, async (req, auth) => {
) )
log('Updated contract properties.') log('Updated contract properties.')
return { betId: betDoc.id } return { betId: betDoc.id, makers }
}) })
log('Main transaction finished.') log('Main transaction finished.')
await redeemShares(auth.uid, contractId) await redeemShares(auth.uid, contractId)
const userIds = [
auth.uid,
...(result.makers ?? []).map((maker) => maker.bet.userId),
]
await Promise.all(userIds.map((userId) => redeemShares(userId, contractId)))
log('Share redemption transaction finished.') log('Share redemption transaction finished.')
return result
return { betId: result.betId }
}) })
const firestore = admin.firestore() const firestore = admin.firestore()