Parachain.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* eslint-disable @typescript-eslint/camelcase */
  2. // Copyright 2017-2019 @polkadot/app-parachains 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 { I18nProps } from '@polkadot/react-components/types';
  6. import BN from 'bn.js';
  7. import React from 'react';
  8. import styled from 'styled-components';
  9. import { Bytes, Option } from '@polkadot/types';
  10. import { Card, Static } from '@polkadot/react-components';
  11. import { styles as rowStyles } from '@polkadot/react-components/Row';
  12. import { withCalls, withMulti } from '@polkadot/react-api';
  13. import { formatNumber } from '@polkadot/util';
  14. import translate from '../translate';
  15. interface Props extends I18nProps {
  16. className?: string;
  17. paraId: BN;
  18. parachains_heads?: string | null;
  19. parachains_relayDispatchQueueSize?: [BN, BN];
  20. }
  21. function Parachain ({ className, paraId, parachains_heads, parachains_relayDispatchQueueSize, t }: Props): React.ReactElement<Props> {
  22. return (
  23. <Card className={className}>
  24. <div className='ui--Row'>
  25. <div className='ui--Row-base'>
  26. <div className='ui--Row-details parachains--Item-header'>
  27. <h3>#{formatNumber(paraId)}</h3>
  28. </div>
  29. </div>
  30. <Static
  31. help={t('the last heads of this parachain')}
  32. label={t('heads')}
  33. value={parachains_heads || t('<unknown>')}
  34. />
  35. <Static
  36. help={t('the relay dispatch queue size')}
  37. label={t('relay queue')}
  38. value={
  39. parachains_relayDispatchQueueSize
  40. ? formatNumber(parachains_relayDispatchQueueSize[0])
  41. : '-'
  42. }
  43. />
  44. </div>
  45. </Card>
  46. );
  47. }
  48. export default withMulti(
  49. styled(Parachain)`
  50. ${rowStyles}
  51. .parachains--Item-header {
  52. margin-bottom: 1rem;
  53. }
  54. `,
  55. translate,
  56. withCalls<Props>(
  57. ['query.parachains.heads', {
  58. paramName: 'paraId',
  59. transform: (heads: Option<Bytes>): string | null =>
  60. heads.isSome ? heads.unwrap().toHex() : null
  61. }],
  62. ['query.parachains.relayDispatchQueueSize', { paramName: 'paraId' }]
  63. )
  64. );