Skip to content

Commit

Permalink
fix: misstake halving loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
PainterPuppets committed Nov 15, 2023
1 parent f57cb11 commit fce3bd3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/utils/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,14 @@ export const useCurrentEpochOverTime = (theoretical: boolean) => {
})
const current = useMemo(() => new Date().getTime(), [])

if (!theoretical && firstBlock.data) {
if (!theoretical) {
if (!firstBlock.data) {
return {
currentEpochUsedTime: 0,
currentEpochEstimatedTime: 0,
isLoading: true,
}
}
// Extrapolate the end time based on how much time has elapsed since the current epoch.
const startedAt = firstBlock.data.timestamp
const currentEpochUsedTime = current - startedAt
Expand All @@ -580,6 +587,7 @@ export const useCurrentEpochOverTime = (theoretical: boolean) => {
return {
currentEpochUsedTime,
currentEpochEstimatedTime,
isLoading: statistics.epochInfo.index === '0',
}
}

Expand All @@ -588,6 +596,7 @@ export const useCurrentEpochOverTime = (theoretical: boolean) => {
return {
currentEpochUsedTime,
currentEpochEstimatedTime,
isLoading: statistics.epochInfo.index === '0',
}
}

Expand All @@ -607,7 +616,7 @@ export const useSingleHalving = (_halvingCount = 1) => {
const current = useMemo(() => new Date().getTime(), [])

// special handling for last epoch: https://github.com/Magickbase/ckb-explorer-public-issues/issues/483
const { currentEpochEstimatedTime, currentEpochUsedTime } = useCurrentEpochOverTime(
const { currentEpochEstimatedTime, currentEpochUsedTime, isLoading } = useCurrentEpochOverTime(
!(currentEpoch === targetEpoch - 1 && epochBlockIndex / epochLength > 0.5),
)

Expand All @@ -618,7 +627,7 @@ export const useSingleHalving = (_halvingCount = 1) => {
const inCelebration = haveDone && currentEpoch < celebrationOverEpoch && !celebrationSkipped

return {
isLoading: statistics.epochInfo.index === '0',
isLoading,
halvingCount,
currentEpoch,
targetEpoch,
Expand Down

0 comments on commit fce3bd3

Please sign in to comment.