Portfolio email ux

This commit is contained in:
Ian Philips 2022-09-29 18:13:33 -06:00
parent 262183e0e6
commit 2625ab1549
3 changed files with 16 additions and 23 deletions

View File

@ -320,7 +320,7 @@
style="line-height: 24px; margin: 10px 0; margin-top: 20px; margin-bottom: 20px;" style="line-height: 24px; margin: 10px 0; margin-top: 20px; margin-bottom: 20px;"
data-testid="4XoHRGw1Y"> data-testid="4XoHRGw1Y">
<span style="color:#000000;font-family:Arial, Helvetica, sans-serif;font-size:18px;"> <span style="color:#000000;font-family:Arial, Helvetica, sans-serif;font-size:18px;">
And here's some of the biggest changes in your portfolio: And here's some recent changes in your investments:
</span> </span>
</p> </p>
</div> </div>

View File

@ -643,13 +643,13 @@ export const sendWeeklyPortfolioUpdateEmail = async (
templateData[`question${i + 1}Title`] = investment.questionTitle templateData[`question${i + 1}Title`] = investment.questionTitle
templateData[`question${i + 1}Url`] = investment.questionUrl templateData[`question${i + 1}Url`] = investment.questionUrl
templateData[`question${i + 1}Prob`] = investment.questionProb templateData[`question${i + 1}Prob`] = investment.questionProb
templateData[`question${i + 1}Change`] = formatMoney(investment.difference) templateData[`question${i + 1}Change`] = formatMoney(investment.profit)
templateData[`question${i + 1}ChangeStyle`] = investment.questionChangeStyle templateData[`question${i + 1}ChangeStyle`] = investment.profitStyle
}) })
await sendTemplateEmail( await sendTemplateEmail(
// privateUser.email, privateUser.email,
'iansphilips@gmail.com', // 'iansphilips@gmail.com',
`Here's your weekly portfolio update!`, `Here's your weekly portfolio update!`,
investments.length === 0 investments.length === 0
? 'portfolio-update-no-movers' ? 'portfolio-update-no-movers'

View File

@ -195,15 +195,13 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
contract, contract,
betsInLastWeek betsInLastWeek
).profit ).profit
const marketChange =
currentMarketProbability - marketProbabilityAWeekAgo
const profit = const profit =
betsMadeInLastWeekProfit + betsMadeInLastWeekProfit +
(currentBetsMadeAWeekAgoValue - betsMadeAWeekAgoValue) (currentBetsMadeAWeekAgoValue - betsMadeAWeekAgoValue)
return { return {
currentValue: currentBetsMadeAWeekAgoValue, currentValue: currentBetsMadeAWeekAgoValue,
pastValue: betsMadeAWeekAgoValue, pastValue: betsMadeAWeekAgoValue,
difference: profit, profit,
contractSlug: contract.slug, contractSlug: contract.slug,
marketProbAWeekAgo: marketProbabilityAWeekAgo, marketProbAWeekAgo: marketProbabilityAWeekAgo,
questionTitle: contract.question, questionTitle: contract.question,
@ -211,17 +209,13 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
questionProb: cpmmContract.resolution questionProb: cpmmContract.resolution
? cpmmContract.resolution ? cpmmContract.resolution
: Math.round(cpmmContract.prob * 100) + '%', : Math.round(cpmmContract.prob * 100) + '%',
questionChange: profitStyle: `color: ${
(marketChange > 0 ? '+' : '') +
Math.round(marketChange * 100) +
'%',
questionChangeStyle: `color: ${
profit > 0 ? 'rgba(0,160,0,1)' : '#a80000' profit > 0 ? 'rgba(0,160,0,1)' : '#a80000'
};`, };`,
} as PerContractInvestmentsData } as PerContractInvestmentsData
}) })
), ),
(differences) => Math.abs(differences.difference) (differences) => Math.abs(differences.profit)
).reverse() ).reverse()
log( log(
@ -233,12 +227,10 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
const [winningInvestments, losingInvestments] = partition( const [winningInvestments, losingInvestments] = partition(
investmentValueDifferences.filter( investmentValueDifferences.filter(
(diff) => (diff) => diff.pastValue > 0.01 && Math.abs(diff.profit) > 1
diff.pastValue > 0.01 &&
Math.abs(diff.difference / diff.pastValue) > 0.01 // difference is greater than 1%
), ),
(investmentsData: PerContractInvestmentsData) => { (investmentsData: PerContractInvestmentsData) => {
return investmentsData.difference > 0 return investmentsData.profit > 0
} }
) )
// pick 3 winning investments and 3 losing investments // pick 3 winning investments and 3 losing investments
@ -251,7 +243,9 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
worstInvestments.length === 0 && worstInvestments.length === 0 &&
usersToContractsCreated[privateUser.id].length === 0 usersToContractsCreated[privateUser.id].length === 0
) { ) {
log('No bets in last week, no market movers, no markets created') log(
'No bets in last week, no market movers, no markets created. Not sending an email.'
)
await firestore.collection('private-users').doc(privateUser.id).update({ await firestore.collection('private-users').doc(privateUser.id).update({
weeklyPortfolioUpdateEmailSent: true, weeklyPortfolioUpdateEmailSent: true,
}) })
@ -268,7 +262,7 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
}) })
log('Sent weekly portfolio update email to', privateUser.email) log('Sent weekly portfolio update email to', privateUser.email)
count++ count++
log('sent out emails to user count:', count) log('sent out emails to users:', count)
}) })
) )
} }
@ -277,11 +271,10 @@ export type PerContractInvestmentsData = {
questionTitle: string questionTitle: string
questionUrl: string questionUrl: string
questionProb: string questionProb: string
questionChange: string profitStyle: string
questionChangeStyle: string
currentValue: number currentValue: number
pastValue: number pastValue: number
difference: number profit: number
} }
export type OverallPerformanceData = { export type OverallPerformanceData = {