|
@@ -1,20 +1,6 @@
|
|
|
-import React, { useState } from "react";
|
|
|
-import { Button } from "react-bootstrap";
|
|
|
-import Stats from "./MinMax";
|
|
|
-import Validator from "./Validator";
|
|
|
-import Waiting from "./Waiting";
|
|
|
-import Loading from "../Loading";
|
|
|
-
|
|
|
-import {
|
|
|
- Member,
|
|
|
- Post,
|
|
|
- ProposalDetail,
|
|
|
- Seat,
|
|
|
- Stakes,
|
|
|
- RewardPoints,
|
|
|
- Status,
|
|
|
- Tokenomics,
|
|
|
-} from "../../types";
|
|
|
+import React from "react";
|
|
|
+import Content from "./Content";
|
|
|
+import { IState } from "../../types";
|
|
|
import {
|
|
|
AppBar,
|
|
|
createStyles,
|
|
@@ -26,22 +12,6 @@ import {
|
|
|
Typography,
|
|
|
} from "@material-ui/core";
|
|
|
|
|
|
-interface IProps {
|
|
|
- councils: Seat[][];
|
|
|
- members: Member[];
|
|
|
- posts: Post[];
|
|
|
- proposals: ProposalDetail[];
|
|
|
- validators: string[];
|
|
|
- stashes: string[];
|
|
|
- nominators: string[];
|
|
|
- stars: { [key: string]: boolean };
|
|
|
- toggleStar: (account: string) => void;
|
|
|
- stakes?: { [key: string]: Stakes };
|
|
|
- rewardPoints?: RewardPoints;
|
|
|
- tokenomics?: Tokenomics;
|
|
|
- status: Status;
|
|
|
-}
|
|
|
-
|
|
|
const useStyles = makeStyles((theme: Theme) =>
|
|
|
createStyles({
|
|
|
root: {
|
|
@@ -55,93 +25,9 @@ const useStyles = makeStyles((theme: Theme) =>
|
|
|
})
|
|
|
);
|
|
|
|
|
|
-const Validators = (iProps: IProps) => {
|
|
|
- const [props] = useState(iProps);
|
|
|
- const [sortBy, setSortBy] = useState("totalStake");
|
|
|
-
|
|
|
- const [showWaiting, setShowWaiting] = useState(false);
|
|
|
- const [showValidators, setShowValidators] = useState(false);
|
|
|
-
|
|
|
- const toggleValidators = () => setShowValidators((prev) => !prev);
|
|
|
-
|
|
|
- const toggleWaiting = () => setShowWaiting((prev) => !prev);
|
|
|
-
|
|
|
- const sortValidators = (field: string, validators: string[]) => {
|
|
|
- const { stakes, rewardPoints } = props;
|
|
|
- try {
|
|
|
- if (field === "points" || !stakes)
|
|
|
- return validators.sort((a, b) =>
|
|
|
- rewardPoints
|
|
|
- ? rewardPoints.individual[b] - rewardPoints.individual[a]
|
|
|
- : 0
|
|
|
- );
|
|
|
-
|
|
|
- if (field === "commission")
|
|
|
- return validators.sort((a, b) =>
|
|
|
- stakes[a] && stakes[b]
|
|
|
- ? stakes[a].commission - stakes[b].commission
|
|
|
- : 0
|
|
|
- );
|
|
|
-
|
|
|
- if (field === "ownStake")
|
|
|
- return validators.sort((a, b) =>
|
|
|
- stakes[a] && stakes[b] ? stakes[b].own - stakes[a].own : 0
|
|
|
- );
|
|
|
-
|
|
|
- if (field === "totalStake")
|
|
|
- return validators.sort((a, b) =>
|
|
|
- stakes[a] && stakes[b] ? stakes[b].total - stakes[a].total : 0
|
|
|
- );
|
|
|
-
|
|
|
- if (field === "othersStake") {
|
|
|
- const sumOf = (stakes: { value: number }[]) => {
|
|
|
- let sum = 0;
|
|
|
- stakes.forEach((s) => (sum += s.value));
|
|
|
- return sum;
|
|
|
- };
|
|
|
-
|
|
|
- return validators.sort((a, b) =>
|
|
|
- stakes[a] && stakes[b]
|
|
|
- ? sumOf(stakes[b].others) - sumOf(stakes[a].others)
|
|
|
- : 0
|
|
|
- );
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- console.debug(`sorting failed`, e);
|
|
|
- }
|
|
|
-
|
|
|
- return validators;
|
|
|
- };
|
|
|
-
|
|
|
- const {
|
|
|
- getMember,
|
|
|
- councils,
|
|
|
- members,
|
|
|
- posts,
|
|
|
- proposals,
|
|
|
- validators,
|
|
|
- nominators,
|
|
|
- stashes,
|
|
|
- stars,
|
|
|
- rewardPoints,
|
|
|
- status,
|
|
|
- stakes,
|
|
|
- tokenomics,
|
|
|
- } = props;
|
|
|
-
|
|
|
+const Validators = (props: IState) => {
|
|
|
const classes = useStyles();
|
|
|
|
|
|
- if (!status || !status.block) return <Loading gridSize={12} />;
|
|
|
-
|
|
|
- const { lastReward, block, era, startTime } = status;
|
|
|
-
|
|
|
- const issued = tokenomics ? Number(tokenomics.totalIssuance) : 0;
|
|
|
- const price = tokenomics ? Number(tokenomics.price) : 0;
|
|
|
-
|
|
|
- const starred = stashes.filter((v) => stars[v]);
|
|
|
- const unstarred = validators.filter((v) => !stars[v]);
|
|
|
- const waiting = stashes.filter((s) => !stars[s] && !validators.includes(s));
|
|
|
-
|
|
|
return (
|
|
|
<Grid
|
|
|
style={{
|
|
@@ -157,7 +43,8 @@ const Validators = (iProps: IProps) => {
|
|
|
textAlign: "center",
|
|
|
backgroundColor: "#4038FF",
|
|
|
color: "#fff",
|
|
|
- height: 600,
|
|
|
+ minHeight: 500,
|
|
|
+ maxHeight: 500,
|
|
|
overflow: "auto",
|
|
|
}}
|
|
|
>
|
|
@@ -173,73 +60,7 @@ const Validators = (iProps: IProps) => {
|
|
|
</Toolbar>
|
|
|
</AppBar>
|
|
|
|
|
|
- <Stats
|
|
|
- block={block}
|
|
|
- era={era}
|
|
|
- stakes={stakes}
|
|
|
- issued={issued}
|
|
|
- price={price}
|
|
|
- validators={validators}
|
|
|
- nominators={nominators.length}
|
|
|
- waiting={waiting.length}
|
|
|
- reward={status.lastReward}
|
|
|
- />
|
|
|
-
|
|
|
- <div className="d-flex flex-column mt-3">
|
|
|
- {sortValidators(sortBy, starred).map((v) => (
|
|
|
- <Validator
|
|
|
- key={v}
|
|
|
- sortBy={setSortBy}
|
|
|
- starred={stars[v] ? `teal` : undefined}
|
|
|
- toggleStar={props.toggleStar}
|
|
|
- startTime={startTime}
|
|
|
- validator={v}
|
|
|
- reward={lastReward / validators.length}
|
|
|
- councils={councils}
|
|
|
- council={status.council}
|
|
|
- member={getMember(v)}
|
|
|
- posts={posts}
|
|
|
- proposals={proposals}
|
|
|
- validators={validators}
|
|
|
- stakes={stakes}
|
|
|
- rewardPoints={rewardPoints}
|
|
|
- />
|
|
|
- ))}
|
|
|
-
|
|
|
- <Button onClick={() => toggleValidators()}>
|
|
|
- Toggle {unstarred.length} validators
|
|
|
- </Button>
|
|
|
-
|
|
|
- {showValidators &&
|
|
|
- sortValidators(sortBy, unstarred).map((v) => (
|
|
|
- <Validator
|
|
|
- key={v}
|
|
|
- sortBy={setSortBy}
|
|
|
- starred={stars[v] ? `teal` : undefined}
|
|
|
- toggleStar={props.toggleStar}
|
|
|
- startTime={startTime}
|
|
|
- validator={v}
|
|
|
- reward={lastReward / validators.length}
|
|
|
- councils={councils}
|
|
|
- council={status.council}
|
|
|
- member={getMember(v)}
|
|
|
- posts={posts}
|
|
|
- proposals={proposals}
|
|
|
- validators={validators}
|
|
|
- stakes={stakes}
|
|
|
- rewardPoints={rewardPoints}
|
|
|
- />
|
|
|
- ))}
|
|
|
-
|
|
|
- <Waiting
|
|
|
- toggleWaiting={toggleWaiting}
|
|
|
- show={showWaiting}
|
|
|
- waiting={waiting}
|
|
|
- posts={posts}
|
|
|
- proposals={proposals}
|
|
|
- members={members}
|
|
|
- />
|
|
|
- </div>
|
|
|
+ <Content getMember={props.getMember} {...props} />
|
|
|
</Paper>
|
|
|
</Grid>
|
|
|
);
|