SummaryBar.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* eslint-disable @typescript-eslint/camelcase */
  2. // Copyright 2017-2019 @polkadot/app-123code authors & contributors
  3. // This software may be modified and distributed under the terms
  4. // of the Apache-2.0 license. See the LICENSE file for details.
  5. import { AccountId } from '@polkadot/types/interfaces';
  6. import { BareProps, I18nProps } from '@polkadot/react-components/types';
  7. import BN from 'bn.js';
  8. import React, { useContext } from 'react';
  9. import { ApiContext, withCalls } from '@polkadot/react-api';
  10. import { Bubble, IdentityIcon } from '@polkadot/react-components';
  11. import { formatBalance, formatNumber } from '@polkadot/util';
  12. import translate from './translate';
  13. interface Props extends BareProps, I18nProps {
  14. balances_totalIssuance?: BN;
  15. chain_bestNumber?: BN;
  16. chain_bestNumberLag?: BN;
  17. staking_validators?: AccountId[];
  18. }
  19. function SummaryBar ({ balances_totalIssuance, chain_bestNumber, chain_bestNumberLag, staking_validators }: Props): React.ReactElement<Props> {
  20. const { api, systemChain, systemName, systemVersion } = useContext(ApiContext);
  21. return (
  22. <summary>
  23. <div>
  24. <Bubble icon='tty' label='node'>
  25. {systemName} v{systemVersion}
  26. </Bubble>
  27. <Bubble icon='chain' label='chain'>
  28. {systemChain}
  29. </Bubble>
  30. <Bubble icon='code' label='runtime'>
  31. {api.runtimeVersion.implName} v{api.runtimeVersion.implVersion}
  32. </Bubble>
  33. <Bubble icon='bullseye' label='best #'>
  34. {formatNumber(chain_bestNumber)} ({formatNumber(chain_bestNumberLag)} lag)
  35. </Bubble>
  36. {staking_validators && (
  37. <Bubble icon='chess queen' label='validators'>{
  38. staking_validators.map((accountId, index): React.ReactNode => (
  39. <IdentityIcon key={index} value={accountId} size={20} />
  40. ))
  41. }</Bubble>
  42. )}
  43. <Bubble icon='circle' label='total tokens'>
  44. {formatBalance(balances_totalIssuance)}
  45. </Bubble>
  46. </div>
  47. </summary>
  48. );
  49. }
  50. // inject the actual API calls automatically into props
  51. export default translate(
  52. withCalls<Props>(
  53. 'derive.chain.bestNumber',
  54. 'derive.chain.bestNumberLag',
  55. 'derive.staking.validators',
  56. 'query.balances.totalIssuance'
  57. )(SummaryBar)
  58. );