From 295fd57c8f6d9ff68689a727256df8c77b77b4c2 Mon Sep 17 00:00:00 2001 From: panosdb Date: Sun, 6 Oct 2024 14:11:49 +0300 Subject: [PATCH] Fix council proposal creation --- README.md | 13 +++++++++++++ hooks/useCreateProposal.ts | 34 ++++++++++++++++------------------ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 34a147711..8eca353a0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,16 @@ +# Governance UI + +This codebase holds the Solana DAO Management UI + +## Local setup + +1. Install the node version under `.nvmrc` or run `nvm use` +2. Install dependencies `yarn` +3. `cp .env.sample .env` +4. Start server locally `yarn dev` +5. Visit http://localhost:3000/ + + ### Using custom Swap API endpoints You can set custom URLs via the configuration for any self-hosted Jupiter APIs, like the [V6 Swap API](https://station.jup.ag/docs/apis/self-hosted) or [Paid Hosted APIs](https://station.jup.ag/docs/apis/self-hosted#paid-hosted-apis) Here is an example: diff --git a/hooks/useCreateProposal.ts b/hooks/useCreateProposal.ts index 4a66af135..a24bd2194 100644 --- a/hooks/useCreateProposal.ts +++ b/hooks/useCreateProposal.ts @@ -281,6 +281,10 @@ export const useCanCreateProposal = ( const connected = !!wallet?.connected const realm = useRealmQuery().data?.result + const { + toManyCommunityOutstandingProposalsForUser, + toManyCouncilOutstandingProposalsForUse, + } = useRealm() const { power: communityPower, @@ -294,44 +298,38 @@ export const useCanCreateProposal = ( isReady: councilReady } = useProposeAs('council') - const power = communityPower || councilPower - const proposer = communityPower ? communityProposer : councilProposer - const isReady = communityReady && councilReady + const hasCouncilPower = councilPower && !councilPower.isZero() + const hasCommunityPower = councilPower && !councilPower.isZero() - const { - toManyCommunityOutstandingProposalsForUser, - toManyCouncilOutstandingProposalsForUse, - } = useRealm() + const isReady = communityReady && councilReady + const hasEnoughCouncilPower = hasCouncilPower && + councilPower.gte(governance?.account.config.minCouncilTokensToCreateProposal || new BN(1)) - const minWeightToCreateProposal = (governance?.pubkey == realm?.account.communityMint ? - governance?.account.config.minCommunityTokensToCreateProposal : - governance?.account.config.minCouncilTokensToCreateProposal) || undefined + const hasEnoughCommunityPower = hasCommunityPower && + councilPower.gte(governance?.account.config.minCommunityTokensToCreateProposal || new BN(1)) - const hasEnoughVotingPower = power?.gt(minWeightToCreateProposal || new BN(1)) + const hasEnoughPower = hasEnoughCouncilPower || hasEnoughCommunityPower const canCreateProposal = realm && - hasEnoughVotingPower && + hasEnoughPower && !toManyCommunityOutstandingProposalsForUser && !toManyCouncilOutstandingProposalsForUse - const minWeightToCreateProposalS = minWeightToCreateProposal - ? new BigNumber(minWeightToCreateProposal.toString()).toString() - : "1" - const error = !connected ? 'Connect your wallet to create new proposal' : isReady && !communityPower && !councilPower ? 'There is no governance configuration to create a new proposal' - : !hasEnoughVotingPower - ? `Please select only one account with at least ${minWeightToCreateProposalS} governance power to create a new proposal.` + : !hasEnoughPower + ? `Please select only one account with at either council or community governance power to create a new proposal.` : toManyCommunityOutstandingProposalsForUser ? 'Too many community outstanding proposals. You need to finalize them before creating a new one.' : toManyCouncilOutstandingProposalsForUse ? 'Too many council outstanding proposals. You need to finalize them before creating a new one.' : '' + const proposer = hasEnoughCouncilPower ? councilProposer : communityProposer const warning = proposer ? `Add a proposal as: ${shortenAddress(proposer.toString())}.` : ''