If a limit bet doesn't match any orders, don't update the contract, don't redeem shares. Perf win!
This commit is contained in:
parent
6e1aa4b0f4
commit
a9018d77c7
|
@ -128,8 +128,10 @@ export const placebet = newEndpoint({}, async (req, auth) => {
|
||||||
updateMakers(makers, betDoc.id, contractDoc, trans)
|
updateMakers(makers, betDoc.id, contractDoc, trans)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newBet.amount !== 0) {
|
||||||
trans.update(userDoc, { balance: FieldValue.increment(-newBet.amount) })
|
trans.update(userDoc, { balance: FieldValue.increment(-newBet.amount) })
|
||||||
log('Updated user balance.')
|
log('Updated user balance.')
|
||||||
|
|
||||||
trans.update(
|
trans.update(
|
||||||
contractDoc,
|
contractDoc,
|
||||||
removeUndefinedProps({
|
removeUndefinedProps({
|
||||||
|
@ -143,19 +145,21 @@ export const placebet = newEndpoint({}, async (req, auth) => {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
log('Updated contract properties.')
|
log('Updated contract properties.')
|
||||||
|
}
|
||||||
|
|
||||||
return { betId: betDoc.id, makers }
|
return { betId: betDoc.id, makers, newBet }
|
||||||
})
|
})
|
||||||
|
|
||||||
log('Main transaction finished.')
|
log('Main transaction finished.')
|
||||||
await redeemShares(auth.uid, contractId)
|
|
||||||
|
|
||||||
|
if (result.newBet.amount !== 0) {
|
||||||
const userIds = [
|
const userIds = [
|
||||||
auth.uid,
|
auth.uid,
|
||||||
...(result.makers ?? []).map((maker) => maker.bet.userId),
|
...(result.makers ?? []).map((maker) => maker.bet.userId),
|
||||||
]
|
]
|
||||||
await Promise.all(userIds.map((userId) => redeemShares(userId, contractId)))
|
await Promise.all(userIds.map((userId) => redeemShares(userId, contractId)))
|
||||||
log('Share redemption transaction finished.')
|
log('Share redemption transaction finished.')
|
||||||
|
}
|
||||||
|
|
||||||
return { betId: result.betId }
|
return { betId: result.betId }
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user