From edbae16c8ee8eb567aaaed379060c3f7357f7e99 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Wed, 14 Sep 2022 08:56:05 -0600 Subject: [PATCH] Betting streak reset indicator --- .../profile/betting-streak-modal.tsx | 43 ++++++++++++++++++- web/components/user-page.tsx | 13 +++++- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/web/components/profile/betting-streak-modal.tsx b/web/components/profile/betting-streak-modal.tsx index a137833c..4d1d63be 100644 --- a/web/components/profile/betting-streak-modal.tsx +++ b/web/components/profile/betting-streak-modal.tsx @@ -3,19 +3,44 @@ import { Col } from 'web/components/layout/col' import { BETTING_STREAK_BONUS_AMOUNT, BETTING_STREAK_BONUS_MAX, + BETTING_STREAK_RESET_HOUR, } from 'common/economy' import { formatMoney } from 'common/util/format' +import { User } from 'common/user' +import dayjs from 'dayjs' +import clsx from 'clsx' export function BettingStreakModal(props: { isOpen: boolean setOpen: (open: boolean) => void + currentUser?: User | null }) { - const { isOpen, setOpen } = props + const { isOpen, setOpen, currentUser } = props + const missingStreak = currentUser && !hasCompletedStreakToday(currentUser) return ( - 🔥 + + 🔥 + + {missingStreak && ( + + + You haven't predicted yet today! + + + If the fire icon is gray, this means you haven't predicted yet + today to get your streak bonus. Get out there and make a + prediction! + + + )} Daily prediction streaks • What are they? @@ -37,3 +62,17 @@ export function BettingStreakModal(props: { ) } + +export function hasCompletedStreakToday(user: User) { + const now = dayjs().utc() + const utcTodayAtResetHour = now + .hour(BETTING_STREAK_RESET_HOUR) + .minute(0) + .second(0) + const utcYesterdayAtResetHour = utcTodayAtResetHour.subtract(1, 'day') + let resetTime = utcTodayAtResetHour.valueOf() + if (now.isBefore(utcTodayAtResetHour)) { + resetTime = utcYesterdayAtResetHour.valueOf() + } + return (user?.lastBetTime ?? 0) > resetTime +} diff --git a/web/components/user-page.tsx b/web/components/user-page.tsx index 81aed562..5485267c 100644 --- a/web/components/user-page.tsx +++ b/web/components/user-page.tsx @@ -28,7 +28,10 @@ import { ReferralsButton } from 'web/components/referrals-button' import { formatMoney } from 'common/util/format' import { ShareIconButton } from 'web/components/share-icon-button' import { ENV_CONFIG } from 'common/envs/constants' -import { BettingStreakModal } from 'web/components/profile/betting-streak-modal' +import { + BettingStreakModal, + hasCompletedStreakToday, +} from 'web/components/profile/betting-streak-modal' import { REFERRAL_AMOUNT } from 'common/economy' import { LoansModal } from './profile/loans-modal' import { UserLikesButton } from 'web/components/profile/user-likes-button' @@ -83,6 +86,7 @@ export function UserPage(props: { user: User }) { {showLoansModal && ( @@ -139,7 +143,12 @@ export function UserPage(props: { user: User }) { profit setShowBettingStreakModal(true)} > 🔥 {user.currentBettingStreak ?? 0}