From 50eee33a6e13b1cca4e52985ace15c9c45572975 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 13 Jul 2022 12:51:19 -0500 Subject: [PATCH] Redeem shares of makers after matching with limit bets --- functions/src/place-bet.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index 3c428f43..73c60187 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -144,13 +144,20 @@ export const placebet = newEndpoint({}, async (req, auth) => { ) log('Updated contract properties.') - return { betId: betDoc.id } + return { betId: betDoc.id, makers } }) log('Main transaction finished.') 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.') - return result + + return { betId: result.betId } }) const firestore = admin.firestore()