Skip to content

Commit

Permalink
Merge pull request #354 from ourzora/proposal-number-nav
Browse files Browse the repository at this point in the history
Update proposal page to work with proposal numbers
  • Loading branch information
neokry authored Aug 24, 2023
2 parents 905ee17 + cb8d16d commit dff4e8a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 27 deletions.
7 changes: 5 additions & 2 deletions apps/web/src/data/subgraph/queries/proposalOGMetadata.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
query proposalOGMetadata($proposalId: ID!) {
proposal(id: $proposalId) {
query proposalOGMetadata($where: Proposal_filter!, $first: Int!) {
proposals(where: $where, first: $first) {
...Proposal
votes {
...ProposalVote
}
dao {
name
contractImage
Expand Down
14 changes: 3 additions & 11 deletions apps/web/src/data/subgraph/requests/proposalQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
import { SDK } from 'src/data/subgraph/client'
import {
ProposalFragment,
ProposalOgMetadataQuery,
ProposalQuery,
ProposalVoteFragment as ProposalVote,
} from 'src/data/subgraph/sdk.generated'
import { CHAIN_ID } from 'src/typings'
Expand All @@ -22,14 +20,8 @@ export interface Proposal
votes?: ProposalVote[]
}

export type ProposalQueryLike = ProposalQuery | ProposalOgMetadataQuery

export const formatAndFetchState = async (chainId: CHAIN_ID, data: ProposalQueryLike) => {
if (!data?.proposal) {
return undefined
}

const { executableFrom, expiresAt, calldatas, ...proposal } = data?.proposal
export const formatAndFetchState = async (chainId: CHAIN_ID, data: ProposalFragment) => {
const { executableFrom, expiresAt, calldatas, ...proposal } = data

const baseProposal = {
...proposal,
Expand Down Expand Up @@ -61,7 +53,7 @@ export const getProposal = async (
proposalId,
})

return await formatAndFetchState(chainId, data)
return await formatAndFetchState(chainId, data.proposal!)
} catch (e) {
console.log('err', e)
Sentry.captureException(e)
Expand Down
22 changes: 17 additions & 5 deletions apps/web/src/data/subgraph/sdk.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2118,12 +2118,13 @@ export type ProposalQuery = {
}

export type ProposalOgMetadataQueryVariables = Exact<{
proposalId: Scalars['ID']
where: Proposal_Filter
first: Scalars['Int']
}>

export type ProposalOgMetadataQuery = {
__typename?: 'Query'
proposal?: {
proposals: Array<{
__typename?: 'Proposal'
abstainVotes: number
againstVotes: number
Expand All @@ -2146,6 +2147,13 @@ export type ProposalOgMetadataQuery = {
voteStart: any
snapshotBlockNumber: any
transactionHash: any
votes: Array<{
__typename?: 'ProposalVote'
voter: any
support: ProposalVoteSupport
weight: number
reason?: string | null
}>
dao: {
__typename?: 'DAO'
name: string
Expand All @@ -2156,7 +2164,7 @@ export type ProposalOgMetadataQuery = {
treasuryAddress: any
governorAddress: any
}
} | null
}>
}

export type ProposalsQueryVariables = Exact<{
Expand Down Expand Up @@ -2514,9 +2522,12 @@ export const ProposalDocument = gql`
${ProposalVoteFragmentDoc}
`
export const ProposalOgMetadataDocument = gql`
query proposalOGMetadata($proposalId: ID!) {
proposal(id: $proposalId) {
query proposalOGMetadata($where: Proposal_filter!, $first: Int!) {
proposals(where: $where, first: $first) {
...Proposal
votes {
...ProposalVote
}
dao {
name
contractImage
Expand All @@ -2529,6 +2540,7 @@ export const ProposalOgMetadataDocument = gql`
}
}
${ProposalFragmentDoc}
${ProposalVoteFragmentDoc}
`
export const ProposalsDocument = gql`
query proposals($where: Proposal_filter, $first: Int!, $skip: Int) {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/modules/auction/components/AuctionPaused.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const AuctionPaused = () => {
shallow={!pausedProposal?.proposalId}
href={
pausedProposal?.proposalId
? `/dao/${query.network}/${query.token}/vote/${pausedProposal?.proposalId}`
? `/dao/${query.network}/${query.token}/vote/${pausedProposal?.proposalNumber}`
: `/dao/${query.network}/${query.token}?tab=activity`
}
>
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/modules/proposal/components/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export const ProposalCard: React.FC<ProposalCardProps> = ({
return (
<Link
href={
collection ? `/dao/${router?.query.network}/${collection}/vote/${proposalId}` : ''
collection
? `/dao/${router?.query.network}/${collection}/vote/${proposalNumber}`
: ''
}
passHref
>
Expand Down
26 changes: 19 additions & 7 deletions apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
formatAndFetchState,
getProposal,
} from 'src/data/subgraph/requests/proposalQuery'
import { Proposal_Filter } from 'src/data/subgraph/sdk.generated'
import { getDaoLayout } from 'src/layouts/DaoLayout'
import { DaoContractAddresses, SectionHandler } from 'src/modules/dao'
import {
Expand Down Expand Up @@ -107,7 +108,7 @@ export default VotePage

export const getServerSideProps: GetServerSideProps = async ({ params, req, res }) => {
const collection = params?.token as AddressType
const proposalId = params?.id as `0x${string}`
const proposalIdOrNumber = params?.id as `0x${string}`
const network = params?.network as string

const chain = PUBLIC_DEFAULT_CHAINS.find((x) => x.slug === network)
Expand All @@ -121,11 +122,22 @@ export const getServerSideProps: GetServerSideProps = async ({ params, req, res
const env = process.env.VERCEL_ENV || 'development'
const protocol = env === 'development' ? 'http' : 'https'

const data = await SDK.connect(chain.id).proposalOGMetadata({
proposalId,
})
let where: Proposal_Filter

if (!data.proposal) {
where = proposalIdOrNumber.startsWith('0x')
? {
proposalId: proposalIdOrNumber,
}
: { proposalNumber: parseInt(proposalIdOrNumber), dao: collection.toLowerCase() }

const data = await SDK.connect(chain.id)
.proposalOGMetadata({
where,
first: 1,
})
.then((x) => (x.proposals.length > 0 ? x.proposals[0] : undefined))

if (!data) {
return {
notFound: true,
}
Expand Down Expand Up @@ -156,7 +168,7 @@ export const getServerSideProps: GetServerSideProps = async ({ params, req, res
governorAddress,
treasuryAddress,
auctionAddress,
} = data.proposal.dao
} = data.dao

const ogMetadata: ProposalOgMetadata = {
proposal: {
Expand Down Expand Up @@ -200,7 +212,7 @@ export const getServerSideProps: GetServerSideProps = async ({ params, req, res
},
daoName: name,
ogImageURL,
proposalId,
proposalId: proposal.proposalId,
addresses,
},
}
Expand Down

2 comments on commit dff4e8a

@vercel
Copy link

@vercel vercel bot commented on dff4e8a Aug 24, 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:

testnet-nouns-builder – ./apps/web

testnet-nouns-builder-git-main-nouns-builder.vercel.app
testnet-nouns-builder-nouns-builder.vercel.app
testnet.nouns.build

@vercel
Copy link

@vercel vercel bot commented on dff4e8a Aug 24, 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.