Council.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React from 'react';
  2. import { ApiProps } from '@polkadot/react-api/types';
  3. import { I18nProps } from '@polkadot/react-components/types';
  4. import { withCalls } from '@polkadot/react-api/with';
  5. import { Table } from 'semantic-ui-react';
  6. import { formatBalance } from '@polkadot/util';
  7. import CouncilCandidate from './CandidatePreview';
  8. import { calcBackersStake } from '@polkadot/joy-utils/index';
  9. import { Seat } from '@joystream/types/';
  10. import translate from './translate';
  11. import Section from '@polkadot/joy-utils/Section';
  12. type Props = ApiProps &
  13. I18nProps & {
  14. council?: Seat[];
  15. };
  16. type State = {};
  17. class Council extends React.PureComponent<Props, State> {
  18. state: State = {};
  19. private renderTable (council: Seat[]) {
  20. return (
  21. <Table celled selectable compact>
  22. <Table.Header>
  23. <Table.Row>
  24. <Table.HeaderCell>#</Table.HeaderCell>
  25. <Table.HeaderCell>Council member</Table.HeaderCell>
  26. <Table.HeaderCell>Own stake</Table.HeaderCell>
  27. <Table.HeaderCell>{'Backers\' stake'}</Table.HeaderCell>
  28. <Table.HeaderCell>Backers count</Table.HeaderCell>
  29. </Table.Row>
  30. </Table.Header>
  31. <Table.Body>
  32. {council.map((seat, index) => (
  33. <Table.Row key={index}>
  34. <Table.Cell>{index + 1}</Table.Cell>
  35. <Table.Cell>
  36. <CouncilCandidate accountId={seat.member} />
  37. </Table.Cell>
  38. <Table.Cell>{formatBalance(seat.stake)}</Table.Cell>
  39. <Table.Cell>{formatBalance(calcBackersStake(seat.backers))}</Table.Cell>
  40. <Table.Cell>{seat.backers.length}</Table.Cell>
  41. </Table.Row>
  42. ))}
  43. </Table.Body>
  44. </Table>
  45. );
  46. }
  47. render () {
  48. const { council = [] } = this.props;
  49. // console.log({ council });
  50. return (
  51. <Section title="Active council members">
  52. {!council.length ? <em>Council is not elected yet</em> : this.renderTable(council)}
  53. </Section>
  54. );
  55. }
  56. }
  57. // inject the actual API calls automatically into props
  58. export default translate(
  59. withCalls<Props>(['query.council.activeCouncil', { propName: 'council' }])(Council)
  60. );