Proposal.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 as ProposalType } 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: ProposalType;
  19. }
  20. function renderProposal ({ democracy_depositOf, t }: Props): React.ReactNode {
  21. if (!democracy_depositOf) {
  22. return null;
  23. }
  24. const [balance, addresses] = democracy_depositOf;
  25. return (
  26. <div>
  27. <Labelled label={t('depositors')}>
  28. {addresses.map((address, index): React.ReactNode => (
  29. <InputAddress
  30. isDisabled
  31. key={`${index}:${address}`}
  32. value={address}
  33. withLabel={false}
  34. />
  35. ))}
  36. </Labelled>
  37. <Static label={t('balance')}>
  38. {formatBalance(balance)}
  39. </Static>
  40. </div>
  41. );
  42. }
  43. function Proposal (props: Props): React.ReactElement<Props> {
  44. const { className, democracy_depositOf, idNumber, value } = props;
  45. const depositors = democracy_depositOf
  46. ? democracy_depositOf[1]
  47. : [];
  48. return (
  49. <ActionItem
  50. className={className}
  51. idNumber={idNumber}
  52. proposal={value}
  53. accessory={
  54. <Seconding
  55. depositors={depositors}
  56. proposalId={idNumber}
  57. />
  58. }
  59. >
  60. {renderProposal(props)}
  61. </ActionItem>
  62. );
  63. }
  64. export default withMulti(
  65. Proposal,
  66. translate,
  67. withCalls<Props>(
  68. ['query.democracy.depositOf', {
  69. paramName: 'idNumber',
  70. transform: (value: Option<Tuple>): Tuple | null =>
  71. value.unwrapOr(null)
  72. }]
  73. )
  74. );