2022-01-30 21:51:30 +00:00
|
|
|
import { getProbability } from '../../common/calculate'
|
2022-01-10 21:07:57 +00:00
|
|
|
import { Contract } from '../../common/contract'
|
2022-02-08 11:26:33 +00:00
|
|
|
import { PrivateUser, User } from '../../common/user'
|
2022-01-30 21:51:30 +00:00
|
|
|
import { formatPercent } from '../../common/util/format'
|
2022-02-08 11:26:33 +00:00
|
|
|
import { sendTemplateEmail, sendTextEmail } from './send-email'
|
2022-01-19 03:36:46 +00:00
|
|
|
import { getPrivateUser, getUser } from './utils'
|
2022-01-02 00:08:52 +00:00
|
|
|
|
2022-01-10 22:07:44 +00:00
|
|
|
type market_resolved_template = {
|
2022-01-19 18:43:12 +00:00
|
|
|
userId: string
|
2022-01-10 22:07:44 +00:00
|
|
|
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-30 21:51:30 +00:00
|
|
|
resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT',
|
|
|
|
resolutionProbability?: number
|
2022-01-02 00:08:52 +00:00
|
|
|
) => {
|
2022-01-19 03:36:46 +00:00
|
|
|
const privateUser = await getPrivateUser(userId)
|
|
|
|
if (
|
|
|
|
!privateUser ||
|
|
|
|
privateUser.unsubscribedFromResolutionEmails ||
|
|
|
|
!privateUser.email
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
2022-01-02 00:08:52 +00:00
|
|
|
const user = await getUser(userId)
|
|
|
|
if (!user) return
|
|
|
|
|
2022-01-30 21:51:30 +00:00
|
|
|
const prob = resolutionProbability ?? getProbability(contract.totalShares)
|
|
|
|
|
|
|
|
const toDisplayResolution = {
|
|
|
|
YES: 'YES',
|
|
|
|
NO: 'NO',
|
|
|
|
CANCEL: 'N/A',
|
|
|
|
MKT: formatPercent(prob),
|
|
|
|
}
|
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 = {
|
2022-01-19 18:43:12 +00:00
|
|
|
userId: user.id,
|
2022-01-10 22:07:44 +00:00
|
|
|
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-19 03:36:46 +00:00
|
|
|
await sendTemplateEmail(
|
|
|
|
privateUser.email,
|
|
|
|
subject,
|
|
|
|
'market-resolved',
|
|
|
|
templateData
|
|
|
|
)
|
2022-01-02 00:08:52 +00:00
|
|
|
}
|
2022-02-08 11:26:33 +00:00
|
|
|
|
|
|
|
export const sendWelcomeEmail = async (
|
|
|
|
user: User,
|
|
|
|
privateUser: PrivateUser
|
|
|
|
) => {
|
|
|
|
const firstName = user.name.split(' ')[0]
|
|
|
|
|
|
|
|
await sendTextEmail(
|
|
|
|
privateUser.email || '',
|
|
|
|
'Welcome to Manifold Markets!',
|
|
|
|
`Hi ${firstName},
|
|
|
|
|
|
|
|
Thanks for joining us! We can't wait to see what markets you create.
|
|
|
|
Questions? Feedback? I'd love to hear from you - just reply to this email!
|
|
|
|
Or come chat with us on Discord: https://discord.gg/eHQBNBqXuh
|
|
|
|
|
|
|
|
Best,
|
|
|
|
Austin from Manifold`
|
|
|
|
)
|
|
|
|
}
|