Browse Source

Started to fix @joystream/types integration

mkbeefcake 1 year ago
parent
commit
0c638b8873
2 changed files with 34 additions and 19 deletions
  1. 31 16
      src/App.tsx
  2. 3 3
      src/hooks/useGetValidation.ts

+ 31 - 16
src/App.tsx

@@ -249,35 +249,50 @@ class App extends React.Component<IProps, IState> {
     );
   }
 
-  // startup from bottom up
+  async getStakesForValidators(api: ApiPromise) {
+    const era = Number(await api.query.staking.currentEra());
+    console.log('Era: ', era);
+    // await this.updateValidatorPoints(api, era);
+    // await this.updateValidators(api);
+
+    // console.log('LastReward', await getLastReward(api, era));
+    // console.log('getTotalStake', await getTotalStake(api, era));
+
+  }
 
+  // startup from bottom up
   joyApi() {
     console.debug(`Connecting to ${wsLocation}`);
     const provider = new WsProvider(wsLocation);
     ApiPromise.create({ provider/*, types*/ }).then(async (api) => {
       await api.isReady;
       console.log(`Connected to ${wsLocation}`);
-      debugger;
       
       this.setState({ connected: true });
-      this.updateWorkingGroups(api);
+      // this.updateWorkingGroups(api);
 
+      // For getting Reward
+      await this.getStakesForValidators(api);
+  
       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
-          ? timestamp - status.block.timestamp
-          : 6000;
-        status.block = { id, timestamp, duration };
-        this.save("status", status);
-
-        blocks = blocks.filter((i) => i.id !== id).concat(status.block);
-        this.setState({ blocks });
+
+        // console.log(`api.rpc.chain.subscribeNewHeads: ${id}`)
+
+        // 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
+        //   ? timestamp - status.block.timestamp
+        //   : 6000;
+        // status.block = { id, timestamp, duration };
+        // this.save("status", status);
+
+        // blocks = blocks.filter((i) => i.id !== id).concat(status.block);
+        // this.setState({ blocks });
       });
     });
   }

+ 3 - 3
src/hooks/useGetValidation.ts

@@ -7,8 +7,8 @@ export function useValidation({ council }: ForSelectedCouncil) {
   // const [fetchCandidates, CandidateQuery] = useGetCandidatesCountQuery();
   // const [fetchVotes, VotesQuery] = useGetCastVotesCountLazyQuery();
 
-  useEffect(() => {
-    if (!council) return;
+  // useEffect(() => {
+  //    if (!council) return;
 
     // var variables = {
     //   where: { createdAt_gt: council.electedAt.timestamp, createdAt_lt: council.endedAt?.timestamp },
@@ -20,7 +20,7 @@ export function useValidation({ council }: ForSelectedCouncil) {
     // fetchVotes({
     //   variables,
     // });
-  }, [council]);
+  // }, [council]);
 
   // const candidates = useMemo(() => CandidateQuery.data?.candidatesConnection.totalCount, [CandidateQuery.data]);
   // const votes = useMemo(() => VotesQuery.data?.castVotesConnection.totalCount, [VotesQuery.data]);