Joystream Stats před 3 roky
rodič
revize
701d83dfe0
1 změnil soubory, kde provedl 25 přidání a 3 odebrání
  1. 25 3
      rewards.ts

+ 25 - 3
rewards.ts

@@ -20,6 +20,7 @@ import {
   getBlockHash,
   getMint,
   getNextWorker,
+  getMember,
   getWorker,
   getWorkerReward,
   getStake,
@@ -45,8 +46,11 @@ export const getWorkerRewards = async (
   for (let id = 0; id < nextWorkerId; ++id) {
     const worker: WorkerOf = await getWorker(api, group, hash, id);
 
-    // TODO workers fired before the end will be missed out
-    if (!worker.is_active) continue;
+    const account = worker.role_account_id;
+    const memberId = worker.member_id;
+    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;
 
     if (worker.role_stake_profile.isSome) {
@@ -59,11 +63,29 @@ export const getWorkerRewards = async (
       const rewardId: RewardRelationshipId = worker.reward_relationship.unwrap();
       reward = await getWorkerReward(api, hash, rewardId);
     }
-    workers.push({ id, stake, reward });
+    workers.push({ id, stake, reward, status, handle, account, memberId });
   }
   return workers;
 };
 
+export const getWorkerRow = (
+  worker: WorkerReward,
+  earnedStart: number
+): string => {
+  const mtjoy = (mtjoy: number): string => (mtjoy / 1000000).toFixed(1);
+
+  const { id, memberId, account, handle, status, reward } = worker;
+  const earnedEnd = reward.total_reward_received.toNumber();
+  if (!earnedEnd) return ``;
+  const totalEarned = mtjoy(earnedEnd);
+  const earnedTerm = mtjoy(earnedEnd - earnedStart);
+  const amount = reward.amount_per_payout.toNumber();
+  const rewardPerBlock = (amount / Number(reward.payout_interval)).toFixed();
+  const url = `https://pioneer.joystreamstats.live/#/members/${handle}`; // TODO
+  // TODO compare earning to term start and show difference
+  return `| ${id} | [@${handle}](${url}) | ${status} | ${rewardPerBlock} | ${earnedTerm} | ${totalEarned} |\n`;
+};
+
 export const getBurnedTokens = (
   burnAddress: string,
   blocks: [number, CacheEvent[]][]