Proposal.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* eslint-disable @typescript-eslint/camelcase */
  2. // Copyright 2017-2019 @polkadot/app-democracy 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, Balance, Proposal } from '@polkadot/types/interfaces';
  6. import { I18nProps } from '@polkadot/react-components/types';
  7. import BN from 'bn.js';
  8. import React from 'react';
  9. import { Option, Tuple, Vec } from '@polkadot/types';
  10. import { ActionItem, InputAddress, Labelled, Static } from '@polkadot/react-components';
  11. import { withCalls, withMulti } from '@polkadot/react-api';
  12. import { formatBalance } from '@polkadot/util';
  13. import translate from '../translate';
  14. import Seconding from './Seconding';
  15. interface Props extends I18nProps {
  16. democracy_depositOf?: [Balance, Vec<AccountId>] | null;
  17. idNumber: BN;
  18. value: Proposal;
  19. }
  20. class ProposalDisplay extends React.PureComponent<Props> {
  21. public render (): React.ReactNode {
  22. const { className, democracy_depositOf, idNumber, value } = this.props;
  23. const depositors = democracy_depositOf
  24. ? democracy_depositOf[1]
  25. : [];
  26. return (
  27. <ActionItem
  28. className={className}
  29. idNumber={idNumber}
  30. proposal={value}
  31. accessory={
  32. <Seconding
  33. depositors={depositors}
  34. proposalId={idNumber}
  35. />
  36. }
  37. >
  38. {this.renderInfo()}
  39. </ActionItem>
  40. );
  41. }
  42. private renderInfo (): React.ReactNode {
  43. const { democracy_depositOf, t } = this.props;
  44. if (!democracy_depositOf) {
  45. return null;
  46. }
  47. const [balance, addresses] = democracy_depositOf;
  48. return (
  49. <div>
  50. <Labelled label={t('depositors')}>
  51. {addresses.map((address, index): React.ReactNode => (
  52. <InputAddress
  53. isDisabled
  54. key={`${index}:${address}`}
  55. value={address}
  56. withLabel={false}
  57. />
  58. ))}
  59. </Labelled>
  60. <Static label={t('balance')}>
  61. {formatBalance(balance)}
  62. </Static>
  63. </div>
  64. );
  65. }
  66. }
  67. export default withMulti(
  68. ProposalDisplay,
  69. translate,
  70. withCalls<Props>(
  71. ['query.democracy.depositOf', {
  72. paramName: 'idNumber',
  73. transform: (value: Option<Tuple>): Tuple | null =>
  74. value.unwrapOr(null)
  75. }]
  76. )
  77. );