diff --git a/functions/src/email-templates/weekly-portfolio-update.html b/functions/src/email-templates/weekly-portfolio-update.html index 909c1a92..ca3fa749 100644 --- a/functions/src/email-templates/weekly-portfolio-update.html +++ b/functions/src/email-templates/weekly-portfolio-update.html @@ -261,7 +261,7 @@
{{investment_value}} -
+
{{investment_change}}
@@ -317,7 +317,7 @@{{question1Prob}} -
+
{{question1Change}}
@@ -335,7 +335,7 @@{{question2Prob}} -
+
{{question2Change}}
@@ -353,7 +353,7 @@{{question3Prob}} -
+
{{question3Change}}
@@ -371,7 +371,7 @@{{question4Prob}} -
+
{{question4Change}}
diff --git a/functions/src/emails.ts b/functions/src/emails.ts index c7d286cc..298e5ef8 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -23,7 +23,7 @@ import { import { PerContractInvestmentsData, OverallPerformanceData, -} from './weekly-profit-loss-emails' +} from 'functions/src/weekly-portfolio-emails' export const sendMarketResolutionEmail = async ( reason: notification_reason_types, @@ -642,6 +642,7 @@ export const sendWeeklyPortfolioUpdateEmail = async ( 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}ChangeStyle`] = investment.questionChangeStyle }) await sendTemplateEmail( diff --git a/functions/src/index.ts b/functions/src/index.ts index 47b1aaef..336cb4ad 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -30,7 +30,7 @@ export * from './reset-betting-streaks' export * from './reset-weekly-emails-flag' export * from './on-update-contract-follow' export * from './on-update-like' -export * from './weekly-profit-loss-emails' +export * from './weekly-portfolio-emails' // v2 export * from './health' diff --git a/functions/src/test-scheduled-function.ts b/functions/src/test-scheduled-function.ts index 6b64e0cd..423206f7 100644 --- a/functions/src/test-scheduled-function.ts +++ b/functions/src/test-scheduled-function.ts @@ -1,5 +1,5 @@ import { APIError, newEndpoint } from './api' -import { sendPortfolioUpdateEmailsToAllUsers } from './weekly-profit-loss-emails' +import { sendPortfolioUpdateEmailsToAllUsers } from './weekly-portfolio-emails' import { isProd } from './utils' export const testscheduledfunction = newEndpoint( diff --git a/functions/src/weekly-profit-loss-emails.ts b/functions/src/weekly-portfolio-emails.ts similarity index 91% rename from functions/src/weekly-profit-loss-emails.ts rename to functions/src/weekly-portfolio-emails.ts index 3721cd12..c3da79ef 100644 --- a/functions/src/weekly-profit-loss-emails.ts +++ b/functions/src/weekly-portfolio-emails.ts @@ -3,7 +3,6 @@ import * as admin from 'firebase-admin' import { Contract, CPMMContract } from '../../common/contract' import { - getAllPrivateUsers, getPrivateUser, getUser, getValue, @@ -36,7 +35,8 @@ const firestore = admin.firestore() export async function sendPortfolioUpdateEmailsToAllUsers() { const privateUsers = isProd() - ? await getAllPrivateUsers() + ? // ? await getAllPrivateUsers() + filterDefined([await getPrivateUser('AJwLWoo3xue32XIiAVrL5SyR1WB2')]) : filterDefined([await getPrivateUser('6hHpzvRG0pMq8PNJs7RZj2qlZGn2')]) // get all users that haven't unsubscribed from weekly emails const privateUsersToSendEmailsTo = privateUsers @@ -152,15 +152,15 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { log('No portfolio metrics a week ago for user', privateUser.id) return } + const valueChange = + mostRecentPortfolioMetrics.investmentValue - + portfolioMetricsAWeekAgo.investmentValue // get the difference const performanceData = { investment_value: formatMoney( mostRecentPortfolioMetrics.investmentValue ), - investment_change: formatMoney( - portfolioMetricsAWeekAgo.investmentValue - - mostRecentPortfolioMetrics.investmentValue - ), + investment_change: formatMoney(valueChange), current_balance: formatMoney(user.balance), markets_created: usersToContractsCreated[privateUser.id].length.toString(), @@ -174,6 +174,9 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { unique_bettors: usersToTxnsReceived[privateUser.id] .filter((txn) => txn.category === 'UNIQUE_BETTOR_BONUS') .length.toString(), + investment_change_style: `font-size:14px;display: inline; padding: 2px; border-radius: 5px; background-color: ${ + valueChange > 0 ? 'rgba(0,160,0,0.2)' : 'rgba(160,0,0,0.2)' + };`, // More options: bonuses, tips given, } as OverallPerformanceData type investmentDiff = { @@ -219,6 +222,11 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { Math.round( (currentMarketProbability - marketProbabilityAWeekAgo) * 100 ) + '%', + questionChangeStyle: `font-size:14px;display: inline; padding: 2px; border-radius: 5px; background-color: ${ + currentMarketProbability > marketProbabilityAWeekAgo + ? 'rgba(0,160,0,0.2)' + : 'rgba(160,0,0,0.2)' + };`, } }) ), @@ -265,8 +273,10 @@ export type PerContractInvestmentsData = { questionUrl: string questionProb: string questionChange: string + questionChangeStyle: string } export type OverallPerformanceData = { + investment_change_style: string investment_value: string investment_change: string current_balance: string