Members.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2017-2020 @polkadot/app-democracy authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import { DeriveElectionsInfo } from '@polkadot/api-derive/types';
  5. import { AccountId } from '@polkadot/types/interfaces';
  6. import React, { useMemo } from 'react';
  7. import { Table } from '@polkadot/react-components';
  8. import { useTranslation } from '../translate';
  9. import Candidate from './Candidate';
  10. interface Props {
  11. allVotes?: Record<string, AccountId[]>;
  12. className?: string;
  13. electionsInfo?: DeriveElectionsInfo;
  14. prime?: AccountId | null;
  15. }
  16. function Members ({ allVotes = {}, className = '', electionsInfo, prime }: Props): React.ReactElement<Props> {
  17. const { t } = useTranslation();
  18. const header = useMemo(() => [
  19. [t('members'), 'start', 2],
  20. [t('backing')],
  21. [t('votes')]
  22. ], [t]);
  23. return (
  24. <Table
  25. className={className}
  26. empty={electionsInfo && t<string>('No members found')}
  27. header={header}
  28. >
  29. {electionsInfo?.members.map(([accountId, balance]): React.ReactNode => (
  30. <Candidate
  31. address={accountId}
  32. balance={balance}
  33. isPrime={prime?.eq(accountId)}
  34. key={accountId.toString()}
  35. voters={allVotes[accountId.toString()]}
  36. />
  37. ))}
  38. </Table>
  39. );
  40. }
  41. export default React.memo(Members);