Просмотр исходного кода

rewards:getFinalizedSpendingProposals: catch proposal issue

Joystream Stats 3 лет назад
Родитель
Сommit
000bb8b866
1 измененных файлов с 20 добавлено и 13 удалено
  1. 20 13
      rewards.ts

+ 20 - 13
rewards.ts

@@ -99,7 +99,6 @@ export const getWorkerRow = (
   const amount = Number(reward.amount_per_payout.toBigInt());
   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`;
 };
 
@@ -135,19 +134,27 @@ export const getFinalizedSpendingProposals = async (
 
     const proposalId = proposalEvent.data[0] as ProposalId;
     const proposalInfo: ProposalOf = await getProposalInfo(api, proposalId);
-    const finalizedData = proposalInfo.status.asFinalized;
-    const details: ProposalDetailsOf = await getProposalDetails(
-      api,
-      proposalId
-    );
-    if (finalizedData.proposalStatus.isApproved && details.isSpending) {
-      let approvedData = finalizedData.proposalStatus.asApproved;
-      if (!approvedData.isExecuted) continue;
-      if (!spendingProposals.some((proposal) => proposal.id === +proposalId)) {
-        const title = proposalInfo.title.toString();
-        const amount = +details.asSpending[0];
-        spendingProposals.push({ id: +proposalId, title, amount });
+    if (!proposalInfo) continue;
+    try {
+      const finalizedData = proposalInfo.status.asFinalized;
+      const details: ProposalDetailsOf = await getProposalDetails(
+        api,
+        proposalId
+      );
+      if (finalizedData.proposalStatus.isApproved && details.isSpending) {
+        let approvedData = finalizedData.proposalStatus.asApproved;
+        if (!approvedData.isExecuted) continue;
+        if (
+          !spendingProposals.some((proposal) => proposal.id === +proposalId)
+        ) {
+          const title = proposalInfo.title.toString();
+          const amount = +details.asSpending[0];
+          spendingProposals.push({ id: +proposalId, title, amount });
+        }
       }
+    } catch (e) {
+      console.error(`Failed to fetch proposal info: ${e.message}`);
+      continue;
     }
   }
   return spendingProposals;