|
@@ -45,9 +45,7 @@ export const filterMethods = {
|
|
|
finalizedSpendingProposals: ({ section, method }: CacheEvent) =>
|
|
|
section === "proposalsEngine" && method === "ProposalStatusUpdated",
|
|
|
sudoSetBalance: ({ section, method }: CacheEvent) =>
|
|
|
- section === "balances" && method === "BalanceSet",
|
|
|
- proposalStatusUpdated: ({ section, method }: CacheEvent) =>
|
|
|
- section === "proposalsEngine" && method === "ProposalStatusUpdated",
|
|
|
+ section == "balances" && method == "BalanceSet",
|
|
|
};
|
|
|
|
|
|
export const getWorkerRewards = async (
|
|
@@ -66,21 +64,19 @@ 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;
|
|
|
- let reward: RewardRelationship;
|
|
|
|
|
|
+ // fetch reward and stake
|
|
|
+ const w: WorkerReward = { id, status, handle, account, memberId };
|
|
|
if (worker.role_stake_profile.isSome) {
|
|
|
const roleStakeProfile = worker.role_stake_profile.unwrap();
|
|
|
- stake = await getStake(api, roleStakeProfile.stake_id, hash);
|
|
|
+ w.stake = await getStake(api, roleStakeProfile.stake_id);
|
|
|
}
|
|
|
|
|
|
if (worker.reward_relationship.isSome) {
|
|
|
- // TODO changing salaries are not reflected
|
|
|
- const rewardId: RewardRelationshipId =
|
|
|
- worker.reward_relationship.unwrap();
|
|
|
- reward = await getWorkerReward(api, hash, rewardId);
|
|
|
+ const id: RewardRelationshipId = worker.reward_relationship.unwrap();
|
|
|
+ w.reward = await getWorkerReward(api, hash, id);
|
|
|
}
|
|
|
- workers.push({ id, stake, reward, status, handle, account, memberId });
|
|
|
+ workers.push(w);
|
|
|
}
|
|
|
return workers;
|
|
|
};
|
|
@@ -92,6 +88,7 @@ export const getWorkerRow = (
|
|
|
const mtjoy = (mtjoy: number): string => (mtjoy / 1000000).toFixed(1);
|
|
|
|
|
|
const { id, memberId, account, handle, status, reward } = worker;
|
|
|
+ if (!reward) return ``;
|
|
|
const earnedEnd = Number(reward.total_reward_received.toBigInt());
|
|
|
if (!earnedEnd) return ``;
|
|
|
const totalEarned = mtjoy(earnedEnd);
|
|
@@ -121,42 +118,32 @@ export const getFinalizedSpendingProposals = async (
|
|
|
api: ApiPromise,
|
|
|
blocks: [number, CacheEvent[]][]
|
|
|
): Promise<SpendingProposal[]> => {
|
|
|
- const selectedEvents: CacheEvent[] = [];
|
|
|
- blocks.map(([key, proposalEvents]) =>
|
|
|
- proposalEvents.map((proposalEvent) => selectedEvents.push(proposalEvent))
|
|
|
- );
|
|
|
-
|
|
|
let spendingProposals: SpendingProposal[] = [];
|
|
|
- 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);
|
|
|
- if (!proposalInfo) continue;
|
|
|
- try {
|
|
|
+ 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) {
|
|
|
- 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 (!finalizedData.proposalStatus.isApproved || !details.isSpending)
|
|
|
+ return;
|
|
|
+ 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 });
|
|
|
}
|
|
|
- } catch (e) {
|
|
|
- console.error(`Failed to fetch proposal info: ${e.message}`);
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
+ })
|
|
|
+ );
|
|
|
return spendingProposals;
|
|
|
};
|
|
|
|
|
@@ -179,17 +166,16 @@ export const getActiveValidators = async (
|
|
|
): Promise<AccountId[]> => {
|
|
|
const block = await getBlock(api, hash);
|
|
|
let currentBlockNr = block.block.header.number.toNumber();
|
|
|
- let activeValidators: AccountId[];
|
|
|
- do {
|
|
|
+ let activeValidators: AccountId[] = [];
|
|
|
+ while (!activeValidators.length) {
|
|
|
const hash: Hash = await getBlockHash(api, currentBlockNr);
|
|
|
const validators: AccountId[] = await getValidators(api, hash);
|
|
|
if (validators.length) {
|
|
|
let max = await getValidatorCount(api, hash);
|
|
|
activeValidators = validators.slice(0, max);
|
|
|
}
|
|
|
-
|
|
|
if (searchPreviousBlocks) --currentBlockNr;
|
|
|
else ++currentBlockNr;
|
|
|
- } while (!activeValidators);
|
|
|
+ }
|
|
|
return activeValidators;
|
|
|
};
|