3 次代码提交 04aab01006 ... 0c638b8873

作者 SHA1 备注 提交日期
  mkbeefcake 0c638b8873 Started to fix @joystream/types integration 1 年之前
  mkbeefcake f6bbf3b93e 20230222: Changed wsLocation to live server 1 年之前
  mkbeefcake 5936eacec9 20230222: Started to check validator & nominator chain queries 1 年之前
共有 6 个文件被更改,包括 43 次插入26 次删除
  1. 34 17
      src/App.tsx
  2. 3 3
      src/components/Dashboard/Proposals.tsx
  3. 1 1
      src/components/Dashboard/index.tsx
  4. 2 1
      src/config.ts
  5. 3 3
      src/hooks/useGetValidation.ts
  6. 0 1
      src/lib/queries.ts

+ 34 - 17
src/App.tsx

@@ -249,33 +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}`);
+      
       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 });
       });
     });
   }
@@ -317,8 +334,8 @@ class App extends React.Component<IProps, IState> {
   }
 
   componentDidMount() {
-    // this.loadData(); // local storage + bootstrap
-    // this.joyApi(); // joystream rpc connection
+    this.loadData(); // local storage + bootstrap
+    this.joyApi(); // joystream rpc connection
     //this.initializeSocket() // jsstats socket.io
   }
 

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

@@ -25,7 +25,7 @@ const ProposalWorker = (props: {proposal: Proposal} ) => {
 	const { proposal } = props;
 
 	return (
-		<TableRow key={proposal.id}>
+		<TableRow key={`key-${proposal.id}`}>
 			<TableCell>{proposal.title}</TableCell>
 			<TableCell><i>{proposal.createdAt}</i></TableCell>
 			<TableCell>
@@ -78,8 +78,8 @@ const Proposals = (props: { council: ElectedCouncil | undefined}) => {
 								<TableBody>
 									{rowsPerPage > 0 ? 
 											proposals.slice(page * rowsPerPage, page *rowsPerPage + rowsPerPage)
-												.map((proposal) => <ProposalWorker proposal={proposal}/>)
-										: proposals.map((proposal) => <ProposalWorker proposal={proposal} />)
+												.map((proposal) => <ProposalWorker key={proposal.id} proposal={proposal}/>)
+										: proposals.map((proposal) => <ProposalWorker key={proposal.id} proposal={proposal} />)
 									}
 								</TableBody>
 							</>)}

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

@@ -7,7 +7,7 @@ import Videos from "./Videos";
 import Forum from "./Forum";
 import Election from "./Election";
 import Validation from "./Validation";
-import WorkGroup from './WorkGroup';
+import WorkGroup from './Workgroup';
 
 import Banner from "./ui/Banner";
 import { useElectedCouncils } from '@/hooks';

+ 2 - 1
src/config.ts

@@ -1,6 +1,7 @@
 export const historyDepth = 336;
 export const domain = "https://pioneer.joystreamstats.live";
-export const wsLocation = "wss://joystreamstats.live:9945";
+//export const wsLocation = "wss://joystreamstats.live:9945";
+export const wsLocation = "wss://rpc.joystream.org:9944";
 export const apiLocation = "https://api.joystreamstats.live/api"
 export const socketLocation = "/socket.io"
 export const hydraLocation = "https://hydra.joystream.org/graphql"

+ 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]);

+ 0 - 1
src/lib/queries.ts

@@ -12,7 +12,6 @@ export const queryJstats = (route: string) => {
 };
 
 export const getTokenomics = async (old?: Tokenomics) => {
-  debugger;
   if (old?.timestamp + 300000 > new Date()) return;
   console.debug(`Updating tokenomics`);
   let { data } = await axios.get("https://status.joystream.org/status");