Skip to content

Commit

Permalink
Merge pull request #127 from public-assembly/salief/adjust-proposal-q…
Browse files Browse the repository at this point in the history
…uery

small mod to how props are returned
  • Loading branch information
salieflewis authored Jun 30, 2023
2 parents 17adc13 + 27f7780 commit 1d5f73f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-ravens-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@public-assembly/builder-utils': patch
---

getStatefulProposals now returns a proposals state as the corresponding string name. Votes is added to the dao proposals query.
4 changes: 2 additions & 2 deletions packages/builder-utils/src/context/GovernorProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Proposal } from '../subgraph/types/graphql'
import { Hex } from 'viem'
import { getStatefulProposals } from '../lib/getProposalState'

export type StatefulProposal = Omit<Proposal, '__typename' | 'votes'> & {
export type StatefulProposal = Omit<Proposal, '__typename'> & {
state: string
}

Expand All @@ -28,7 +28,7 @@ export function GovernorProvider({ children }: PropsWithChildren) {
if (!daoProposals) return
// prettier-ignore
(async () => {
setProposals(await getStatefulProposals(daoProposals, governorAddress))
setProposals(await getStatefulProposals(daoProposals, governorAddress as Hex))
})()
}, [daoProposals])

Expand Down
29 changes: 15 additions & 14 deletions packages/builder-utils/src/lib/getProposalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@ import { governorAbi } from '../abi'
import { Hash, Hex } from 'viem'
import { readContract } from 'wagmi/actions'

