From 01b6f2474c5f6802f3d4320ecd791cef18d9acc1 Mon Sep 17 00:00:00 2001 From: 0xShuk Date: Fri, 28 Jun 2024 20:22:26 +0530 Subject: [PATCH 1/5] test-delegation-council --- hooks/useCreateProposal.ts | 11 +++++++++-- .../proposal/components/instructions/Empty.tsx | 3 ++- pages/dao/[symbol]/proposal/new.tsx | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hooks/useCreateProposal.ts b/hooks/useCreateProposal.ts index 434bdfbbe2..b1f78b37fb 100644 --- a/hooks/useCreateProposal.ts +++ b/hooks/useCreateProposal.ts @@ -17,6 +17,8 @@ import { proposalQueryKeys } from './queries/proposal' import { createLUTProposal } from 'actions/createLUTproposal' import { useLegacyVoterWeight } from './queries/governancePower' import {useVotingClients} from "@hooks/useVotingClients"; +import { useTokenOwnerRecordsDelegatedToUser } from './queries/tokenOwnerRecord' +import { ProgramAccount, ProgramAccountWithType, TokenOwnerRecord } from '@solana/spl-governance' export default function useCreateProposal() { const connection = useLegacyConnectionContext() @@ -38,6 +40,7 @@ export default function useCreateProposal() { voteByCouncil = false, isDraft = false, utilizeLookupTable, + myDelegatedTors }: { title: string description: string @@ -45,7 +48,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 +58,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') diff --git a/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx b/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx index f93190a006..6bef4bd070 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx @@ -56,7 +56,8 @@ const Empty = ({ - ownVoterWeight?.canCreateProposal(x.governance.account.config) + // ownVoterWeight?.canCreateProposal(x.governance.account.config) + true )} 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 (
Date: Fri, 28 Jun 2024 20:31:14 +0530 Subject: [PATCH 2/5] add new --- pages/dao/[symbol]/proposal/components/instructions/Empty.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx b/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx index 6bef4bd070..a1214e6f97 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({}) From a1c4617e8edbc86b6c993cc72b6b23c0beb9f184 Mon Sep 17 00:00:00 2001 From: 0xShuk Date: Fri, 28 Jun 2024 20:34:49 +0530 Subject: [PATCH 3/5] remove x --- .../dao/[symbol]/proposal/components/instructions/Empty.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx b/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx index a1214e6f97..fff4423fcf 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/Empty.tsx @@ -53,10 +53,7 @@ const Empty = ({ return ( - // ownVoterWeight?.canCreateProposal(x.governance.account.config) - true - )} + governedAccounts={assetAccounts} onChange={(value) => { handleSetForm({ value, propertyName: 'governedAccount' }) }} From b0363b8308f548da5c57f07f09d629500bcd31db Mon Sep 17 00:00:00 2001 From: 0xShuk Date: Fri, 28 Jun 2024 20:38:22 +0530 Subject: [PATCH 4/5] make optional --- hooks/useCreateProposal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/useCreateProposal.ts b/hooks/useCreateProposal.ts index b1f78b37fb..34b8d9456d 100644 --- a/hooks/useCreateProposal.ts +++ b/hooks/useCreateProposal.ts @@ -49,7 +49,7 @@ export default function useCreateProposal() { voteByCouncil?: boolean isDraft?: boolean utilizeLookupTable?: boolean, - myDelegatedTors: ProgramAccount[] | undefined + myDelegatedTors?: ProgramAccount[] | undefined }) => { const { result: selectedGovernance } = await fetchGovernanceByPubkey( connection.current, From 185ce9f1607925c44bf7620f6ce436b331084cd3 Mon Sep 17 00:00:00 2001 From: 0xShuk Date: Sat, 29 Jun 2024 00:56:25 +0530 Subject: [PATCH 5/5] add on the other page --- hooks/useCreateProposal.ts | 10 +++++----- hub/components/EditRealmConfig/index.tsx | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hooks/useCreateProposal.ts b/hooks/useCreateProposal.ts index 34b8d9456d..6704ac5b92 100644 --- a/hooks/useCreateProposal.ts +++ b/hooks/useCreateProposal.ts @@ -17,8 +17,7 @@ import { proposalQueryKeys } from './queries/proposal' import { createLUTProposal } from 'actions/createLUTproposal' import { useLegacyVoterWeight } from './queries/governancePower' import {useVotingClients} from "@hooks/useVotingClients"; -import { useTokenOwnerRecordsDelegatedToUser } from './queries/tokenOwnerRecord' -import { ProgramAccount, ProgramAccountWithType, TokenOwnerRecord } from '@solana/spl-governance' +import { ProgramAccount, TokenOwnerRecord } from '@solana/spl-governance' export default function useCreateProposal() { const connection = useLegacyConnectionContext() @@ -120,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) {