Weekly => daily loans

This commit is contained in:
James Grugett 2022-08-24 22:03:07 -05:00 committed by mantikoros
parent 5333f881ef
commit a7a45d1968
4 changed files with 20 additions and 15 deletions

View File

@ -10,11 +10,11 @@ import {
import { PortfolioMetrics, User } from './user' import { PortfolioMetrics, User } from './user'
import { filterDefined } from './util/array' import { filterDefined } from './util/array'
const LOAN_WEEKLY_RATE = 0.05 const LOAN_DAILY_RATE = 0.01
const calculateNewLoan = (investedValue: number, loanTotal: number) => { const calculateNewLoan = (investedValue: number, loanTotal: number) => {
const netValue = investedValue - loanTotal const netValue = investedValue - loanTotal
return netValue * LOAN_WEEKLY_RATE return netValue * LOAN_DAILY_RATE
} }
export const getLoanUpdates = ( export const getLoanUpdates = (

View File

@ -12,8 +12,8 @@ const firestore = admin.firestore()
export const updateLoans = functions export const updateLoans = functions
.runWith({ memory: '2GB', timeoutSeconds: 540 }) .runWith({ memory: '2GB', timeoutSeconds: 540 })
// Run every Monday. // Run every day at midnight.
.pubsub.schedule('0 0 * * 1') .pubsub.schedule('0 0 * * *')
.timeZone('America/Los_Angeles') .timeZone('America/Los_Angeles')
.onRun(updateLoansCore) .onRun(updateLoansCore)
@ -79,9 +79,13 @@ async function updateLoansCore() {
const today = new Date().toDateString().replace(' ', '-') const today = new Date().toDateString().replace(' ', '-')
const key = `loan-notifications-${today}` const key = `loan-notifications-${today}`
await Promise.all( await Promise.all(
userPayouts.map(({ user, payout }) => userPayouts
createLoanIncomeNotification(user, key, payout) // 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!') log('Notifications sent!')

View File

@ -11,11 +11,12 @@ export function LoansModal(props: {
<Modal open={isOpen} setOpen={setOpen}> <Modal open={isOpen} setOpen={setOpen}>
<Col className="items-center gap-4 rounded-md bg-white px-8 py-6"> <Col className="items-center gap-4 rounded-md bg-white px-8 py-6">
<span className={'text-8xl'}>🏦</span> <span className={'text-8xl'}>🏦</span>
<span className="text-xl">Loans on your bets</span> <span className="text-xl">Daily loans on your bets</span>
<Col className={'gap-2'}> <Col className={'gap-2'}>
<span className={'text-indigo-700'}> What are loans?</span> <span className={'text-indigo-700'}> What are daily loans?</span>
<span className={'ml-2'}> <span className={'ml-2'}>
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.
</span> </span>
<span className={'text-indigo-700'}> <span className={'text-indigo-700'}>
Do I have to pay back a loan? Do I have to pay back a loan?
@ -33,12 +34,12 @@ export function LoansModal(props: {
</span> </span>
<span className={'text-indigo-700'}> What is an example?</span> <span className={'text-indigo-700'}> What is an example?</span>
<span className={'ml-2'}> <span className={'ml-2'}>
For example, if you bet M$100 on "Will I become a millionare?" on For example, if you bet M$1000 on "Will I become a millionare?" on
Sunday, you will get M$5 back on Monday. Monday, you will get M$10 back on Tuesday.
</span> </span>
<span className={'ml-2'}> <span className={'ml-2'}>
Previous loans count against your total bet amount. So, the next Previous loans count against your total bet amount. So on Wednesday,
week, you would get back 5% of M$95 = M$4.75. you would get back 1% of M$990 = M$9.9.
</span> </span>
</Col> </Col>
</Col> </Col>

View File

@ -397,7 +397,7 @@ function IncomeNotificationItem(props: {
} else if (sourceType === 'betting_streak_bonus') { } else if (sourceType === 'betting_streak_bonus') {
reasonText = 'for your' reasonText = 'for your'
} else if (sourceType === 'loan' && sourceText) { } else if (sourceType === 'loan' && sourceText) {
reasonText = `of your invested bets returned as` reasonText = `of your invested bets returned as a`
} }
const bettingStreakText = const bettingStreakText =