|
@@ -66,8 +66,8 @@ export const getWorkerRewards = async (
|
|
const member: Membership = await getMember(api, memberId, hash);
|
|
const member: Membership = await getMember(api, memberId, hash);
|
|
const handle = member ? String(member.handle) : account.toString();
|
|
const handle = member ? String(member.handle) : account.toString();
|
|
const status = worker.is_active ? `active` : `inactive`;
|
|
const status = worker.is_active ? `active` : `inactive`;
|
|
- let stake: Stake | undefined = undefined
|
|
|
|
- let reward: RewardRelationship | undefined = undefined
|
|
|
|
|
|
+ let stake: Stake;
|
|
|
|
+ let reward: RewardRelationship;
|
|
|
|
|
|
if (worker.role_stake_profile.isSome) {
|
|
if (worker.role_stake_profile.isSome) {
|
|
const roleStakeProfile = worker.role_stake_profile.unwrap();
|
|
const roleStakeProfile = worker.role_stake_profile.unwrap();
|
|
@@ -80,9 +80,7 @@ export const getWorkerRewards = async (
|
|
worker.reward_relationship.unwrap();
|
|
worker.reward_relationship.unwrap();
|
|
reward = await getWorkerReward(api, hash, rewardId);
|
|
reward = await getWorkerReward(api, hash, rewardId);
|
|
}
|
|
}
|
|
- if (stake && reward) {
|
|
|
|
- workers.push({ id, stake, reward, status, handle, account, memberId });
|
|
|
|
- }
|
|
|
|
|
|
+ workers.push({ id, stake, reward, status, handle, account, memberId });
|
|
}
|
|
}
|
|
return workers;
|
|
return workers;
|
|
};
|
|
};
|
|
@@ -124,32 +122,34 @@ export const getFinalizedSpendingProposals = async (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
blocks: [number, CacheEvent[]][]
|
|
blocks: [number, CacheEvent[]][]
|
|
): Promise<SpendingProposal[]> => {
|
|
): Promise<SpendingProposal[]> => {
|
|
|
|
+ const selectedEvents: CacheEvent[] = [];
|
|
|
|
+ blocks.map(([key, proposalEvents]) =>
|
|
|
|
+ proposalEvents.map((proposalEvent) => selectedEvents.push(proposalEvent))
|
|
|
|
+ );
|
|
|
|
+
|
|
let spendingProposals: SpendingProposal[] = [];
|
|
let spendingProposals: SpendingProposal[] = [];
|
|
- await blocks.forEach(([key, proposals]) =>
|
|
|
|
- proposals.forEach(async (proposalEvent) => {
|
|
|
|
- let statusUpdateData = proposalEvent.data[1] as any;
|
|
|
|
- const finalizedAt = statusUpdateData.finalized.finalizedAt;
|
|
|
|
- if (!(statusUpdateData.finalized && finalizedAt)) return;
|
|
|
|
-
|
|
|
|
- const proposalId = proposalEvent.data[0] as ProposalId;
|
|
|
|
- const id = +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)
|
|
|
|
- return;
|
|
|
|
|
|
+ for (const proposalEvent of selectedEvents) {
|
|
|
|
+ let statusUpdateData = proposalEvent.data[1] as any;
|
|
|
|
+ const finalizedAt = statusUpdateData.finalized.finalizedAt;
|
|
|
|
+ if (!(statusUpdateData.finalized && finalizedAt)) continue;
|
|
|
|
+
|
|
|
|
+ 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;
|
|
let approvedData = finalizedData.proposalStatus.asApproved;
|
|
- if (!approvedData.isExecuted) return;
|
|
|
|
- if (!spendingProposals.some((proposal) => proposal.id === id)) {
|
|
|
|
|
|
+ if (!approvedData.isExecuted) continue;
|
|
|
|
+ if (!spendingProposals.some((proposal) => proposal.id === +proposalId)) {
|
|
const title = proposalInfo.title.toString();
|
|
const title = proposalInfo.title.toString();
|
|
const amount = +details.asSpending[0];
|
|
const amount = +details.asSpending[0];
|
|
- spendingProposals.push({ id, title, amount });
|
|
|
|
|
|
+ spendingProposals.push({ id: +proposalId, title, amount });
|
|
}
|
|
}
|
|
- })
|
|
|
|
- );
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return spendingProposals;
|
|
return spendingProposals;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -172,7 +172,7 @@ export const getActiveValidators = async (
|
|
): Promise<AccountId[]> => {
|
|
): Promise<AccountId[]> => {
|
|
const block = await getBlock(api, hash);
|
|
const block = await getBlock(api, hash);
|
|
let currentBlockNr = block.block.header.number.toNumber();
|
|
let currentBlockNr = block.block.header.number.toNumber();
|
|
- let activeValidators: AccountId[] | undefined = undefined;
|
|
|
|
|
|
+ let activeValidators: AccountId[];
|
|
do {
|
|
do {
|
|
const hash: Hash = await getBlockHash(api, currentBlockNr);
|
|
const hash: Hash = await getBlockHash(api, currentBlockNr);
|
|
const validators: AccountId[] = await getValidators(api, hash);
|
|
const validators: AccountId[] = await getValidators(api, hash);
|
|
@@ -183,6 +183,6 @@ export const getActiveValidators = async (
|
|
|
|
|
|
if (searchPreviousBlocks) --currentBlockNr;
|
|
if (searchPreviousBlocks) --currentBlockNr;
|
|
else ++currentBlockNr;
|
|
else ++currentBlockNr;
|
|
- } while (activeValidators == undefined);
|
|
|
|
|
|
+ } while (!activeValidators);
|
|
return activeValidators;
|
|
return activeValidators;
|
|
};
|
|
};
|