Skip to content

Commit

Permalink
DAO-608 Add proposal to queue (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
Freshenext authored Aug 6, 2024
1 parent 19336f9 commit c7f0acf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/lib/useVoteOnProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}
14 changes: 13 additions & 1 deletion src/pages/proposals/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -108,6 +115,11 @@ const PageWithProposal = (proposal: PageWithProposal) => {
) : (
<Button onClick={votingModal.openModal}>Vote on chain</Button>
)}
{proposalNeedsQueuing && ['Succeeded', 'Queued'].includes(proposalStateHuman) && (
<Button onClick={onQueueProposal} className="mt-2" disabled={proposalStateHuman === 'Queued'}>
Put on Queue
</Button>
)}
{votingModal.isModalOpened && address && (
<VoteProposalModal
onSubmit={handleVoting}
Expand Down

0 comments on commit c7f0acf

Please sign in to comment.