Pass notifyFills the contract

This commit is contained in:
Ian Philips 2022-08-18 16:54:25 -06:00
parent 231ddf5be6
commit e7a033ff08

View File

@ -55,12 +55,13 @@ export const onCreateBet = functions.firestore
} }
await updateUniqueBettorsAndGiveCreatorBonus(contract, eventId, bet.userId) await updateUniqueBettorsAndGiveCreatorBonus(contract, eventId, bet.userId)
const user = await getUser(bet.userId) const bettor = await getUser(bet.userId)
if (!user) return if (!bettor) return
await notifyFills(bet, contractId, eventId, user)
await updateBettingStreak(user, bet, contract, eventId)
await firestore.collection('users').doc(user.id).update({ lastBetTime }) await notifyFills(bet, contract, eventId, bettor)
await updateBettingStreak(bettor, bet, contract, eventId)
await firestore.collection('users').doc(bettor.id).update({ lastBetTime })
}) })
const updateBettingStreak = async ( const updateBettingStreak = async (
@ -205,15 +206,12 @@ const updateUniqueBettorsAndGiveCreatorBonus = async (
const notifyFills = async ( const notifyFills = async (
bet: Bet, bet: Bet,
contractId: string, contract: Contract,
eventId: string, eventId: string,
user: User user: User
) => { ) => {
if (!bet.fills) return if (!bet.fills) return
const contract = await getContract(contractId)
if (!contract) return
const matchedFills = bet.fills.filter((fill) => fill.matchedBetId !== null) const matchedFills = bet.fills.filter((fill) => fill.matchedBetId !== null)
const matchedBets = ( const matchedBets = (
await Promise.all( await Promise.all(