diff --git a/hooks/useCreateProposal.ts b/hooks/useCreateProposal.ts index 434bdfbbe2..6704ac5b92 100644 --- a/hooks/useCreateProposal.ts +++ b/hooks/useCreateProposal.ts @@ -17,6 +17,7 @@ import { proposalQueryKeys } from './queries/proposal' import { createLUTProposal } from 'actions/createLUTproposal' import { useLegacyVoterWeight } from './queries/governancePower' import {useVotingClients} from "@hooks/useVotingClients"; +import { ProgramAccount, TokenOwnerRecord } from '@solana/spl-governance' export default function useCreateProposal() { const connection = useLegacyConnectionContext() @@ -38,6 +39,7 @@ export default function useCreateProposal() { voteByCouncil = false, isDraft = false, utilizeLookupTable, + myDelegatedTors }: { title: string description: string @@ -45,7 +47,8 @@ export default function useCreateProposal() { instructionsData: InstructionDataWithHoldUpTime[] voteByCouncil?: boolean isDraft?: boolean - utilizeLookupTable?: boolean + utilizeLookupTable?: boolean, + myDelegatedTors?: ProgramAccount[] | undefined }) => { const { result: selectedGovernance } = await fetchGovernanceByPubkey( connection.current, @@ -54,10 +57,13 @@ export default function useCreateProposal() { const minCouncilTokensToCreateProposal = selectedGovernance?.account.config.minCouncilTokensToCreateProposal const councilPower = ownVoterWeight?.councilTokenRecord?.account.governingTokenDepositAmount - const ownTokenRecord = + const ownTokenRecord = myDelegatedTors ? + myDelegatedTors[0] : minCouncilTokensToCreateProposal && councilPower && councilPower >= minCouncilTokensToCreateProposal ? ownVoterWeight?.councilTokenRecord : ownVoterWeight?.communityTokenRecord + + console.log(ownTokenRecord?.pubkey.toBase58()) if (!ownTokenRecord) throw new Error('token owner record does not exist') if (!selectedGovernance) throw new Error('governance not found') @@ -113,11 +119,12 @@ export default function useCreateProposal() { const propose = ( params: Omit[0], 'governance'> & { - governance: PublicKey + governance: PublicKey, + myDelegatedTors?: ProgramAccount[] | undefined } ) => { - const { governance, ...rest } = params - return handleCreateProposal({ ...rest, governance: { pubkey: governance } }) + const { governance, myDelegatedTors , ...rest} = params + return handleCreateProposal({ ...rest, governance: { pubkey: governance }, myDelegatedTors }) } const proposeMultiChoice = async ({ diff --git a/hub/components/EditRealmConfig/index.tsx b/hub/components/EditRealmConfig/index.tsx index 8f1864f08b..59bcac2cb2 100644 --- a/hub/components/EditRealmConfig/index.tsx +++ b/hub/components/EditRealmConfig/index.tsx @@ -32,6 +32,7 @@ import { Form } from './Form'; import * as gql from './gql'; import { RealmHeader } from './RealmHeader'; import { Summary } from './Summary'; +import { useTokenOwnerRecordsDelegatedToUser } from '@hooks/queries/tokenOwnerRecord'; type Governance = TypeOf< typeof gql.getGovernanceResp @@ -167,6 +168,8 @@ export function EditRealmConfig(props: Props) { } }, [governanceResult._tag]); + const myDelegationPower = useTokenOwnerRecordsDelegatedToUser().data + return pipe( result, RE.match( @@ -321,6 +324,7 @@ export function EditRealmConfig(props: Props) { prerequisiteInstructions: [], })), governance: governance.governanceAddress, + myDelegatedTors: myDelegationPower }); if (proposalAddress) { diff --git a/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx b/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx index f93190a006..fff4423fcf 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx @@ -9,7 +9,6 @@ import { import { NewProposalContext } from '../../new' import GovernedAccountSelect from '../GovernedAccountSelect' import useGovernanceAssets from '@hooks/useGovernanceAssets' -import { useLegacyVoterWeight } from '@hooks/queries/governancePower' const Empty = ({ index, governance, @@ -20,7 +19,6 @@ const Empty = ({ const [form, setForm] = useState({ governedAccount: undefined, }) - const { result: ownVoterWeight } = useLegacyVoterWeight() const { assetAccounts } = useGovernanceAssets() const shouldBeGoverned = !!(index !== 0 && governance) const [formErrors, setFormErrors] = useState({}) @@ -55,9 +53,7 @@ const Empty = ({ return ( - ownVoterWeight?.canCreateProposal(x.governance.account.config) - )} + governedAccounts={assetAccounts} onChange={(value) => { handleSetForm({ value, propertyName: 'governedAccount' }) }} diff --git a/pages/dao/[symbol]/proposal/new.tsx b/pages/dao/[symbol]/proposal/new.tsx index b543278a20..9ccfde18a9 100644 --- a/pages/dao/[symbol]/proposal/new.tsx +++ b/pages/dao/[symbol]/proposal/new.tsx @@ -141,6 +141,7 @@ import PythRecoverAccount from './components/instructions/Pyth/PythRecoverAccoun import { useVoteByCouncilToggle } from '@hooks/useVoteByCouncilToggle' import BurnTokens from './components/instructions/BurnTokens' import RemoveLockup from './components/instructions/Validators/removeLockup' +import { useTokenOwnerRecordsDelegatedToUser } from '@hooks/queries/tokenOwnerRecord' const TITLE_LENGTH_LIMIT = 130 // the true length limit is either at the tx size level, and maybe also the total account size level (I can't remember) @@ -385,6 +386,7 @@ const New = () => { instructionsData, voteByCouncil, isDraft, + myDelegatedTors: myDelegationPower }) const url = fmtUrlWithCluster( @@ -637,6 +639,8 @@ const New = () => { [governance?.pubkey?.toBase58()] ) + const myDelegationPower = useTokenOwnerRecordsDelegatedToUser().data + return (