1
1
import * as Tooltip from '@radix-ui/react-tooltip'
2
2
import { 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'
4
10
import { MultisigAccount , TransactionAccount } from '@sqds/mesh/lib/types'
5
11
import { useRouter } from 'next/router'
6
12
import { Fragment , useCallback , useContext , useEffect , useState } from 'react'
@@ -40,6 +46,12 @@ import {
40
46
41
47
import { getMappingCluster , isPubkey } from '../InstructionViews/utils'
42
48
import { 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'
43
55
const ProposalRow = ( {
44
56
proposal,
45
57
multisig,
@@ -369,13 +381,35 @@ const Proposal = ({
369
381
} , [ cluster , proposal , squads , connection ] )
370
382
371
383
const handleClick = async (
372
- handler : ( squad : SquadsMesh , proposalKey : PublicKey ) => any ,
384
+ instructionGenerator : (
385
+ squad : SquadsMesh ,
386
+ vaultKey : PublicKey ,
387
+ proposalKey : PublicKey
388
+ ) => Promise < TransactionInstruction > ,
373
389
msg : string
374
390
) => {
375
391
if ( proposal && squads ) {
376
392
try {
377
393
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
+
379
413
if ( refreshData ) await refreshData ( ) . fetchData ( )
380
414
toast . success ( msg )
381
415
} catch ( e : any ) {
@@ -387,27 +421,55 @@ const Proposal = ({
387
421
}
388
422
389
423
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
+ )
393
434
}
394
435
395
436
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
+ )
399
447
}
400
448
401
449
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
+ )
405
460
}
406
461
407
462
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
+ )
411
473
}
412
474
413
475
return proposal !== undefined &&
0 commit comments