// Copyright 2017-2020 @polkadot/react-query authors & contributors // SPDX-License-Identifier: Apache-2.0 import React from 'react'; import type { BlockNumber } from '@polkadot/types/interfaces'; import { useApi, useCall } from '@polkadot/react-hooks'; import { formatNumber } from '@polkadot/util'; interface Props { children?: React.ReactNode; className?: string; label?: React.ReactNode; withPound?: boolean; } function BestNumber ({ children, className = '', label, withPound }: Props): React.ReactElement { const { api, isApiReady } = useApi(); const bestNumber = useCall(isApiReady && api.derive.chain.bestNumber); return (
{label || ''}{withPound && '#'}{ bestNumber ? formatNumber(bestNumber) : '-' }{children}
); } export default React.memo(BestNumber);