Skip to content

Commit

Permalink
Fix past councils spending amounts (#4554)
Browse files Browse the repository at this point in the history
* Fix-3225: used BudgetUpdatedEvent instead of BudgetSetEvent

* Fix 3225 : updated test.tsx and mock server.ts

* Fix 4121: migrated proposalExecutedEvent to Proposals

* Fix 4121: updated the totalspent

* Fix 4121 : Removed unnecessary line

* Fix 4121 : Updated test.tsx

* Fix 4121: Updated the code by Thesan's suggestion

* added channelPayerMadeEvent
  • Loading branch information
mkbeefcake authored Nov 15, 2023
1 parent bef916b commit 022aadd
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 148 deletions.
19 changes: 16 additions & 3 deletions packages/ui/src/council/hooks/usePastCouncil.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
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 &&
workingGroupData?.channelPaymentMadeEvents &&
asPastCouncilWithDetails(
workingGroupData.rewardPaidEvents,
workingGroupData.budgetUpdatedEvents,
councilData.electedCouncilByUniqueInput,
councilData.budgetSpendingEvents,
councilData.fundingRequestsApproved
councilData.fundingRequestsApproved,
workingGroupData.channelPaymentMadeEvents
),
}
}
9 changes: 6 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,13 @@ 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 && pastCouncil && pastCouncil.totalSpent,
spentOnProposals: data && getSpentOnProposals(data.fundingRequestsApproved),
}
}
248 changes: 131 additions & 117 deletions packages/ui/src/council/queries/__generated__/council.generated.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

2 comments on commit 022aadd

@vercel
Copy link

@vercel vercel bot commented on 022aadd Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 022aadd Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pioneer-2 – ./

pioneer-2.vercel.app
pioneer-2-joystream.vercel.app
pioneer-2-git-dev-joystream.vercel.app

Please sign in to comment.