Fix build error from merge. Extract resolution emails to function

This commit is contained in:
jahooma 2022-01-01 19:13:30 -06:00
parent 5890b74225
commit 0950a281f2
2 changed files with 31 additions and 16 deletions

View File

@ -8,7 +8,7 @@ export const sendMarketResolutionEmail = async (
payout: number,
creator: User,
contract: Contract,
resolution: 'YES' | 'NO' | 'CANCEL'
resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT'
) => {
const user = await getUser(userId)
if (!user) return
@ -32,4 +32,4 @@ https://mantic.markets/${creator.username}/${contract.slug}
await sendEmail(user.email, subject, body)
}
const toDisplayResolution = { YES: 'YES', NO: 'NO', CANCEL: 'N/A' }
const toDisplayResolution = { YES: 'YES', NO: 'NO', CANCEL: 'N/A', MKT: 'MKT' }

View File

@ -16,7 +16,7 @@ export const resolveMarket = functions
.https.onCall(
async (
data: {
outcome: 'YES' | 'NO' | 'CANCEL'
outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT'
contractId: string
},
context
@ -82,25 +82,40 @@ export const resolveMarket = functions
.catch((e) => ({ status: 'error', message: e }))
.then(() => ({ status: 'success' }))
const activeBets = bets.filter((bet) => !bet.isSold && !bet.sale)
const nonWinners = _.difference(
_.uniq(activeBets.map(({ userId }) => userId)),
Object.keys(userPayouts)
)
const emailPayouts = [
...Object.entries(userPayouts),
...nonWinners.map((userId) => [userId, 0] as const),
]
await Promise.all(
emailPayouts.map(([userId, payout]) =>
sendMarketResolutionEmail(userId, payout, creator, contract, outcome)
)
await sendResolutionEmails(
openBets,
userPayouts,
creator,
contract,
outcome
)
return result
}
)
const sendResolutionEmails = async (
openBets: Bet[],
userPayouts: { [userId: string]: number },
creator: User,
contract: Contract,
outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT'
) => {
const nonWinners = _.difference(
_.uniq(openBets.map(({ userId }) => userId)),
Object.keys(userPayouts)
)
const emailPayouts = [
...Object.entries(userPayouts),
...nonWinners.map((userId) => [userId, 0] as const),
]
await Promise.all(
emailPayouts.map(([userId, payout]) =>
sendMarketResolutionEmail(userId, payout, creator, contract, outcome)
)
)
}
const firestore = admin.firestore()
const getCancelPayouts = (truePool: number, bets: Bet[]) => {