import { chakra } from '@chakra-ui/react'; import React from 'react'; import { route } from 'nextjs/routes'; import config from 'configs/app'; import { useMultichainContext } from 'lib/contexts/multichain'; import * as EntityBase from 'ui/shared/entities/base/components'; import getChainTooltipText from 'ui/shared/externalChains/getChainTooltipText'; import { distributeEntityProps } from '../base/utils'; type LinkProps = EntityBase.LinkBaseProps & Partial>; const Link = chakra((props: LinkProps) => { const heightOrHash = props.hash ?? String(props.number); const defaultHref = route( { pathname: '/block/[height_or_hash]', query: { height_or_hash: heightOrHash } }, { chain: props.chain, external: props.external }, ); return ( { props.children } ); }); type IconProps = EntityBase.IconBaseProps & Pick; const Icon = (props: IconProps) => { const isPendingUpdate = props.isPendingUpdate && config.UI.views.block.pendingUpdateAlertEnabled; const name = (() => { if ('name' in props) { return props.name; } return isPendingUpdate ? 'status/warning' : 'block'; })(); const hint = (() => { if ('hint' in props) { return props.hint; } if (props.chain && props.shield !== false) { return getChainTooltipText(props.chain, 'Block on '); } return isPendingUpdate ? 'Block is being re-synced. Details may be incomplete until the update is finished.' : undefined; })(); return ( ); }; type ContentProps = Omit & Pick; const Content = chakra((props: ContentProps) => { return ( ); }); const Container = EntityBase.Container; export interface EntityProps extends EntityBase.EntityBaseProps { number: number | string; hash?: string; isPendingUpdate?: boolean; } const BlockEntity = (props: EntityProps) => { const multichainContext = useMultichainContext(); const partsProps = distributeEntityProps(props, multichainContext); const content = ; return ( { props.noLink ? content : { content } } ); }; export default React.memo(chakra(BlockEntity)); export { Container, Link, Icon, Content, };