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

View File

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

View File

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