From a7a45d196898869a2b2268c5ff1633f4cc9600dc Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 24 Aug 2022 22:03:07 -0500 Subject: [PATCH] Weekly => daily loans --- common/loans.ts | 4 ++-- functions/src/update-loans.ts | 14 +++++++++----- web/components/profile/loans-modal.tsx | 15 ++++++++------- web/pages/notifications.tsx | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/common/loans.ts b/common/loans.ts index 46c491b5..cb956c09 100644 --- a/common/loans.ts +++ b/common/loans.ts @@ -10,11 +10,11 @@ import { import { PortfolioMetrics, User } from './user' import { filterDefined } from './util/array' -const LOAN_WEEKLY_RATE = 0.05 +const LOAN_DAILY_RATE = 0.01 const calculateNewLoan = (investedValue: number, loanTotal: number) => { const netValue = investedValue - loanTotal - return netValue * LOAN_WEEKLY_RATE + return netValue * LOAN_DAILY_RATE } export const getLoanUpdates = ( diff --git a/functions/src/update-loans.ts b/functions/src/update-loans.ts index fd89b643..770315fd 100644 --- a/functions/src/update-loans.ts +++ b/functions/src/update-loans.ts @@ -12,8 +12,8 @@ const firestore = admin.firestore() export const updateLoans = functions .runWith({ memory: '2GB', timeoutSeconds: 540 }) - // Run every Monday. - .pubsub.schedule('0 0 * * 1') + // Run every day at midnight. + .pubsub.schedule('0 0 * * *') .timeZone('America/Los_Angeles') .onRun(updateLoansCore) @@ -79,9 +79,13 @@ async function updateLoansCore() { const today = new Date().toDateString().replace(' ', '-') const key = `loan-notifications-${today}` await Promise.all( - userPayouts.map(({ user, payout }) => - createLoanIncomeNotification(user, key, payout) - ) + userPayouts + // Don't send a notification if the payout is < M$1, + // because a M$0 loan is confusing. + .filter(({ payout }) => payout >= 1) + .map(({ user, payout }) => + createLoanIncomeNotification(user, key, payout) + ) ) log('Notifications sent!') diff --git a/web/components/profile/loans-modal.tsx b/web/components/profile/loans-modal.tsx index c8d30b4e..945fb6fe 100644 --- a/web/components/profile/loans-modal.tsx +++ b/web/components/profile/loans-modal.tsx @@ -11,11 +11,12 @@ export function LoansModal(props: { 🏦 - Loans on your bets + Daily loans on your bets - • What are loans? + • What are daily loans? - Every Monday, get 5% of your total bet amount back as a loan. + Every day at midnight PT, get 1% of your total bet amount back as a + loan. • Do I have to pay back a loan? @@ -33,12 +34,12 @@ export function LoansModal(props: { • What is an example? - For example, if you bet M$100 on "Will I become a millionare?" on - Sunday, you will get M$5 back on Monday. + For example, if you bet M$1000 on "Will I become a millionare?" on + Monday, you will get M$10 back on Tuesday. - Previous loans count against your total bet amount. So, the next - week, you would get back 5% of M$95 = M$4.75. + Previous loans count against your total bet amount. So on Wednesday, + you would get back 1% of M$990 = M$9.9. diff --git a/web/pages/notifications.tsx b/web/pages/notifications.tsx index 94ad6680..9b717af9 100644 --- a/web/pages/notifications.tsx +++ b/web/pages/notifications.tsx @@ -397,7 +397,7 @@ function IncomeNotificationItem(props: { } else if (sourceType === 'betting_streak_bonus') { reasonText = 'for your' } else if (sourceType === 'loan' && sourceText) { - reasonText = `of your invested bets returned as` + reasonText = `of your invested bets returned as a` } const bettingStreakText =