Show investment in market resolve email

This commit is contained in:
James Grugett 2022-02-24 01:04:24 -06:00
parent 64223e5ff1
commit db541cb63b
3 changed files with 37 additions and 2 deletions

View File

@ -437,6 +437,28 @@
margin: 0; margin: 0;
" "
/> />
Your investment was
<span style="font-weight: bold"
>M$ {{investment}}</span
>.
<br
style="
font-family: 'Helvetica Neue', Helvetica,
Arial, sans-serif;
box-sizing: border-box;
font-size: 16px;
margin: 0;
"
/>
<br
style="
font-family: 'Helvetica Neue', Helvetica,
Arial, sans-serif;
box-sizing: border-box;
font-size: 16px;
margin: 0;
"
/>
Your payout is Your payout is
<span style="font-weight: bold" <span style="font-weight: bold"
>M$ {{payout}}</span >M$ {{payout}}</span

View File

@ -16,6 +16,7 @@ type market_resolved_template = {
creatorName: string creatorName: string
question: string question: string
outcome: string outcome: string
investment: string
payout: string payout: string
url: string url: string
} }
@ -39,6 +40,7 @@ const toDisplayResolution = (
export const sendMarketResolutionEmail = async ( export const sendMarketResolutionEmail = async (
userId: string, userId: string,
investment: number,
payout: number, payout: number,
creator: User, creator: User,
contract: Contract, contract: Contract,
@ -69,6 +71,7 @@ export const sendMarketResolutionEmail = async (
creatorName: creator.name, creatorName: creator.name,
question: contract.question, question: contract.question,
outcome, outcome,
investment: `${Math.round(investment)}`,
payout: `${Math.round(payout)}`, payout: `${Math.round(payout)}`,
url: `https://manifold.markets/${creator.username}/${contract.slug}`, url: `https://manifold.markets/${creator.username}/${contract.slug}`,
} }

View File

@ -134,14 +134,24 @@ const sendResolutionEmails = async (
_.uniq(openBets.map(({ userId }) => userId)), _.uniq(openBets.map(({ userId }) => userId)),
Object.keys(userPayouts) Object.keys(userPayouts)
) )
const investedByUser = _.mapValues(
_.groupBy(openBets, (bet) => bet.userId),
(bets) => _.sumBy(bets, (bet) => bet.amount)
)
const emailPayouts = [ const emailPayouts = [
...Object.entries(userPayouts), ...Object.entries(userPayouts),
...nonWinners.map((userId) => [userId, 0] as const), ...nonWinners.map((userId) => [userId, 0] as const),
] ].map(([userId, payout]) => ({
userId,
investment: investedByUser[userId],
payout,
}))
await Promise.all( await Promise.all(
emailPayouts.map(([userId, payout]) => emailPayouts.map(({ userId, investment, payout }) =>
sendMarketResolutionEmail( sendMarketResolutionEmail(
userId, userId,
investment,
payout, payout,
creator, creator,
contract, contract,