From c7f0acf9453026634c4f7b2640eefefc1a4763ae Mon Sep 17 00:00:00 2001 From: Francis Rodriguez <39339295+Freshenext@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:03:16 -0400 Subject: [PATCH] DAO-608 Add proposal to queue (#98) --- src/lib/useVoteOnProposal.tsx | 22 +++++++++++++++++++++- src/pages/proposals/[id].tsx | 14 +++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/lib/useVoteOnProposal.tsx b/src/lib/useVoteOnProposal.tsx index be4914a0..21c6bb73 100644 --- a/src/lib/useVoteOnProposal.tsx +++ b/src/lib/useVoteOnProposal.tsx @@ -29,11 +29,21 @@ enum ProposalState { export const useVoteOnProposal = (proposalId: string) => { const { address } = useAccount() + // Check if proposal needs queuing + const { data: proposalNeedsQueuing } = useReadContract({ + ...DEFAULT_DAO, + functionName: 'proposalNeedsQueuing', + args: [BigInt(proposalId)], + }) + // First read the proposal to see if it's active const { data: proposalState } = useReadContract({ ...DEFAULT_DAO, functionName: 'state', args: [BigInt(proposalId)], + query: { + refetchInterval: 5000, + }, }) const isProposalActive = proposalState === 1 @@ -61,11 +71,21 @@ export const useVoteOnProposal = (proposalId: string) => { }) } + const onQueueProposal = async () => { + return writeContractAsync({ + ...DEFAULT_DAO, + functionName: 'queue', + args: [BigInt(proposalId)], + }) + } + return { onVote, isProposalActive, didUserVoteAlready: !!hasVoted, proposalState, - proposalStateHuman: proposalState ? ProposalState[proposalState] : '', + proposalStateHuman: proposalState !== undefined ? ProposalState[proposalState] : '', + proposalNeedsQueuing, + onQueueProposal, } } diff --git a/src/pages/proposals/[id].tsx b/src/pages/proposals/[id].tsx index e6b884f9..9be5c049 100644 --- a/src/pages/proposals/[id].tsx +++ b/src/pages/proposals/[id].tsx @@ -62,7 +62,14 @@ const PageWithProposal = (proposal: PageWithProposal) => { const { votingPowerAtSnapshot } = useVotingPowerAtSnapshot(snapshot as bigint) const { threshold, canCreateProposal } = useVotingPower() - const { onVote, isProposalActive, didUserVoteAlready, proposalStateHuman } = useVoteOnProposal(proposalId) + const { + onVote, + isProposalActive, + didUserVoteAlready, + proposalStateHuman, + proposalNeedsQueuing, + onQueueProposal, + } = useVoteOnProposal(proposalId) const cannotCastVote = !isProposalActive || didUserVoteAlready || !canCreateProposal @@ -108,6 +115,11 @@ const PageWithProposal = (proposal: PageWithProposal) => { ) : ( )} + {proposalNeedsQueuing && ['Succeeded', 'Queued'].includes(proposalStateHuman) && ( + + )} {votingModal.isModalOpened && address && (