Bläddra i källkod

rewards: fix getFinalizedSpendingProposals

Joystream Stats 2 år sedan
förälder
incheckning
66515fb8c1
1 ändrade filer med 16 tillägg och 15 borttagningar
  1. 16 15
      rewards.ts

+ 16 - 15
rewards.ts

@@ -118,14 +118,14 @@ export const getFinalizedSpendingProposals = async (
   api: ApiPromise,
   blocks: [number, CacheEvent[]][]
 ): Promise<SpendingProposal[]> => {
-  let spendingProposals: SpendingProposal[] = [];
-  await blocks.forEach(([key, proposals]) =>
-    proposals.forEach(async (proposalEvent) => {
-      let statusUpdateData = proposalEvent.data[1] as any;
+  const spendingProposals: SpendingProposal[] = [];
+  for (const [key, events] of blocks) {
+    for (const event of events) {
+      let statusUpdateData = event.data[1] as any;
       const finalizedAt = statusUpdateData.finalized.finalizedAt;
-      if (!(statusUpdateData.finalized && finalizedAt)) return;
+      if (!(statusUpdateData.finalized && finalizedAt)) continue;
 
-      const proposalId = proposalEvent.data[0] as ProposalId;
+      const proposalId = event.data[0] as ProposalId;
       const id = +proposalId;
       const proposalInfo: ProposalOf = await getProposalInfo(api, proposalId);
       const finalizedData = proposalInfo.status.asFinalized;
@@ -134,16 +134,17 @@ export const getFinalizedSpendingProposals = async (
         proposalId
       );
       if (!finalizedData.proposalStatus.isApproved || !details.isSpending)
-        return;
+        continue;
       let approvedData = finalizedData.proposalStatus.asApproved;
-      if (!approvedData.isExecuted) return;
-      if (!spendingProposals.some((proposal) => proposal.id === id)) {
-        const title = proposalInfo.title.toString();
-        const amount = +details.asSpending[0];
-        spendingProposals.push({ id, title, amount });
-      }
-    })
-  );
+      if (!approvedData.isExecuted) continue;
+      if (spendingProposals.some((proposal) => +proposal.id === +id)) continue;
+      const title = String(proposalInfo.title.toHuman());
+      const amount = +details.asSpending[0];
+
+      console.log(`Spent ${amount.toFixed().padStart(8)} on ${id} ${title}`);
+      spendingProposals.push({ id, title, amount });
+    }
+  }
   return spendingProposals;
 };