Skip to content

Commit

Permalink
fix: use better implementation with simpler type for useGroupHistoric…
Browse files Browse the repository at this point in the history
…alProposals
  • Loading branch information
wgwz committed Jul 25, 2023
1 parent dd72117 commit 5512fdd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
26 changes: 14 additions & 12 deletions src/hooks/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ export function useGroupHistoricalProposals(groupId?: string) {
if (!client) {
throw Error('graphql client not initialized')
}
const proposals = await Promise.all(
policyIds.map(async (address) => {
const res = await client.request(ProposalsByGroupPolicyAddressDocument, {
groupPolicyAddress: address,
})
return res.allProposals?.nodes.map((p) => {
const proposal = getFragmentData(ProposalItemFragmentDoc, p)
const result = []
for (const address of policyIds) {
const res = await client.request(ProposalsByGroupPolicyAddressDocument, {
groupPolicyAddress: address,
})
if (!!res.allProposals && !!res.allProposals.nodes) {
const { nodes } = res.allProposals
for (const node of nodes) {
const proposal = getFragmentData(ProposalItemFragmentDoc, node)
if (proposal) {
const executorResult =
{
Expand All @@ -140,12 +142,12 @@ export function useGroupHistoricalProposals(groupId?: string) {
votingPeriodEnd: proposal.votingPeriodEnd,
historical: true,
}
return uiProposal
result.push(uiProposal)
}
})
}),
)
return proposals.flat()
}
}
}
return result
},
enabled: !isLoading,
})
Expand Down
5 changes: 1 addition & 4 deletions src/pages/group-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export default function GroupPage() {
isRefetching: isRefetchingBalances,
} = useBalances(groupPolicy?.address)

const derivedProposals = useDerivedProposals(
proposals,
historicalProposals as UIProposal[],
)
const derivedProposals = useDerivedProposals(proposals, historicalProposals)

if (
isLoadingGroup ||
Expand Down

0 comments on commit 5512fdd

Please sign in to comment.