Skip to content

Commit

Permalink
Fix 4121: updated the totalspent
Browse files Browse the repository at this point in the history
  • Loading branch information
mkbeefcake committed Oct 6, 2023
1 parent eadb910 commit 858d85f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
15 changes: 13 additions & 2 deletions packages/ui/src/council/hooks/usePastCouncil.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
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) => {
const { loadingRange, fromBlock, toBlock } = useCouncilBlockRange(id)

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
Expand Down
10 changes: 7 additions & 3 deletions packages/ui/src/council/hooks/usePastCouncilStats.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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),
}
}
11 changes: 10 additions & 1 deletion packages/ui/src/council/types/PastCouncil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 858d85f

Please sign in to comment.