11import * as Tooltip from '@radix-ui/react-tooltip'
22import { useWallet } from '@solana/wallet-adapter-react'
3- import { AccountMeta , Keypair , PublicKey , SystemProgram } from '@solana/web3.js'
3+ import {
4+ AccountMeta ,
5+ Keypair ,
6+ PublicKey ,
7+ SystemProgram ,
8+ TransactionInstruction ,
9+ } from '@solana/web3.js'
410import { MultisigAccount , TransactionAccount } from '@sqds/mesh/lib/types'
511import { useRouter } from 'next/router'
612import { Fragment , useCallback , useContext , useEffect , useState } from 'react'
@@ -40,6 +46,12 @@ import {
4046
4147import { getMappingCluster , isPubkey } from '../InstructionViews/utils'
4248import { getPythProgramKeyForCluster , PythCluster } from '@pythnetwork/client'
49+ import {
50+ DEFAULT_PRIORITY_FEE_CONFIG ,
51+ TransactionBuilder ,
52+ sendTransactions ,
53+ } from '@pythnetwork/solana-utils'
54+ import { Wallet } from '@coral-xyz/anchor'
4355const ProposalRow = ( {
4456 proposal,
4557 multisig,
@@ -369,13 +381,35 @@ const Proposal = ({
369381 } , [ cluster , proposal , squads , connection ] )
370382
371383 const handleClick = async (
372- handler : ( squad : SquadsMesh , proposalKey : PublicKey ) => any ,
384+ instructionGenerator : (
385+ squad : SquadsMesh ,
386+ vaultKey : PublicKey ,
387+ proposalKey : PublicKey
388+ ) => Promise < TransactionInstruction > ,
373389 msg : string
374390 ) => {
375391 if ( proposal && squads ) {
376392 try {
377393 setIsTransactionLoading ( true )
378- await handler ( squads , proposal . publicKey )
394+ const instruction = await instructionGenerator (
395+ squads ,
396+ proposal . ms ,
397+ proposal . publicKey
398+ )
399+ const builder = new TransactionBuilder (
400+ squads . wallet . publicKey ,
401+ squads . connection
402+ )
403+ builder . addInstruction ( { instruction, signers : [ ] } )
404+ const versionedTxs = await builder . getVersionedTransactions (
405+ DEFAULT_PRIORITY_FEE_CONFIG
406+ )
407+ await sendTransactions (
408+ versionedTxs ,
409+ squads . connection ,
410+ squads . wallet as Wallet
411+ )
412+
379413 if ( refreshData ) await refreshData ( ) . fetchData ( )
380414 toast . success ( msg )
381415 } catch ( e : any ) {
@@ -387,27 +421,55 @@ const Proposal = ({
387421 }
388422
389423 const handleClickApprove = async ( ) => {
390- await handleClick ( async ( squad : SquadsMesh , proposalKey : PublicKey ) => {
391- await squad . approveTransaction ( proposalKey )
392- } , `Approved proposal ${ proposal ?. publicKey . toBase58 ( ) } ` )
424+ await handleClick (
425+ async (
426+ squad : SquadsMesh ,
427+ vaultKey : PublicKey ,
428+ proposalKey : PublicKey
429+ ) : Promise < TransactionInstruction > => {
430+ return await squad . buildApproveTransaction ( vaultKey , proposalKey )
431+ } ,
432+ `Approved proposal ${ proposal ?. publicKey . toBase58 ( ) } `
433+ )
393434 }
394435
395436 const handleClickReject = async ( ) => {
396- await handleClick ( async ( squad : SquadsMesh , proposalKey : PublicKey ) => {
397- await squad . rejectTransaction ( proposalKey )
398- } , `Rejected proposal ${ proposal ?. publicKey . toBase58 ( ) } ` )
437+ await handleClick (
438+ async (
439+ squad : SquadsMesh ,
440+ vaultKey : PublicKey ,
441+ proposalKey : PublicKey
442+ ) : Promise < TransactionInstruction > => {
443+ return await squad . buildRejectTransaction ( vaultKey , proposalKey )
444+ } ,
445+ `Rejected proposal ${ proposal ?. publicKey . toBase58 ( ) } `
446+ )
399447 }
400448
401449 const handleClickExecute = async ( ) => {
402- await handleClick ( async ( squad : SquadsMesh , proposalKey : PublicKey ) => {
403- await squad . executeTransaction ( proposalKey )
404- } , `Executed proposal ${ proposal ?. publicKey . toBase58 ( ) } ` )
450+ await handleClick (
451+ async (
452+ squad : SquadsMesh ,
453+ vaultKey : PublicKey ,
454+ proposalKey : PublicKey
455+ ) : Promise < TransactionInstruction > => {
456+ return await squad . buildExecuteTransaction ( proposalKey )
457+ } ,
458+ `Executed proposal ${ proposal ?. publicKey . toBase58 ( ) } `
459+ )
405460 }
406461
407462 const handleClickCancel = async ( ) => {
408- await handleClick ( async ( squad : SquadsMesh , proposalKey : PublicKey ) => {
409- await squad . cancelTransaction ( proposalKey )
410- } , `Cancelled proposal ${ proposal ?. publicKey . toBase58 ( ) } ` )
463+ await handleClick (
464+ async (
465+ squad : SquadsMesh ,
466+ vaultKey : PublicKey ,
467+ proposalKey : PublicKey
468+ ) : Promise < TransactionInstruction > => {
469+ return await squad . buildCancelTransaction ( vaultKey , proposalKey )
470+ } ,
471+ `Cancelled proposal ${ proposal ?. publicKey . toBase58 ( ) } `
472+ )
411473 }
412474
413475 return proposal !== undefined &&
0 commit comments