export enum ProposalState {
Pending = 0,
Active = 1,
Canceled = 2,
Defeated = 3,
Succeeded = 4,
Queued = 5,
Expired = 6,
Executed = 7,
Vetoed = 8,
export const ProposalState = {
0: 'Pending',
1: 'Active',
2: 'Canceled',
3: 'Defeated',
4: 'Succeeded',
5: 'Queued',
6: 'Expired',
7: 'Executed',
8: 'Vetoed',
}

export const getProposalState = async (governorAddress: Hex, proposalId: Hash) => {
return (await readContract({
return await readContract({
address: governorAddress,
abi: governorAbi,
functionName: 'state',
args: [proposalId],
})) as ProposalState
})
}

export const getStatefulProposals = async (daoProposals, governorAddress) => {
export const getStatefulProposals = async (daoProposals, governorAddress: Hex) => {
const statefulProposals = await Promise.all(
daoProposals.map(async (proposal) => {
const state = await getProposalState(governorAddress, proposal.id)
return { ...proposal, state }
const stateString = ProposalState[state] // Access the string value from the ProposalState object
return { ...proposal, state: stateString }
})
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function useProposalDetailsQuery({ proposalId }: { proposalId: string })
transactionHash: proposalDetails?.proposal?.transactionHash,
governorAddress: proposalDetails?.proposal?.dao.governorAddress,
tokenAddress: proposalDetails?.proposal?.dao.tokenAddress,
votes: proposalDetails?.proposal?.votes,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export const PROPOSAL_DETAILS_QUERY = graphql(`
governorAddress
tokenAddress
}
votes {
reason
support
voter
weight
}
}
}
`)
6 changes: 3 additions & 3 deletions packages/builder-utils/src/subgraph/types/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const documents = {
types.HistoricalAuctionDocument,
'\n query HistoricalToken($id: ID!, $tokenId: BigInt!) {\n dao(id: $id) {\n tokens(where: { tokenId: $tokenId }) {\n tokenId\n name\n owner\n mintedAt\n image\n }\n }\n }\n':
types.HistoricalTokenDocument,
'\n query ProposalDetails($proposalId: ID!) {\n proposal(id: $proposalId) {\n abstainVotes\n againstVotes\n calldatas\n canceled\n description\n descriptionHash\n executableFrom\n executed\n expiresAt\n forVotes\n proposalId\n proposalNumber\n proposalThreshold\n proposer\n queued\n quorumVotes\n targets\n timeCreated\n title\n values\n vetoed\n voteCount\n voteEnd\n voteStart\n snapshotBlockNumber\n transactionHash\n dao {\n governorAddress\n tokenAddress\n }\n }\n }\n':
'\n query ProposalDetails($proposalId: ID!) {\n proposal(id: $proposalId) {\n abstainVotes\n againstVotes\n calldatas\n canceled\n description\n descriptionHash\n executableFrom\n executed\n expiresAt\n forVotes\n proposalId\n proposalNumber\n proposalThreshold\n proposer\n queued\n quorumVotes\n targets\n timeCreated\n title\n values\n vetoed\n voteCount\n voteEnd\n voteStart\n snapshotBlockNumber\n transactionHash\n dao {\n governorAddress\n tokenAddress\n }\n votes {\n reason\n support\n voter\n weight\n }\n }\n }\n':
types.ProposalDetailsDocument,
'\n query ProposalVotes($proposalId: ID!) {\n proposal(id: $proposalId) {\n votes {\n reason\n support\n voter\n weight\n }\n }\n }\n':
types.ProposalVotesDocument,
Expand Down Expand Up @@ -93,8 +93,8 @@ export function graphql(
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: '\n query ProposalDetails($proposalId: ID!) {\n proposal(id: $proposalId) {\n abstainVotes\n againstVotes\n calldatas\n canceled\n description\n descriptionHash\n executableFrom\n executed\n expiresAt\n forVotes\n proposalId\n proposalNumber\n proposalThreshold\n proposer\n queued\n quorumVotes\n targets\n timeCreated\n title\n values\n vetoed\n voteCount\n voteEnd\n voteStart\n snapshotBlockNumber\n transactionHash\n dao {\n governorAddress\n tokenAddress\n }\n }\n }\n'
): typeof documents['\n query ProposalDetails($proposalId: ID!) {\n proposal(id: $proposalId) {\n abstainVotes\n againstVotes\n calldatas\n canceled\n description\n descriptionHash\n executableFrom\n executed\n expiresAt\n forVotes\n proposalId\n proposalNumber\n proposalThreshold\n proposer\n queued\n quorumVotes\n targets\n timeCreated\n title\n values\n vetoed\n voteCount\n voteEnd\n voteStart\n snapshotBlockNumber\n transactionHash\n dao {\n governorAddress\n tokenAddress\n }\n }\n }\n']
source: '\n query ProposalDetails($proposalId: ID!) {\n proposal(id: $proposalId) {\n abstainVotes\n againstVotes\n calldatas\n canceled\n description\n descriptionHash\n executableFrom\n executed\n expiresAt\n forVotes\n proposalId\n proposalNumber\n proposalThreshold\n proposer\n queued\n quorumVotes\n targets\n timeCreated\n title\n values\n vetoed\n voteCount\n voteEnd\n voteStart\n snapshotBlockNumber\n transactionHash\n dao {\n governorAddress\n tokenAddress\n }\n votes {\n reason\n support\n voter\n weight\n }\n }\n }\n'
): typeof documents['\n query ProposalDetails($proposalId: ID!) {\n proposal(id: $proposalId) {\n abstainVotes\n againstVotes\n calldatas\n canceled\n description\n descriptionHash\n executableFrom\n executed\n expiresAt\n forVotes\n proposalId\n proposalNumber\n proposalThreshold\n proposer\n queued\n quorumVotes\n targets\n timeCreated\n title\n values\n vetoed\n voteCount\n voteEnd\n voteStart\n snapshotBlockNumber\n transactionHash\n dao {\n governorAddress\n tokenAddress\n }\n votes {\n reason\n support\n voter\n weight\n }\n }\n }\n']
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
20 changes: 20 additions & 0 deletions packages/builder-utils/src/subgraph/types/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,13 @@ export type ProposalDetailsQuery = {
snapshotBlockNumber: any
transactionHash: any
dao: { __typename?: 'DAO'; governorAddress: any; tokenAddress: any }
votes: Array<{
__typename?: 'ProposalVote'
reason?: string | null
support: ProposalVoteSupport
voter: any
weight: number
}>
} | null
}

Expand Down Expand Up @@ -2735,6 +2742,19 @@ export const ProposalDetailsDocument = {
],
},
},
{
kind: 'Field',
name: { kind: 'Name', value: 'votes' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'reason' } },
{ kind: 'Field', name: { kind: 'Name', value: 'support' } },
{ kind: 'Field', name: { kind: 'Name', value: 'voter' } },
{ kind: 'Field', name: { kind: 'Name', value: 'weight' } },
],
},
},
],
},
},
Expand Down

1 comment on commit 1d5f73f

@vercel
Copy link

@vercel vercel bot commented on 1d5f73f Jun 30, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.