ghost-portal/packages/react-query/src/BestNumber.tsx
Ewa Kowalska 87505b1c59
Eslint imports (#4037)
* Add eslint configuration

* Patch eslint plugin for sorting imports

* Apply eslint rules for imports
2020-12-01 14:40:42 +01:00

33 lines
889 B
TypeScript

// 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<Props> {
const { api, isApiReady } = useApi();
const bestNumber = useCall<BlockNumber>(isApiReady && api.derive.chain.bestNumber);
return (
<div className={className}>
{label || ''}{withPound && '#'}{
bestNumber
? formatNumber(bestNumber)
: '-'
}{children}
</div>
);
}
export default React.memo(BestNumber);