From 6fab5c8ab59fc4e375d06b12bceabfb4ee87ab17 Mon Sep 17 00:00:00 2001 From: painterpuppets Date: Wed, 15 Nov 2023 17:49:41 +0800 Subject: [PATCH] chore: add coming soon buffer --- src/components/Banner/HalvingBanner.tsx | 4 ++-- src/pages/Halving/index.tsx | 4 ++-- src/utils/hook.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/Banner/HalvingBanner.tsx b/src/components/Banner/HalvingBanner.tsx index af60936625..0195d8e39a 100644 --- a/src/components/Banner/HalvingBanner.tsx +++ b/src/components/Banner/HalvingBanner.tsx @@ -34,7 +34,7 @@ function numberToOrdinal(number: number) { export const HalvingBanner = () => { const { estimatedDate, halvingCount, inCelebration, isLoading } = useHalving() - const [days, hours, minutes, seconds, expired] = useCountdown(estimatedDate) + const [days, hours, minutes, seconds, countdown] = useCountdown(estimatedDate) const isMobile = useIsMobile() const [t, { language }] = useTranslation() @@ -60,7 +60,7 @@ export const HalvingBanner = () => { return t('halving.learn_more') } - if (expired) { + if (countdown <= 3) { return t('halving.comming_soon') } diff --git a/src/pages/Halving/index.tsx b/src/pages/Halving/index.tsx index 26c9784dd9..ae3741da7f 100644 --- a/src/pages/Halving/index.tsx +++ b/src/pages/Halving/index.tsx @@ -54,7 +54,7 @@ export const HalvingCountdownPage = () => { (((currentEpoch % EPOCHS_PER_HALVING) * THEORETICAL_EPOCH_TIME - currentEpochUsedTime) / (EPOCHS_PER_HALVING * THEORETICAL_EPOCH_TIME)) * 100 - const [days, hours, minutes, seconds, expired] = useCountdown(estimatedDate) + const [days, hours, minutes, seconds, countdown] = useCountdown(estimatedDate) const shortCountdown = () => { if (days > 0) { @@ -132,7 +132,7 @@ export const HalvingCountdownPage = () => { ) } - if (expired) { + if (countdown <= 3) { return (
diff --git a/src/utils/hook.ts b/src/utils/hook.ts index 3baf1bc263..f591d21f26 100644 --- a/src/utils/hook.ts +++ b/src/utils/hook.ts @@ -537,7 +537,7 @@ export function useParsedDate(timestamp: number): string { return parseDate(timestamp, now) } -export const useCountdown = (targetDate: Date): [number, number, number, number, boolean] => { +export const useCountdown = (targetDate: Date): [number, number, number, number, number] => { const countdownDate = new Date(targetDate).getTime() const [countdown, setCountdown] = useState(countdownDate - new Date().getTime()) @@ -556,7 +556,7 @@ export const useCountdown = (targetDate: Date): [number, number, number, number, const minutes = expired ? 0 : Math.floor((countdown % (1000 * 60 * 60)) / (1000 * 60)) const seconds = expired ? 0 : Math.floor((countdown % (1000 * 60)) / 1000) - return [days, hours, minutes, seconds, expired] + return [days, hours, minutes, seconds, countdown] } export const useCurrentEpochOverTime = (theoretical: boolean) => { @@ -617,7 +617,7 @@ export const useSingleHalving = (_halvingCount = 1) => { // special handling for last epoch: https://github.com/Magickbase/ckb-explorer-public-issues/issues/483 const { currentEpochEstimatedTime, currentEpochUsedTime, isLoading } = useCurrentEpochOverTime( - !(currentEpoch === targetEpoch - 1 && epochBlockIndex / epochLength > 0.5), + !(currentEpoch === targetEpoch - 1 && epochBlockIndex / epochLength > 0.2), ) const estimatedTime = currentEpochEstimatedTime + THEORETICAL_EPOCH_TIME * (targetEpoch - currentEpoch - 1)