Council.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/hoc';
  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/functions/misc';
  9. import { Seat } from '@joystream/types/council';
  10. import translate from './translate';
  11. import Section from '@polkadot/joy-utils/react/components/Section';
  12. import { RouteProps } from 'react-router-dom';
  13. type Props = RouteProps & ApiProps & I18nProps & {
  14. council?: Seat[];
  15. };
  16. type State = Record<any, never>;
  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. );