From 858d85fd61d6805023d85a5bb9014b89e2589aef Mon Sep 17 00:00:00 2001 From: mkbeefcake Date: Fri, 6 Oct 2023 06:19:00 +0000 Subject: [PATCH] Fix 4121: updated the totalspent --- packages/ui/src/council/hooks/usePastCouncil.ts | 15 +++++++++++++-- .../ui/src/council/hooks/usePastCouncilStats.ts | 10 +++++++--- packages/ui/src/council/types/PastCouncil.ts | 11 ++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/council/hooks/usePastCouncil.ts b/packages/ui/src/council/hooks/usePastCouncil.ts index b8e55bee91..cf850055a1 100644 --- a/packages/ui/src/council/hooks/usePastCouncil.ts +++ b/packages/ui/src/council/hooks/usePastCouncil.ts @@ -1,5 +1,5 @@ import { useCouncilBlockRange } from '@/council/hooks/useCouncilBlockRange' -import { useGetPastCouncilQuery } from '@/council/queries' +import { useGetPastCouncilQuery, useGetPastCouncilWorkingGroupsQuery } from '@/council/queries' import { asPastCouncilWithDetails } from '@/council/types/PastCouncil' export const usePastCouncil = (id: string) => { @@ -7,13 +7,24 @@ export const usePastCouncil = (id: string) => { const { loading: loadingData, data: councilData } = useGetPastCouncilQuery({ variables: { id, fromBlock, toBlock } }) + const { loading: loadingWorkingGroup, data: workingGroupData } = useGetPastCouncilWorkingGroupsQuery({ + variables: { + fromBlock: fromBlock, + toBlock: toBlock, + }, + }) + return { - isLoading: loadingRange || loadingData, + isLoading: loadingRange || loadingData || loadingWorkingGroup, council: councilData?.electedCouncilByUniqueInput && councilData?.budgetSpendingEvents && councilData?.fundingRequestsApproved && + workingGroupData?.rewardPaidEvents && + workingGroupData?.budgetUpdatedEvents && asPastCouncilWithDetails( + workingGroupData.rewardPaidEvents, + workingGroupData.budgetUpdatedEvents, councilData.electedCouncilByUniqueInput, councilData.budgetSpendingEvents, councilData.fundingRequestsApproved diff --git a/packages/ui/src/council/hooks/usePastCouncilStats.ts b/packages/ui/src/council/hooks/usePastCouncilStats.ts index 4fb8275d2c..16f0a4d73b 100644 --- a/packages/ui/src/council/hooks/usePastCouncilStats.ts +++ b/packages/ui/src/council/hooks/usePastCouncilStats.ts @@ -1,5 +1,6 @@ +import { usePastCouncil } from '@/council/hooks/usePastCouncil' import { useGetCouncilBlockRangeQuery, useGetPastCouncilStatsQuery } from '@/council/queries' -import { getSpentOnProposals, getTotalSpent } from '@/council/types/PastCouncil' +import { getSpentOnProposals } from '@/council/types/PastCouncil' export const usePastCouncilStats = (id: string) => { const { loading: loadingRange, data: rangeData } = useGetCouncilBlockRangeQuery({ @@ -19,11 +20,14 @@ export const usePastCouncilStats = (id: string) => { }, }) + const { isLoading: loadingCouncil, council: pastCouncil } = usePastCouncil(id) + return { - isLoading: loadingRange || loadingData, + isLoading: loadingRange || loadingData || loadingCouncil, proposalsApproved: data?.proposalsApproved?.totalCount ?? 0, proposalsRejected: (data?.proposalsRejected?.totalCount || 0) + (data?.proposalsSlashed?.totalCount || 0), - totalSpent: data && getTotalSpent(data.budgetSpendingEvents), + // totalSpent: data && getTotalSpent(data.budgetSpendingEvents), + totalSpent: data && pastCouncil && pastCouncil.totalSpent, spentOnProposals: data && getSpentOnProposals(data.fundingRequestsApproved), } } diff --git a/packages/ui/src/council/types/PastCouncil.ts b/packages/ui/src/council/types/PastCouncil.ts index cc73b34156..34c7ce2963 100644 --- a/packages/ui/src/council/types/PastCouncil.ts +++ b/packages/ui/src/council/types/PastCouncil.ts @@ -6,8 +6,10 @@ import { asBlock, Block } from '@/common/types' import { CouncilSpendingEventFieldsFragment, FundingRequestApprovedFragment, + PastCouncilBudgetUpdatedEventFieldsFragment, PastCouncilDetailedFieldsFragment, PastCouncilFieldsFragment, + PastCouncilRewardPaidEventFieldsFragment, } from '@/council/queries' import { asProposalDetails, DetailsFragment, FundingRequestDetails } from '@/proposals/types' @@ -45,13 +47,20 @@ export const getSpentOnProposals = (fundingRequests: FundingRequestApprovedFragm } export const asPastCouncilWithDetails = ( + workingGroupRewardPaidEvents: PastCouncilRewardPaidEventFieldsFragment[], + workingGroupBudgets: PastCouncilBudgetUpdatedEventFieldsFragment[], councilFields: PastCouncilDetailedFieldsFragment, spendingEvents: CouncilSpendingEventFieldsFragment[], fundingRequestsApproved: FundingRequestApprovedFragment[] ): PastCouncilWithDetails => { return { ...asPastCouncil(councilFields), - totalSpent: getTotalSpent(spendingEvents), + // totalSpent: getTotalSpent(spendingEvents), + totalSpent: councilFields.councilMembers + .reduce((a, b) => a.add(new BN(b.accumulatedReward)), BN_ZERO) + .add(workingGroupBudgets.reduce((a, b) => a.add(new BN(b.budgetChangeAmount)), BN_ZERO)) + .add(getSpentOnProposals(fundingRequestsApproved)) + .add(workingGroupRewardPaidEvents.reduce((a, b) => a.add(new BN(b.amount)), BN_ZERO)), totalMissedRewards: councilFields.councilMembers.reduce((a, b) => a.add(new BN(b.unpaidReward)), BN_ZERO).neg(), totalPaidRewards: councilFields.councilMembers.reduce((a, b) => a.add(new BN(b.accumulatedReward)), BN_ZERO), totalSpentOnProposals: getSpentOnProposals(fundingRequestsApproved),