2022-01-18 07:18:38 +00:00
|
|
|
import * as admin from 'firebase-admin'
|
|
|
|
|
2022-01-10 21:07:57 +00:00
|
|
|
import { Contract } from '../../common/contract'
|
|
|
|
import { User } from '../../common/user'
|
2022-01-10 22:07:44 +00:00
|
|
|
import { sendTemplateEmail } from './send-email'
|
2022-01-02 00:08:52 +00:00
|
|
|
import { getUser } from './utils'
|
|
|
|
|
2022-01-10 22:07:44 +00:00
|
|
|
type market_resolved_template = {
|
|
|
|
name: string
|
|
|
|
creatorName: string
|
|
|
|
question: string
|
|
|
|
outcome: string
|
|
|
|
payout: string
|
|
|
|
url: string
|
|
|
|
}
|
|
|
|
|
2022-01-02 00:08:52 +00:00
|
|
|
export const sendMarketResolutionEmail = async (
|
|
|
|
userId: string,
|
|
|
|
payout: number,
|
|
|
|
creator: User,
|
|
|
|
contract: Contract,
|
2022-01-02 01:13:30 +00:00
|
|
|
resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT'
|
2022-01-02 00:08:52 +00:00
|
|
|
) => {
|
|
|
|
const user = await getUser(userId)
|
|
|
|
if (!user) return
|
|
|
|
|
2022-01-18 07:18:38 +00:00
|
|
|
const fbUser = await admin.auth().getUser(userId)
|
|
|
|
const email = fbUser.email
|
|
|
|
if (!email) return
|
|
|
|
|
2022-01-10 22:07:44 +00:00
|
|
|
const outcome = toDisplayResolution[resolution]
|
2022-01-02 00:08:52 +00:00
|
|
|
|
2022-01-10 22:07:44 +00:00
|
|
|
const subject = `Resolved ${outcome}: ${contract.question}`
|
2022-01-02 00:08:52 +00:00
|
|
|
|
2022-01-10 22:07:44 +00:00
|
|
|
const templateData: market_resolved_template = {
|
|
|
|
name: user.name,
|
|
|
|
creatorName: creator.name,
|
|
|
|
question: contract.question,
|
|
|
|
outcome,
|
|
|
|
payout: `${Math.round(payout)}`,
|
|
|
|
url: `https://manifold.markets/${creator.username}/${contract.slug}`,
|
|
|
|
}
|
2022-01-02 00:08:52 +00:00
|
|
|
|
2022-01-10 22:07:44 +00:00
|
|
|
// Modify template here:
|
|
|
|
// https://app.mailgun.com/app/sending/domains/mg.manifold.markets/templates/edit/market-resolved/initial
|
|
|
|
// Mailgun username: james@mantic.markets
|
2022-01-02 00:08:52 +00:00
|
|
|
|
2022-01-18 07:18:38 +00:00
|
|
|
await sendTemplateEmail(email, subject, 'market-resolved', templateData)
|
2022-01-02 00:08:52 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 01:13:30 +00:00
|
|
|
const toDisplayResolution = { YES: 'YES', NO: 'NO', CANCEL: 'N/A', MKT: 'MKT' }
|