From ec1a9fab777769413142d8f63fa6222bf6721de4 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Thu, 29 Sep 2022 13:06:12 -0400 Subject: [PATCH] Show change in M$ --- functions/src/emails.ts | 4 ++-- functions/src/weekly-portfolio-emails.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 1c7914be..6888cfb1 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -20,7 +20,7 @@ import { getNotificationDestinationsForUser } from '../../common/user-notificati import { PerContractInvestmentsData, OverallPerformanceData, -} from 'functions/src/weekly-portfolio-emails' +} from './weekly-portfolio-emails' export const sendMarketResolutionEmail = async ( reason: notification_reason_types, @@ -643,7 +643,7 @@ export const sendWeeklyPortfolioUpdateEmail = async ( templateData[`question${i + 1}Title`] = investment.questionTitle templateData[`question${i + 1}Url`] = investment.questionUrl templateData[`question${i + 1}Prob`] = investment.questionProb - templateData[`question${i + 1}Change`] = investment.questionChange + templateData[`question${i + 1}Change`] = formatMoney(investment.difference) templateData[`question${i + 1}ChangeStyle`] = investment.questionChangeStyle }) diff --git a/functions/src/weekly-portfolio-emails.ts b/functions/src/weekly-portfolio-emails.ts index 740a0ced..198fa7ca 100644 --- a/functions/src/weekly-portfolio-emails.ts +++ b/functions/src/weekly-portfolio-emails.ts @@ -22,7 +22,6 @@ import { Txn } from '../../common/txn' import { formatMoney } from '../../common/util/format' import { getContractBetMetrics } from '../../common/calculate' -// TODO: reset weeklyPortfolioUpdateEmailSent to false for all users at the start of each week export const weeklyPortfolioUpdateEmails = functions .runWith({ secrets: ['MAILGUN_KEY'], memory: '4GB' }) // every minute on Friday for an hour at 12pm PT (UTC -07:00) @@ -179,6 +178,8 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { const currentMarketProbability = cpmmContract.resolutionProbability ? cpmmContract.resolutionProbability : cpmmContract.prob + + // TODO: returns 0 for resolved markets - doesn't include them const betsMadeAWeekAgoValue = computeInvestmentValueCustomProb( previousBets, contract, @@ -196,12 +197,13 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { ).profit const marketChange = currentMarketProbability - marketProbabilityAWeekAgo + const profit = + betsMadeInLastWeekProfit + + (currentBetsMadeAWeekAgoValue - betsMadeAWeekAgoValue) return { currentValue: currentBetsMadeAWeekAgoValue, pastValue: betsMadeAWeekAgoValue, - difference: - betsMadeInLastWeekProfit + - (currentBetsMadeAWeekAgoValue - betsMadeAWeekAgoValue), + difference: profit, contractSlug: contract.slug, marketProbAWeekAgo: marketProbabilityAWeekAgo, questionTitle: contract.question, @@ -214,9 +216,7 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { Math.round(marketChange * 100) + '%', questionChangeStyle: `color: ${ - currentMarketProbability > marketProbabilityAWeekAgo - ? 'rgba(0,160,0,1)' - : '#a80000' + profit > 0 ? 'rgba(0,160,0,1)' : '#a80000' };`, } as PerContractInvestmentsData })