index.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2017-2019 @polkadot/app-staking 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 { BareProps } from '@polkadot/react-components/types';
  5. import { ComponentProps } from '../types';
  6. import React, { useContext, useEffect, useState } from 'react';
  7. import { ApiContext } from '@polkadot/react-api';
  8. import { BlockAuthorsContext } from '@polkadot/react-query';
  9. import CurrentList from './CurrentList';
  10. import Summary from './Summary';
  11. interface Props extends BareProps, ComponentProps {}
  12. export default function Overview({
  13. allControllers,
  14. allStashes,
  15. recentlyOnline,
  16. stakingOverview
  17. }: Props): React.ReactElement<Props> {
  18. const { isSubstrateV2 } = useContext(ApiContext);
  19. const { byAuthor, lastBlockAuthors, lastBlockNumber } = useContext(BlockAuthorsContext);
  20. const [next, setNext] = useState<string[]>([]);
  21. const validators = stakingOverview && stakingOverview.validators;
  22. useEffect((): void => {
  23. validators &&
  24. setNext(
  25. isSubstrateV2
  26. ? // this is a V2 node currentValidators is a list of stashes
  27. allStashes.filter((address): boolean => !validators.includes(address as any))
  28. : // this is a V1 node currentValidators is a list of controllers
  29. allControllers.filter((address): boolean => !validators.includes(address as any))
  30. );
  31. }, [allControllers, allStashes, validators]);
  32. return (
  33. <div className="staking--Overview">
  34. <Summary
  35. allControllers={allControllers}
  36. lastBlock={lastBlockNumber}
  37. lastAuthors={lastBlockAuthors}
  38. next={next}
  39. stakingOverview={stakingOverview}
  40. />
  41. <CurrentList
  42. authorsMap={byAuthor}
  43. lastAuthors={lastBlockAuthors}
  44. next={next}
  45. recentlyOnline={recentlyOnline}
  46. stakingOverview={stakingOverview}
  47. />
  48. </div>
  49. );
  50. }