BlockToTime.tsx 755 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2017-2020 @polkadot/react-query authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import BN from 'bn.js';
  5. import React from 'react';
  6. import { useBlockTime } from '@polkadot/react-hooks';
  7. interface Props {
  8. blocks?: BN;
  9. children?: React.ReactNode;
  10. className?: string;
  11. label?: React.ReactNode;
  12. }
  13. function BlockToTime ({ blocks, children, className = '', label }: Props): React.ReactElement<Props> | null {
  14. const [, text] = useBlockTime(blocks);
  15. if (blocks?.ltn(0)) {
  16. return null;
  17. }
  18. return (
  19. <div className={className}>
  20. {label || ''}{text}{children}
  21. </div>
  22. );
  23. }
  24. export default React.memo(BlockToTime);