diff --git a/ui/block/BlockCeloEpochTag.tsx b/ui/block/BlockCeloEpochTag.tsx new file mode 100644 index 0000000000..12a84f1970 --- /dev/null +++ b/ui/block/BlockCeloEpochTag.tsx @@ -0,0 +1,72 @@ +import { Tag, Tooltip, useDisclosure } from '@chakra-ui/react'; +import React from 'react'; + +import { route } from 'nextjs-routes'; + +import config from 'configs/app'; +import LinkInternal from 'ui/shared/links/LinkInternal'; + +import type { BlockQuery } from './useBlockQuery'; + +interface Props { + blockQuery: BlockQuery; +} + +const BlockCeloEpochTag = ({ blockQuery }: Props) => { + // have to implement controlled tooltip because of the issue - https://github.com/chakra-ui/chakra-ui/issues/7107 + const { isOpen, onOpen, onToggle, onClose } = useDisclosure(); + + if (!blockQuery.data?.celo) { + return null; + } + + if (!blockQuery.data.celo.is_epoch_block) { + const celoConfig = config.features.celo; + const epochBlockNumber = celoConfig.isEnabled && celoConfig.L2UpgradeBlock && blockQuery.data.height <= celoConfig.L2UpgradeBlock ? + blockQuery.data.celo.epoch_number * celoConfig.BLOCKS_PER_EPOCH : + undefined; + const tag = ( + + Epoch #{ blockQuery.data.celo.epoch_number } + + ); + const content = epochBlockNumber ? ( + + { tag } + + ) : tag; + + return ( + + { content } + + ); + } + + return ( + + + Finalized epoch #{ blockQuery.data.celo.epoch_number } + + + ); +}; + +export default React.memo(BlockCeloEpochTag); diff --git a/ui/pages/Block.tsx b/ui/pages/Block.tsx index 1b93c97ef9..182775e6fe 100644 --- a/ui/pages/Block.tsx +++ b/ui/pages/Block.tsx @@ -1,4 +1,4 @@ -import { chakra, Skeleton, Tooltip } from '@chakra-ui/react'; +import { chakra, Skeleton } from '@chakra-ui/react'; import capitalize from 'lodash/capitalize'; import { useRouter } from 'next/router'; import React from 'react'; @@ -6,8 +6,6 @@ import React from 'react'; import type { PaginationParams } from 'ui/shared/pagination/types'; import type { RoutedTab } from 'ui/shared/Tabs/types'; -import { route } from 'nextjs-routes'; - import config from 'configs/app'; import { useAppContext } from 'lib/contexts/app'; import throwOnAbsentParamError from 'lib/errors/throwOnAbsentParamError'; @@ -15,6 +13,7 @@ import throwOnResourceLoadError from 'lib/errors/throwOnResourceLoadError'; import useIsMobile from 'lib/hooks/useIsMobile'; import getNetworkValidationActionText from 'lib/networks/getNetworkValidationActionText'; import getQueryParamString from 'lib/router/getQueryParamString'; +import BlockCeloEpochTag from 'ui/block/BlockCeloEpochTag'; import BlockDetails from 'ui/block/BlockDetails'; import BlockEpochRewards from 'ui/block/BlockEpochRewards'; import BlockWithdrawals from 'ui/block/BlockWithdrawals'; @@ -24,9 +23,7 @@ import useBlockTxsQuery from 'ui/block/useBlockTxsQuery'; import useBlockWithdrawalsQuery from 'ui/block/useBlockWithdrawalsQuery'; import TextAd from 'ui/shared/ad/TextAd'; import ServiceDegradationWarning from 'ui/shared/alerts/ServiceDegradationWarning'; -import Tag from 'ui/shared/chakra/Tag'; import AddressEntity from 'ui/shared/entities/address/AddressEntity'; -import LinkInternal from 'ui/shared/links/LinkInternal'; import NetworkExplorers from 'ui/shared/NetworkExplorers'; import PageTitle from 'ui/shared/Page/PageTitle'; import Pagination from 'ui/shared/pagination/Pagination'; @@ -149,36 +146,6 @@ const BlockPageContent = () => { return `Block #${ blockQuery.data?.height }`; } })(); - const contentAfter = (() => { - if (!blockQuery.data?.celo) { - return null; - } - - if (!blockQuery.data.celo.is_epoch_block) { - const celoConfig = config.features.celo; - const epochBlockNumber = celoConfig.isEnabled && celoConfig.L2UpgradeBlock && blockQuery.data.height <= celoConfig.L2UpgradeBlock ? - blockQuery.data.celo.epoch_number * celoConfig.BLOCKS_PER_EPOCH : - undefined; - const tag = Epoch #{ blockQuery.data.celo.epoch_number }; - const content = epochBlockNumber ? ( - - { tag } - - ) : tag; - - return ( - - { content } - - ); - } - - return ( - - Finalized epoch #{ blockQuery.data.celo.epoch_number } - - ); - })(); const titleSecondRow = ( <> { !config.UI.views.block.hiddenFields?.miner && blockQuery.data?.miner && ( @@ -206,7 +173,7 @@ const BlockPageContent = () => { } secondRow={ titleSecondRow } isLoading={ blockQuery.isPlaceholderData } />