Joystream Stats 3 gadi atpakaļ
vecāks
revīzija
4215317f9b
2 mainītis faili ar 24 papildinājumiem un 28 dzēšanām
  1. 22 26
      api.ts
  2. 2 2
      index.ts

+ 22 - 26
api.ts

@@ -43,12 +43,9 @@ import {
   RewardRelationshipId,
 } from "@joystream/types/recurring-rewards";
 import { WorkerId, Worker } from "@joystream/types/working-group";
-import {
-  ProposalOf,
-  ProposalDetailsOf
-} from "@joystream/types/augment/types";
+import { ProposalOf, ProposalDetailsOf } from "@joystream/types/augment/types";
 
-import {WorkerOf, } from "@joystream/types/augment-codec/all";
+import { WorkerOf } from "@joystream/types/augment-codec/all";
 
 // blocks
 export const getBlock = (api: ApiPromise, hash: Hash): Promise<SignedBlock> =>
@@ -61,10 +58,6 @@ export const getBlockHash = (
   try {
     return api.rpc.chain.getBlockHash(block);
   } catch (e) {
-    console.error(`BlockHash: ${block}`);
-    //const head =
-    //return api.query.system.blockHash(head)
-    //return api.query.system.parentHash()
     return api.rpc.chain.getFinalizedHead();
   }
 };
@@ -122,7 +115,7 @@ export const getCouncils = async (
     const end = Number(await api.query.council.termEndsAt.at(hash));
     if (end === lastEnd) continue;
     lastEnd = end;
-    starts.push(end - d[3] + 1);
+    starts.push(end - d[3]);
   }
 
   // index by round: each start is the end of the previous term
@@ -132,7 +125,7 @@ export const getCouncils = async (
       const hash = await getBlockHash(api, start);
       const round = await getCouncilRound(api, hash);
       const isLast = index === starts.length - 1;
-      const end = isLast ? start + d[4] : starts[index + 1] - 1;
+      const end = isLast ? start + d[4] - 1 : starts[index + 1] - 1;
       rounds[round] = { start, round, end };
     })
   );
@@ -287,7 +280,7 @@ export const getAccounts = async (
   const entries = await api.query.system.account.entries();
   for (const account of entries) {
     const accountId = String(account[0].toHuman());
-    const balance = (account[1].data.toJSON() as unknown) as AccountData;
+    const balance = account[1].data.toJSON() as unknown as AccountData;
     accounts.push({ accountId, balance });
   }
   return accounts;
@@ -359,9 +352,11 @@ export const getProposalCount = async (
   api: ApiPromise,
   hash?: Hash
 ): Promise<number> =>
-  ((await (hash
-    ? api.query.proposalsEngine.proposalCount.at(hash)
-    : api.query.proposalsEngine.proposalCount())) as u32).toNumber();
+  (
+    (await (hash
+      ? api.query.proposalsEngine.proposalCount.at(hash)
+      : api.query.proposalsEngine.proposalCount())) as u32
+  ).toNumber();
 
 export const getProposalInfo = async (
   api: ApiPromise,
@@ -436,9 +431,8 @@ export const getProposalVotes = async (
   id: ProposalId | number
 ): Promise<{ memberId: number; vote: string }[]> => {
   let votes: { memberId: number; vote: string }[] = [];
-  const entries = await api.query.proposalsEngine.voteExistsByProposalByVoter.entries(
-    id
-  );
+  const entries =
+    await api.query.proposalsEngine.voteExistsByProposalByVoter.entries(id);
   entries.forEach((entry: any) => {
     const memberId = entry[0].args[1].toJSON();
     const vote = entry[1].toString();
@@ -475,19 +469,21 @@ export const getValidatorCount = async (
 export const getValidators = async (
   api: ApiPromise,
   hash: Hash
-): Promise<AccountId[]> =>
-  ((await api.query.staking.snapshotValidators.at(hash)) as Option<
-    Vec<AccountId>
-  >).unwrap();
+): Promise<AccountId[]> => {
+  const snapshot = (await api.query.staking.snapshotValidators.at(
+    hash
+  )) as Option<Vec<AccountId>>;
+  return snapshot.isSome ? snapshot.unwrap() : [];
+};
 
 // media
 export const getNextEntity = async (
   api: ApiPromise,
   hash: Hash
 ): Promise<number> =>
-  ((await api.query.contentDirectory.nextEntityId.at(
-    hash
-  )) as EntityId).toNumber();
+  (
+    (await api.query.contentDirectory.nextEntityId.at(hash)) as EntityId
+  ).toNumber();
 
 export const getNextChannel = async (
   api: ApiPromise,
@@ -508,7 +504,7 @@ export const getEntity = (
 export const getDataObjects = async (
   api: ApiPromise
 ): Promise<Map<ContentId, DataObject>> =>
-  ((await api.query.dataDirectory.dataByContentId.entries()) as unknown) as Map<
+  (await api.query.dataDirectory.dataByContentId.entries()) as unknown as Map<
     ContentId,
     DataObject
   >;

+ 2 - 2
index.ts

@@ -7,8 +7,8 @@ export const getPercent = (value1: number, value2: number): number => {
   return Number(((value2 * 100) / value1 - 100).toFixed(2));
 };
 
-export const momentToString = (moment: Moment) =>
-  new Date(moment.toNumber()).toLocaleDateString("en-US");
+export const momentToString = (timestamp: number) =>
+  new Date(timestamp).toLocaleDateString("en-US");
 
 export const getTotalMinted = (mint: Mint) =>
   Number(mint.getField("total_minted").toString());