Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix council proposal creation #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
34 changes: 16 additions & 18 deletions hooks/useCreateProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ export const useCanCreateProposal = (
const connected = !!wallet?.connected

const realm = useRealmQuery().data?.result
const {
toManyCommunityOutstandingProposalsForUser,
toManyCouncilOutstandingProposalsForUse,
} = useRealm()

const {
power: communityPower,
Expand All @@ -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())}.`
: ''
Expand Down
Loading