From 73237169fad7cf486c834e304535294fe9dd19a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezi=C5=84ski?= Date: Thu, 21 Jul 2022 22:59:16 +0200 Subject: [PATCH] revert add signatory (#882) * revert add signatory * fix --- actions/createProposal.ts | 24 ++++++++++++++++++++++-- actions/signOffProposal.ts | 10 +++++----- components/ProposalActions.tsx | 8 ++------ hooks/useGovernanceAssets.ts | 4 ++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/actions/createProposal.ts b/actions/createProposal.ts index b05aa62375..d26234478f 100644 --- a/actions/createProposal.ts +++ b/actions/createProposal.ts @@ -14,6 +14,7 @@ import { TokenOwnerRecord, VoteType, withCreateProposal, + getSignatoryRecordAddress, } from '@solana/spl-governance' import { RpcContext } from '@solana/spl-governance' import { withInsertTransaction } from '@solana/spl-governance' @@ -29,6 +30,7 @@ import { chunks } from '@utils/helpers' import { UiInstruction } from '@utils/uiTypes/proposalCreationTypes' import { VotingClient } from '@utils/uiTypes/VotePlugin' import { NftVoterClient } from '@solana/governance-program-library' +import { withAddSignatory } from '@solana/spl-governance' export interface InstructionDataWithHoldUpTime { data: InstructionData | null @@ -132,6 +134,24 @@ export const createProposal = async ( plugin?.voterWeightPk ) + await withAddSignatory( + instructions, + programId, + programVersion, + proposalAddress, + tokenOwnerRecord.pubkey, + governanceAuthority, + signatory, + payer + ) + + // TODO: Return signatoryRecordAddress from the SDK call + const signatoryRecordAddress = await getSignatoryRecordAddress( + programId, + proposalAddress, + signatory + ) + const insertInstructions: TransactionInstruction[] = [] const splitToChunkByDefault = instructionsData.filter( (x) => x.chunkSplitByDefault @@ -180,8 +200,8 @@ export const createProposal = async ( governance, proposalAddress, signatory, - undefined, - tokenOwnerRecord.pubkey + signatoryRecordAddress, + undefined ) } diff --git a/actions/signOffProposal.ts b/actions/signOffProposal.ts index 2fb4e76e06..551bd23270 100644 --- a/actions/signOffProposal.ts +++ b/actions/signOffProposal.ts @@ -19,7 +19,7 @@ export const signOffProposal = async ( { connection, wallet, programId }: RpcContext, realmPk: PublicKey, proposal: ProgramAccount, - signatoryRecord: ProgramAccount | undefined + signatoryRecord: ProgramAccount ) => { const instructions: TransactionInstruction[] = [] const signers: Keypair[] = [] @@ -30,7 +30,7 @@ export const signOffProposal = async ( connection, programId ) - const hasNoSignatories = proposal.account.signatoriesCount === 0 + withSignOffProposal( instructions, programId, @@ -38,9 +38,9 @@ export const signOffProposal = async ( realmPk, proposal.account.governance, proposal.pubkey, - !hasNoSignatories ? signatoryRecord!.account.signatory : wallet.publicKey!, - !hasNoSignatories ? signatoryRecord!.pubkey! : undefined, - !hasNoSignatories ? undefined : proposal.account.tokenOwnerRecord + signatoryRecord.account.signatory, + signatoryRecord?.pubkey, + undefined ) const transaction = new Transaction() diff --git a/components/ProposalActions.tsx b/components/ProposalActions.tsx index 51f19795d9..b46f51f6e4 100644 --- a/components/ProposalActions.tsx +++ b/components/ProposalActions.tsx @@ -23,7 +23,7 @@ const ProposalActionsPanel = () => { const { governance, proposal, proposalOwner } = useWalletStore( (s) => s.selectedProposal ) - const { realmInfo, ownTokenRecord, ownCouncilTokenRecord } = useRealm() + const { realmInfo } = useRealm() const wallet = useWalletStore((s) => s.current) const connected = useWalletStore((s) => s.connected) const hasVoteTimeExpired = useHasVoteTimeExpired(governance, proposal!) @@ -57,11 +57,7 @@ const ProposalActionsPanel = () => { }, [proposal, realmInfo, walletPk]) const canSignOff = - (signatoryRecord || - proposal?.account.tokenOwnerRecord.toBase58() === - ownTokenRecord?.pubkey.toBase58() || - proposal?.account.tokenOwnerRecord.toBase58() === - ownCouncilTokenRecord?.pubkey.toBase58()) && + signatoryRecord && (proposal?.account.state === ProposalState.Draft || proposal?.account.state === ProposalState.SigningOff) diff --git a/hooks/useGovernanceAssets.ts b/hooks/useGovernanceAssets.ts index 2cd5d9b083..b0bd3dd6c7 100644 --- a/hooks/useGovernanceAssets.ts +++ b/hooks/useGovernanceAssets.ts @@ -230,8 +230,8 @@ export default function useGovernanceAssets() { id: Instructions.UpdateTokenMetadata, name: 'Update Token Metadata', isVisible: canUseAuthorityInstruction, - }, - { + }, + { id: Instructions.SagaPreOrder, name: 'Pre-order Saga Phone', isVisible: canUseTokenTransferInstruction,