Joystream Stats 2 năm trước cách đây
mục cha
commit
5e552823b8

+ 4 - 8
src/App.tsx

@@ -58,11 +58,7 @@ class App extends React.Component<IProps, IState> {
     let { status, councils } = this.state;
     status.era = await this.updateEra(api);
     status.election = await updateElection(api);
-    if (
-      status.election?.stage &&
-      Object.keys(status.election.stage)[0] === "revealing"
-    )
-      this.getElectionStatus(api);
+    if (status.election?.stage) this.getElectionStatus(api);
     councils.forEach((c) => {
       if (c.round > status.council) status.council = c;
     });
@@ -262,6 +258,9 @@ class App extends React.Component<IProps, IState> {
       api.rpc.chain.subscribeNewHeads(async (header: Header) => {
         let { blocks, status } = this.state;
         const id = header.number.toNumber();
+        const isEven = id / 50 === Math.floor(id / 50);
+        if (isEven || status.block?.id + 50 < id) this.updateStatus(api, id);
+
         if (blocks.find((b) => b.id === id)) return;
         const timestamp = (await api.query.timestamp.now()).toNumber();
         const duration = status.block
@@ -272,9 +271,6 @@ class App extends React.Component<IProps, IState> {
 
         blocks = blocks.filter((i) => i.id !== id).concat(status.block);
         this.setState({ blocks });
-
-        const isEven = id / 50 === Math.floor(id / 50);
-        if (isEven || status.block?.id + 50 < id) this.updateStatus(api, id);
       });
     });
   }

+ 4 - 10
src/components/Dashboard/Council.tsx

@@ -18,14 +18,8 @@ import { Council, Post, ProposalDetail, Status } from "../../types";
 const useStyles = makeStyles((theme: Theme) =>
   createStyles({
     grid: { textAlign: "center", backgroundColor: "#000", color: "#fff" },
-    root: {
-      flexGrow: 1,
-      backgroundColor: "#4038FF",
-    },
-    title: {
-      textAlign: "left",
-      flexGrow: 1,
-    },
+    root: { flexGrow: 1, backgroundColor: "#4038FF" },
+    title: { textAlign: "left", flexGrow: 1 },
     paper: {
       textAlign: "center",
       backgroundColor: "#4038FF",
@@ -66,8 +60,8 @@ const CouncilGrid = (props: {
               <ElectionStatus
                 domain={domain}
                 block={status?.block?.id}
-		stage={election?.stage}
-		termEndsAt={election?.termEndsAt}
+                stage={election?.stage}
+                termEndsAt={election?.termEndsAt}
               />
               Council
             </Typography>

+ 2 - 2
src/components/Dashboard/Proposals.tsx

@@ -37,15 +37,15 @@ const Proposals = (props: {
   startTime: number;
   block: number;
   status: { council: Council };
+  gridSize: GridSize;
 }) => {
   const classes = useStyles();
-
   const { proposals, validators, councils, members, posts, block, status } =
     props;
   const pending = proposals.filter((p) => p && p.result === "Pending");
 
   return (
-    <Grid className={classes.grid} item lg={6}>
+    <Grid className={classes.grid} item lg={props.gridSize} xs={12}>
       <Paper className={classes.paper}>
         <AppBar className={classes.root} position="static">
           <Toolbar>

+ 1 - 0
src/components/Dashboard/index.tsx

@@ -47,6 +47,7 @@ const Dashboard = (props: IProps) => {
             proposalPosts={props.proposalPosts}
             validators={validators}
             status={status}
+            gridSize={6}
           />
           <Council
             getMember={getMember}

+ 0 - 2
src/components/Transactions/index.tsx

@@ -54,8 +54,6 @@ class Transactions extends React.Component<IProps, IState> {
     const { address, transactions } = this.state;
     const getHandle = (key: string) =>
       members.concat(JSG).find(({ rootKey }) => rootKey === key)?.handle || key;
-    console.log(transactions);
-
     return (
       <div className="box">
         <h3>Transactions</h3>

+ 3 - 0
src/lib/election.ts

@@ -136,6 +136,9 @@ export const getVotes = async (api: ApiPromise): Promise<IVote[]> => {
   return votes;
 };
 
+const fromEntries = (xs: [string | number | symbol, any][]) =>
+  xs.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
+
 export const PromiseAllObj = (obj: {
   [k: string]: any;
 }): Promise<{ [k: string]: any }> => {