Fix build error from merge. Extract resolution emails to function
This commit is contained in:
parent
5890b74225
commit
0950a281f2
|
@ -8,7 +8,7 @@ export const sendMarketResolutionEmail = async (
|
||||||
payout: number,
|
payout: number,
|
||||||
creator: User,
|
creator: User,
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
resolution: 'YES' | 'NO' | 'CANCEL'
|
resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT'
|
||||||
) => {
|
) => {
|
||||||
const user = await getUser(userId)
|
const user = await getUser(userId)
|
||||||
if (!user) return
|
if (!user) return
|
||||||
|
@ -32,4 +32,4 @@ https://mantic.markets/${creator.username}/${contract.slug}
|
||||||
await sendEmail(user.email, subject, body)
|
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' }
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const resolveMarket = functions
|
||||||
.https.onCall(
|
.https.onCall(
|
||||||
async (
|
async (
|
||||||
data: {
|
data: {
|
||||||
outcome: 'YES' | 'NO' | 'CANCEL'
|
outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT'
|
||||||
contractId: string
|
contractId: string
|
||||||
},
|
},
|
||||||
context
|
context
|
||||||
|
@ -82,25 +82,40 @@ export const resolveMarket = functions
|
||||||
.catch((e) => ({ status: 'error', message: e }))
|
.catch((e) => ({ status: 'error', message: e }))
|
||||||
.then(() => ({ status: 'success' }))
|
.then(() => ({ status: 'success' }))
|
||||||
|
|
||||||
const activeBets = bets.filter((bet) => !bet.isSold && !bet.sale)
|
await sendResolutionEmails(
|
||||||
const nonWinners = _.difference(
|
openBets,
|
||||||
_.uniq(activeBets.map(({ userId }) => userId)),
|
userPayouts,
|
||||||
Object.keys(userPayouts)
|
creator,
|
||||||
)
|
contract,
|
||||||
const emailPayouts = [
|
outcome
|
||||||
...Object.entries(userPayouts),
|
|
||||||
...nonWinners.map((userId) => [userId, 0] as const),
|
|
||||||
]
|
|
||||||
await Promise.all(
|
|
||||||
emailPayouts.map(([userId, payout]) =>
|
|
||||||
sendMarketResolutionEmail(userId, payout, creator, contract, outcome)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return result
|
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 firestore = admin.firestore()
|
||||||
|
|
||||||
const getCancelPayouts = (truePool: number, bets: Bet[]) => {
|
const getCancelPayouts = (truePool: number, bets: Bet[]) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user