diff --git a/common/numeric-constants.ts b/common/numeric-constants.ts index 2153fb27..9d41d54f 100644 --- a/common/numeric-constants.ts +++ b/common/numeric-constants.ts @@ -4,5 +4,5 @@ export const NUMERIC_FIXED_VAR = 0.005 export const NUMERIC_GRAPH_COLOR = '#5fa5f9' export const NUMERIC_TEXT_COLOR = 'text-blue-500' export const UNIQUE_BETTOR_BONUS_AMOUNT = 10 -export const BETTING_STREAK_BONUS_AMOUNT = 1 +export const BETTING_STREAK_BONUS_AMOUNT = 5 export const BETTING_STREAK_RESET_HOUR = 9 diff --git a/functions/src/on-create-bet.ts b/functions/src/on-create-bet.ts index c258d22f..c5648293 100644 --- a/functions/src/on-create-bet.ts +++ b/functions/src/on-create-bet.ts @@ -23,7 +23,6 @@ import { } from '../../common/antes' import { APIError } from '../../common/api' import { User } from '../../common/user' -import { DAY_MS } from 'common/lib/util/time' const firestore = admin.firestore() const BONUS_START_DATE = new Date('2022-07-13T15:30:00.000Z').getTime() @@ -71,11 +70,14 @@ const updateBettingStreak = async ( contract: Contract, eventId: string ) => { - const betStreakResetTime = getPreviousBettingStreakResetTime() - // If they've already bet after the reset time, they've already gotten their streak bonus - if (user.lastBetTime ?? 0 > betStreakResetTime) return + const betStreakResetTime = getTodaysBettingStreakResetTime() + const lastBetTime = user?.lastBetTime ?? 0 - const newBettingStreak = (user.currentBettingStreak ?? 0) + 1 + // If they've already bet after the reset time, or if we haven't hit the reset time yet + if (lastBetTime > betStreakResetTime || bet.createdTime < betStreakResetTime) + return + + const newBettingStreak = (user?.currentBettingStreak ?? 0) + 1 // Otherwise, add 1 to their betting streak await firestore.collection('users').doc(user.id).update({ currentBettingStreak: newBettingStreak, @@ -246,16 +248,6 @@ const notifyFills = async ( ) } -const getPreviousBettingStreakResetTime = () => { - const today = Date.now() - let betStreakResetTime = new Date().setUTCHours( - BETTING_STREAK_RESET_HOUR, - 0, - 0, - 0 - ) - if (today < betStreakResetTime) { - betStreakResetTime = betStreakResetTime - DAY_MS - } - return betStreakResetTime +const getTodaysBettingStreakResetTime = () => { + return new Date().setUTCHours(BETTING_STREAK_RESET_HOUR, 0, 0, 0) } diff --git a/web/components/user-page.tsx b/web/components/user-page.tsx index dec35224..d3737eea 100644 --- a/web/components/user-page.tsx +++ b/web/components/user-page.tsx @@ -130,7 +130,7 @@ export function UserPage(props: { user: User }) { - + profit setShowBettingStreakModal(true)} > 🔥{user.currentBettingStreak ?? 0} diff --git a/web/pages/notifications.tsx b/web/pages/notifications.tsx index 0c2b25e0..c99b226a 100644 --- a/web/pages/notifications.tsx +++ b/web/pages/notifications.tsx @@ -388,7 +388,7 @@ function IncomeNotificationItem(props: { } else if (sourceType === 'betting_streak_bonus' && sourceText) { reasonText = `for your ${ parseInt(sourceText) / BETTING_STREAK_BONUS_AMOUNT - } day` + }-day` } return ( <>