3
0
Prechádzať zdrojové kódy

Fix some compilation errors.

Oleksandr Korniienko 3 rokov pred
rodič
commit
23b375e460
3 zmenil súbory, kde vykonal 35 pridanie a 10 odobranie
  1. 19 7
      media.ts
  2. 6 3
      rewards.ts
  3. 10 0
      types.ts

+ 19 - 7
media.ts

@@ -1,22 +1,34 @@
-const getEntities = async (blockHash: Hash): Promise<Map<number, Entity>> => {
-  let nrEntities: number = await getNextEntity(this.api, blockHash);
+import { ApiPromise } from "@polkadot/api";
+import { Vec, Option } from '@polkadot/types';
+import { Hash } from "@joystream/types/common";
+import { Entity } from "@joystream/types/content-directory";
+import { ContentId, DataObject } from "@joystream/types/media";
+import { getNextEntity, getEntity, getDataObject } from "./api";
+import { Channel, Media } from "./types";
+
+const CHANNEL_CLASS_iD = 1;
+const VIDEO_CLASS_iD = 10;
+
+const getEntities = async (
+  api: ApiPromise,
+  blockHash: Hash
+): Promise<Map<number, Entity>> => {
+  let nrEntities: number = await getNextEntity(api, blockHash);
   let entities = new Map<number, Entity>();
   for (let i = 0; i < nrEntities; ++i) {
-    const entity: Entity = await getEntity(this.api, blockHash, i);
+    const entity: Entity = await getEntity(api, blockHash, i);
     entities.set(i, entity);
   }
   return entities;
 };
 
 export const computeUsedSpaceInMbs = async (
+  api: ApiPromise,
   contentIds: Vec<ContentId>
 ): Promise<number> => {
   let space = 0;
   for (let contentId of contentIds) {
-    const dataObject: Option<DataObject> = await getDataObject(
-      this.api,
-      contentId
-    );
+    const dataObject: Option<DataObject> = await getDataObject(api, contentId);
     space += dataObject.unwrap().size_in_bytes.toNumber();
   }
   return space / 1024 / 1024;

+ 6 - 3
rewards.ts

@@ -64,7 +64,8 @@ export const getWorkerRewards = async (
     const member: Membership = await getMember(api, memberId, hash);
     const handle = member ? String(member.handle) : account.toString();
     const status = worker.is_active ? `active` : `inactive`;
-    let stake: Stake, reward: RewardRelationship;
+    let stake: Stake | undefined = undefined
+    let reward: RewardRelationship | undefined = undefined
 
     if (worker.role_stake_profile.isSome) {
       const roleStakeProfile = worker.role_stake_profile.unwrap();
@@ -77,7 +78,9 @@ export const getWorkerRewards = async (
         worker.reward_relationship.unwrap();
       reward = await getWorkerReward(api, hash, rewardId);
     }
-    workers.push({ id, stake, reward, status, handle, account, memberId });
+    if (stake && reward) {
+      workers.push({ id, stake, reward, status, handle, account, memberId });
+    }
   }
   return workers;
 };
@@ -167,7 +170,7 @@ export const getActiveValidators = async (
 ): Promise<AccountId[]> => {
   const block = await getBlock(api, hash);
   let currentBlockNr = block.block.header.number.toNumber();
-  let activeValidators: AccountId[];
+  let activeValidators: AccountId[] | undefined = undefined;
   do {
     const hash: Hash = await getBlockHash(api, currentBlockNr);
     const validators: AccountId[] = await getValidators(api, hash);

+ 10 - 0
types.ts

@@ -130,3 +130,13 @@ export interface Exchange {
   status: string;
   xmrAddress: string;
 }
+
+export class Media {
+  constructor(public id: number, public title: string) {
+  }
+}
+
+export class Channel {
+  constructor(public id: number, public title: string) {
+  }
+}