Skip to content

Commit

Permalink
Merge pull request #383 from jordanlesich/fixWarning
Browse files Browse the repository at this point in the history
only use alert if proposal is active
  • Loading branch information
jordanlesich authored Oct 12, 2023
2 parents 63140e7 + a9b8b1f commit 3f12d11
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { Meta } from 'src/components/Meta'
import { CACHE_TIMES } from 'src/constants/cacheTimes'
import { PUBLIC_DEFAULT_CHAINS } from 'src/constants/defaultChains'
import SWR_KEYS from 'src/constants/swrKeys'
import {
ProposalState,
getProposalState,
} from 'src/data/contract/requests/getProposalState'
import { SDK } from 'src/data/subgraph/client'
import {
formatAndFetchState,
Expand All @@ -35,6 +39,13 @@ import { useChainStore } from 'src/stores/useChainStore'
import { propPageWrapper } from 'src/styles/Proposals.css'
import { AddressType } from 'src/typings'

const ACTIVE_PROPOSAL_STATES = [
ProposalState.Active,
ProposalState.Pending,
ProposalState.Queued,
ProposalState.Succeeded,
]

export interface VotePageProps {
proposalId: string
daoName: string
Expand Down Expand Up @@ -67,10 +78,25 @@ const VotePage: NextPageWithLayout<VotePageProps> = ({
chainId: chain.id,
})

const { data: proposal } = useSWR([SWR_KEYS.PROPOSAL, chain.id, proposalId], (_, id) =>
getProposal(chain.id, proposalId)
const { data } = useSWR(
[SWR_KEYS.PROPOSAL, chain.id, proposalId, addresses.governor],
async (_, id) => {
try {
const proposal = await getProposal(chain.id, proposalId)
const state = await getProposalState(
chain.id,
addresses.governor as AddressType,
proposalId as AddressType
)
return { proposal, proposalState: state }
} catch (error) {
throw new Error('Proposal Data not found')
}
}
)

const { proposal, proposalState } = data || {}

const sections = React.useMemo(() => {
if (!proposal) return []
return [
Expand All @@ -95,8 +121,9 @@ const VotePage: NextPageWithLayout<VotePageProps> = ({
const isBadActor = BAD_ACTORS.some((baddie) =>
isAddressEqual(proposal.proposer, baddie as AddressType)
)
const isActive = proposalState && ACTIVE_PROPOSAL_STATES.includes(proposalState)
const isPossibleDrain = balance?.value && checkDrain(proposal.values, balance?.value)
const warn = isBadActor || isPossibleDrain
const warn = isActive && (isBadActor || isPossibleDrain)

return (
<Fragment>
Expand Down

2 comments on commit 3f12d11

@vercel
Copy link

@vercel vercel bot commented on 3f12d11 Oct 12, 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.build
testnet-nouns-builder-git-main-nouns-builder.vercel.app
testnet-nouns-builder-nouns-builder.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 3f12d11 Oct 12, 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.