Add bet amount and outcome to new comment email

This commit is contained in:
James Grugett 2022-02-23 18:52:19 -06:00
parent 9b98c6f300
commit dcd3bc759a
3 changed files with 25 additions and 6 deletions

View File

@ -285,7 +285,6 @@
font-size: 14px;
margin: 0;
padding: 5px 0;
font-weight: bold;
"
valign="top"
>
@ -302,7 +301,10 @@
"
alt=""
/>
{{commentorName}}
<span style="font-weight: bold"
>{{commentorName}}</span
>
{{betDescription}}
</div>
</td>
</tr>

View File

@ -1,5 +1,6 @@
import _ = require('lodash')
import { Answer } from '../../common/answer'
import { Bet } from '../../common/bet'
import { getProbability } from '../../common/calculate'
import { Comment } from '../../common/comment'
import { Contract } from '../../common/contract'
@ -21,7 +22,7 @@ type market_resolved_template = {
const toDisplayResolution = (
outcome: string,
prob: number,
prob?: number,
resolutions?: { [outcome: string]: number }
) => {
if (outcome === 'MKT' && resolutions) return 'MULTI'
@ -30,7 +31,7 @@ const toDisplayResolution = (
YES: 'YES',
NO: 'NO',
CANCEL: 'N/A',
MKT: formatPercent(prob),
MKT: formatPercent(prob ?? 0),
}[outcome]
return display === undefined ? `#${outcome}` : display
@ -144,8 +145,9 @@ export const sendMarketCloseEmail = async (
export const sendNewCommentEmail = async (
userId: string,
commentCreator: User,
contract: Contract,
comment: Comment,
contract: Contract
bet: Bet
) => {
const privateUser = await getPrivateUser(userId)
if (
@ -165,6 +167,11 @@ export const sendNewCommentEmail = async (
const { name: commentorName, avatarUrl: commentorAvatarUrl } = commentCreator
const { text } = comment
const { amount, sale, outcome } = bet
const betDescription = `${sale ? 'sold' : 'bought'} M$ ${Math.round(
amount
)} of ${toDisplayResolution(outcome)}`
const subject = `Comment on ${question}`
const from = `${commentorName} <info@manifold.markets>`
@ -178,6 +185,7 @@ export const sendNewCommentEmail = async (
comment: text,
marketUrl,
unsubscribeUrl,
betDescription,
},
{ from }
)

View File

@ -5,6 +5,7 @@ import * as _ from 'lodash'
import { getContract, getUser, getValues } from './utils'
import { Comment } from '../../common/comment'
import { sendNewCommentEmail } from './emails'
import { Bet } from '../../common/bet'
const firestore = admin.firestore()
@ -23,6 +24,14 @@ export const onCreateComment = functions.firestore
const commentCreator = await getUser(comment.userId)
if (!commentCreator) return
const betSnapshot = await firestore
.collection('contracts')
.doc(contractId)
.collection('bets')
.doc(comment.betId)
.get()
const bet = betSnapshot.data() as Bet
const comments = await getValues<Comment>(
firestore.collection('contracts').doc(contractId).collection('comments')
)
@ -34,7 +43,7 @@ export const onCreateComment = functions.firestore
await Promise.all(
recipientUserIds.map((userId) =>
sendNewCommentEmail(userId, commentCreator, comment, contract)
sendNewCommentEmail(userId, commentCreator, contract, comment, bet)
)
)
})