Skip to content

Commit

Permalink
Fix past councils working groups data (#4553)
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 3225: updated newMissedRewardLevelReachedEvent's block range and removed budgetSetEvent

* Fix 3225: fix lint issue
  • Loading branch information
mkbeefcake authored Sep 27, 2023
1 parent fcba3de commit cfca8af
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
6 changes: 5 additions & 1 deletion packages/ui/src/council/hooks/usePastCouncilWorkingGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export const usePastCouncilWorkingGroups = (id: string) => {
workingGroups:
data &&
data.workingGroups.map(
asPastCouncilWorkingGroup(data.budgetSetEvents, data.rewardPaidEvents, data.newMissedRewardLevelReachedEvents)
asPastCouncilWorkingGroup(
data.rewardPaidEvents,
data.newMissedRewardLevelReachedEvents,
data.budgetUpdatedEvents
)
),
}
}

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

14 changes: 10 additions & 4 deletions packages/ui/src/council/queries/council.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fragment PastCouncilProposalsFields on ProposalVotedEvent {
fragment PastCouncilWorkingGroupFields on WorkingGroup {
id
name
budget
}

fragment PastCouncilBudgetSetEventFields on BudgetSetEvent {
Expand All @@ -39,6 +40,11 @@ fragment PastCouncilNewMissedRewardLevelReachedEventFields on NewMissedRewardLev
newMissedRewardAmount
}

fragment PastCouncilBudgetUpdatedEventFields on BudgetUpdatedEvent {
groupId
budgetChangeAmount
}

fragment ElectedCouncilFields on ElectedCouncil {
id
electedAtBlock
Expand Down Expand Up @@ -243,15 +249,15 @@ query GetPastCouncilWorkingGroups($fromBlock: Int!, $toBlock: Int!) {
workingGroups {
...PastCouncilWorkingGroupFields
}
budgetSetEvents(where: { inBlock_lte: $toBlock }, orderBy: [inBlock_DESC]) {
...PastCouncilBudgetSetEventFields
}
rewardPaidEvents(where: { inBlock_gte: $fromBlock, inBlock_lte: $toBlock }) {
...PastCouncilRewardPaidEventFields
}
newMissedRewardLevelReachedEvents(where: { inBlock_lte: $toBlock }, orderBy: [inBlock_DESC]) {
newMissedRewardLevelReachedEvents(where: { inBlock_gte: $fromBlock, inBlock_lte: $toBlock }) {
...PastCouncilNewMissedRewardLevelReachedEventFields
}
budgetUpdatedEvents(where: { inBlock_gte: $fromBlock, inBlock_lte: $toBlock }) {
...PastCouncilBudgetUpdatedEventFields
}
}

query GetCurrentElection {
Expand Down
10 changes: 6 additions & 4 deletions packages/ui/src/council/types/PastCouncilWorkingGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BN from 'bn.js'
import { BN_ZERO } from '@/common/constants'
import { arrayGroupBy } from '@/common/utils'
import {
PastCouncilBudgetSetEventFieldsFragment,
PastCouncilBudgetUpdatedEventFieldsFragment,
PastCouncilNewMissedRewardLevelReachedEventFieldsFragment,
PastCouncilRewardPaidEventFieldsFragment,
PastCouncilWorkingGroupFieldsFragment,
Expand Down Expand Up @@ -34,9 +34,9 @@ const getTotalMissedReward = (

export const asPastCouncilWorkingGroup =
(
budgetSetEvents: PastCouncilBudgetSetEventFieldsFragment[],
rewardPaidEvents: PastCouncilRewardPaidEventFieldsFragment[],
newMissedRewardLevelReachedEvents: PastCouncilNewMissedRewardLevelReachedEventFieldsFragment[]
newMissedRewardLevelReachedEvents: PastCouncilNewMissedRewardLevelReachedEventFieldsFragment[],
budgetUpdatedEvents: PastCouncilBudgetUpdatedEventFieldsFragment[]
) =>
(fields: PastCouncilWorkingGroupFieldsFragment): PastCouncilWorkingGroup => ({
id: fields.id,
Expand All @@ -45,5 +45,7 @@ export const asPastCouncilWorkingGroup =
.filter((rewardEvent) => rewardEvent.groupId === fields.id)
.reduce((a, b) => a.add(new BN(b.amount)), BN_ZERO),
totalMissedReward: getTotalMissedReward(newMissedRewardLevelReachedEvents, fields.id),
budget: new BN(budgetSetEvents.find((budgetEvent) => budgetEvent.groupId === fields.id)?.newBudget ?? 0),
budget: budgetUpdatedEvents
.filter((updatedEvent) => updatedEvent.groupId === fields.id)
.reduce((a, b) => a.add(new BN(b.budgetChangeAmount)), BN_ZERO),
})
1 change: 1 addition & 0 deletions packages/ui/src/mocks/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const makeServer = (environment = 'development', endpoints = DEFAULT_NETW
workSubmittedEvents: getWhereResolver('WorkSubmittedEvent'),
workSubmittedEventsConnection: getConnectionResolver('WorkSubmittedEventConnection'),
budgetSetEvents: getWhereResolver('BudgetSetEvent'),
budgetUpdatedEvents: getWhereResolver('BudgetUpdatedEvent'),
budgetSpendingEvents: getWhereResolver('BudgetSpendingEvent'),
candidates: getWhereResolver('Candidate'),
candidatesConnection: getConnectionResolver('CandidateConnection'),
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/test/council/pages/PastCouncil.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,14 @@ describe('UI: Past Council page', () => {
)
seedEvent(
{
id: '1',
inBlock: 1,
createdAt: '2021-09-14T11:54:56.127Z',
network: 'OLYMPIA',
groupId: WORKER_DATA.groupId,
newBudget: 80000,
budgetChangeAmount: 80000,
},
'BudgetSetEvent',
'BudgetUpdatedEvent',
mockServer.server
)
seedEvent(
Expand Down

2 comments on commit cfca8af

@vercel
Copy link

@vercel vercel bot commented on cfca8af Sep 27, 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 cfca8af Sep 27, 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-git-dev-joystream.vercel.app
pioneer-2-joystream.vercel.app

Please sign in to comment.