Weekly => daily loans

This commit is contained in:
James Grugett 2022-08-24 22:03:07 -05:00
parent 0caa5e24e8
commit cffd5dcd31
4 changed files with 20 additions and 15 deletions

View File

@ -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 = (

View File

@ -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!')

View File

@ -11,11 +11,12 @@ export function LoansModal(props: {
<Modal open={isOpen} setOpen={setOpen}>
<Col className="items-center gap-4 rounded-md bg-white px-8 py-6">
<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'}>
<span className={'text-indigo-700'}> What are loans?</span>
<span className={'text-indigo-700'}> What are daily loans?</span>
<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 className={'text-indigo-700'}>
Do I have to pay back a loan?
@ -33,12 +34,12 @@ export function LoansModal(props: {
</span>
<span className={'text-indigo-700'}> What is an example?</span>
<span className={'ml-2'}>
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.
</span>
<span className={'ml-2'}>
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.
</span>
</Col>
</Col>

View File

@ -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 =