Skip to content

Commit

Permalink
feat: set duration of halving banner
Browse files Browse the repository at this point in the history
The halving banner shows since 30 days before target epoch
and disapears since 1 day after target epoch
  • Loading branch information
Keith-CY committed Nov 20, 2023
1 parent 1e84978 commit fb71d34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import {
} from './styled'
import Content from '../../components/Content'
import { parseTime, parseTimeNoSecond } from '../../utils/date'
import { BLOCK_POLLING_TIME, ListPageParams, DELAY_BLOCK_NUMBER } from '../../constants/common'
import { BLOCK_POLLING_TIME, ListPageParams, DELAY_BLOCK_NUMBER, EPOCHS_PER_HALVING } from '../../constants/common'
import { localeNumberString, handleHashRate, handleDifficulty } from '../../utils/number'
import { handleBigNumber } from '../../utils/string'
import { isMainnet } from '../../utils/chain'
import LatestBlocksIcon from './latest_blocks.png'
import LatestTransactionsIcon from './latest_transactions.png'
import { BlockCardItem, TransactionCardItem } from './TableCard'
import Loading from '../../components/Loading/SmallLoading'
import { useElementIntersecting, useIsLGScreen, useIsMobile } from '../../utils/hook'
import { useElementIntersecting, useIsLGScreen, useIsMobile, useSingleHalving } from '../../utils/hook'
import Banner from '../../components/Banner'
import { HalvingBanner } from '../../components/Banner/HalvingBanner'
import Search from '../../components/Search'
Expand Down Expand Up @@ -226,12 +226,16 @@ export default () => {
() => transactionsQuery.data?.transactions.slice(0, maxDisplaysCount) ?? [],
[transactionsQuery.data?.transactions],
)
const { currentEpoch, targetEpoch } = useSingleHalving()
const isHalvingHidden =
currentEpoch > targetEpoch + 6 && // 6 epochs(1 day) after halving
currentEpoch < targetEpoch + EPOCHS_PER_HALVING - 180 // 180 epochs(30 days) before next halving

const blockchainDataList = useBlockchainDataList(isMobile, isLG)

return (
<Content>
{isMainnet() ? <HalvingBanner /> : <Banner />}
{isMainnet() && !isHalvingHidden ? <HalvingBanner /> : <Banner />}
<div className="container">
<HomeHeaderTopPanel />
<div className={`${styles.homeStatisticTopPanel} ${styles.afterHardFork}`}>
Expand Down
8 changes: 4 additions & 4 deletions src/utils/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,11 @@ export const useSingleHalving = (_halvingCount = 1) => {
export const useHalving = () => {
const statistics = useStatistics()
const currentEpoch = Number(statistics.epochInfo.epochNumber)
const lastedHalvingCount = Math.ceil((currentEpoch + 1) / EPOCHS_PER_HALVING)
const lastedHalving = useSingleHalving(lastedHalvingCount)
const previousHalving = useSingleHalving(lastedHalvingCount - 1)
const nextHalvingCount = Math.ceil((currentEpoch + 1) / EPOCHS_PER_HALVING)
const nextHalving = useSingleHalving(nextHalvingCount)
const previousHalving = useSingleHalving(nextHalvingCount - 1)

return previousHalving.inCelebration ? previousHalving : lastedHalving
return previousHalving.inCelebration ? previousHalving : nextHalving
}

export default {
Expand Down

0 comments on commit fb71d34

Please sign in to comment.