diff --git a/common/util/format.ts b/common/util/format.ts index 4f123535..5a8ad41e 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -7,9 +7,13 @@ const formatter = new Intl.NumberFormat('en-US', { minimumFractionDigits: 0, }) -export function formatMoney(amount: number) { +export function formatMoney(amount: number, explicitPositiveSign?: boolean) { const newAmount = Math.round(amount) === 0 ? 0 : Math.floor(amount) // handle -0 case - return ENV_CONFIG.moneyMoniker + formatter.format(newAmount).replace('$', '') + return ( + (explicitPositiveSign && newAmount > 0 ? '+' : '') + + ENV_CONFIG.moneyMoniker + + formatter.format(newAmount).replace('$', '') + ) } export function formatMoneyWithDecimals(amount: number) { diff --git a/functions/src/email-templates/weekly-portfolio-update.html b/functions/src/email-templates/weekly-portfolio-update.html index ca3fa749..53474677 100644 --- a/functions/src/email-templates/weekly-portfolio-update.html +++ b/functions/src/email-templates/weekly-portfolio-update.html @@ -31,7 +31,7 @@ } th {color:#000000; font-size:14px;} th, td {padding: 5px; } - td{ font-size: 20px} + td{ font-size: 17px} th, td { vertical-align: center; text-align: center } a { vertical-align: center; text-align: left} img { @@ -47,6 +47,15 @@ display: block; margin: 13px 0; } + p.change{ + margin: 0; vertical-align: middle;font-size:16px;display: inline; padding: 2px; border-radius: 5px; + } + p.prob{ + font-size: 20px;display: inline; vertical-align: middle; + } + a.question{ + font-size: 18px;display: inline; vertical-align: middle; padding-bottom: 25px; + } -

{{investment_value}} -

+

{{investment_change}}

-

{{current_balance}} +

{{tips_received}} +

+ {{markets_created}} @@ -308,16 +317,16 @@ - + {{question1Title}} -

+

{{question1Prob}} -

+

{{question1Change}}

@@ -326,16 +335,16 @@ - + {{question2Title}} -

+

{{question2Prob}} -

+

{{question2Change}}

@@ -344,16 +353,16 @@ - + {{question3Title}} -

+

{{question3Prob}} -

+

{{question3Change}}

@@ -362,16 +371,16 @@ - + {{question4Title}} -

+

{{question4Prob}} -

+

{{question4Change}}

diff --git a/functions/src/weekly-portfolio-emails.ts b/functions/src/weekly-portfolio-emails.ts index c3da79ef..2f3ea7d2 100644 --- a/functions/src/weekly-portfolio-emails.ts +++ b/functions/src/weekly-portfolio-emails.ts @@ -155,26 +155,28 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { const valueChange = mostRecentPortfolioMetrics.investmentValue - portfolioMetricsAWeekAgo.investmentValue + const totalTips = sum( + usersToTxnsReceived[privateUser.id] + .filter((txn) => txn.category === 'TIP') + .map((txn) => txn.amount) + ) // get the difference const performanceData = { investment_value: formatMoney( mostRecentPortfolioMetrics.investmentValue ), - investment_change: formatMoney(valueChange), + investment_change: formatMoney(valueChange, true), current_balance: formatMoney(user.balance), markets_created: usersToContractsCreated[privateUser.id].length.toString(), - tips_received: formatMoney( - sum( - usersToTxnsReceived[privateUser.id] - .filter((txn) => txn.category === 'TIP') - .map((txn) => txn.amount) - ) - ), + tips_received: formatMoney(totalTips, true), + tips_received_style: `background-color: ${ + totalTips > 0 ? 'rgba(0,160,0,0.2)' : 'rgba(160,0,0,0.2)' + };`, 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: ${ + investment_change_style: `background-color: ${ valueChange > 0 ? 'rgba(0,160,0,0.2)' : 'rgba(160,0,0,0.2)' };`, // More options: bonuses, tips given, @@ -209,6 +211,8 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { contract, currentMarketProbability ) + const marketChange = + currentMarketProbability - marketProbabilityAWeekAgo return { currentValue: currentBetsValue, pastValue: betsValueAWeekAgo, @@ -219,13 +223,13 @@ export async function sendPortfolioUpdateEmailsToAllUsers() { questionUrl: contractUrl(contract), questionProb: Math.round(cpmmContract.prob * 100) + '%', questionChange: - Math.round( - (currentMarketProbability - marketProbabilityAWeekAgo) * 100 - ) + '%', - questionChangeStyle: `font-size:14px;display: inline; padding: 2px; border-radius: 5px; background-color: ${ + (marketChange > 0 ? '+' : '') + + Math.round(marketChange * 100) + + '%', + questionChangeStyle: `color: ${ currentMarketProbability > marketProbabilityAWeekAgo - ? 'rgba(0,160,0,0.2)' - : 'rgba(160,0,0,0.2)' + ? 'rgba(0,160,0,1)' + : '#a80000' };`, } }) @@ -276,6 +280,7 @@ export type PerContractInvestmentsData = { questionChangeStyle: string } export type OverallPerformanceData = { + tips_received_style: string investment_change_style: string investment_value: string investment_change: string