From 2c7f144ccfd61e2f56da5befd368b693fad12a0c Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 11 Oct 2023 17:04:49 -0700 Subject: [PATCH 1/2] only use alert if proposal is active --- .../pages/dao/[network]/[token]/vote/[id].tsx | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx b/apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx index 3765a9c5..ae24cdbb 100644 --- a/apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx +++ b/apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx @@ -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, @@ -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 @@ -67,10 +78,28 @@ const VotePage: NextPageWithLayout = ({ 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 || {} + + console.log('proposal', proposal) + console.log('proposalState', proposalState) + const sections = React.useMemo(() => { if (!proposal) return [] return [ @@ -95,8 +124,9 @@ const VotePage: NextPageWithLayout = ({ 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 ( From 17c93e735b8fc70f473c62e17199438b44cc2233 Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 11 Oct 2023 17:12:53 -0700 Subject: [PATCH 2/2] clean --- apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx b/apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx index ae24cdbb..fcf8610a 100644 --- a/apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx +++ b/apps/web/src/pages/dao/[network]/[token]/vote/[id].tsx @@ -97,9 +97,6 @@ const VotePage: NextPageWithLayout = ({ const { proposal, proposalState } = data || {} - console.log('proposal', proposal) - console.log('proposalState', proposalState) - const sections = React.useMemo(() => { if (!proposal) return [] return [