3
3
import type { Idl } from "@coral-xyz/anchor" ;
4
4
import { Program , AnchorProvider } from "@coral-xyz/anchor" ;
5
5
import { WalletIcon } from "@heroicons/react/24/outline" ;
6
- import {
7
- TransactionBuilder ,
8
- sendTransactions ,
9
- } from "@pythnetwork/solana-utils" ;
10
- import type { AnchorWallet } from "@solana/wallet-adapter-react" ;
6
+ import type { PythStakingWallet } from "@pythnetwork/staking-sdk" ;
11
7
import { useConnection } from "@solana/wallet-adapter-react" ;
12
8
import { useWalletModal } from "@solana/wallet-adapter-react-ui" ;
13
- import { PublicKey , Connection } from "@solana/web3.js" ;
9
+ import {
10
+ PublicKey ,
11
+ Connection ,
12
+ VersionedTransaction ,
13
+ TransactionMessage ,
14
+ } from "@solana/web3.js" ;
14
15
import type { ComponentProps } from "react" ;
15
16
import { useCallback } from "react" ;
16
17
@@ -101,7 +102,7 @@ const ConnectWallet = ({ isLoading }: { isLoading?: boolean | undefined }) => {
101
102
) ;
102
103
} ;
103
104
104
- const WalletConnected = ( { wallet } : { wallet : AnchorWallet } ) => {
105
+ const WalletConnected = ( { wallet } : { wallet : PythStakingWallet } ) => {
105
106
const { connection } = useConnection ( ) ;
106
107
107
108
const testedStatus = useData (
@@ -139,7 +140,7 @@ const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => {
139
140
}
140
141
} ;
141
142
142
- const Tester = ( { wallet } : { wallet : AnchorWallet } ) => {
143
+ const Tester = ( { wallet } : { wallet : PythStakingWallet } ) => {
143
144
const toast = useToast ( ) ;
144
145
const { connection } = useConnection ( ) ;
145
146
const { state, execute } = useAsync ( ( ) => testWallet ( connection , wallet ) ) ;
@@ -195,7 +196,7 @@ const Tester = ({ wallet }: { wallet: AnchorWallet }) => {
195
196
196
197
const getHasAlreadyTested = async (
197
198
connection : Connection ,
198
- wallet : AnchorWallet ,
199
+ wallet : PythStakingWallet ,
199
200
) => {
200
201
const receiptAddress = PublicKey . findProgramAddressSync (
201
202
[ wallet . publicKey . toBytes ( ) ] ,
@@ -205,28 +206,28 @@ const getHasAlreadyTested = async (
205
206
return { hasTested : receipt !== null } ;
206
207
} ;
207
208
208
- const testWallet = async ( connection : Connection , wallet : AnchorWallet ) => {
209
+ const testWallet = async (
210
+ connection : Connection ,
211
+ wallet : PythStakingWallet ,
212
+ ) => {
209
213
const walletTester = new Program (
210
214
WalletTesterIDL as Idl ,
211
215
new AnchorProvider ( connection , wallet ) ,
212
216
) ;
213
217
const testMethod = walletTester . methods . test ;
214
218
if ( testMethod ) {
215
- await sendTransactions (
216
- await TransactionBuilder . batchIntoVersionedTransactions (
217
- wallet . publicKey ,
218
- connection ,
219
- [
220
- {
221
- instruction : await testMethod ( ) . instruction ( ) ,
222
- signers : [ ] ,
223
- } ,
224
- ] ,
225
- { } ,
226
- ) ,
227
- connection ,
228
- wallet ,
219
+ const instruction = await testMethod ( ) . instruction ( ) ;
220
+ const { blockhash } = await connection . getLatestBlockhash ( {
221
+ commitment : "confirmed" ,
222
+ } ) ;
223
+ const transaction = new VersionedTransaction (
224
+ new TransactionMessage ( {
225
+ payerKey : wallet . publicKey ,
226
+ recentBlockhash : blockhash ,
227
+ instructions : [ instruction ] ,
228
+ } ) . compileToV0Message ( ) ,
229
229
) ;
230
+ await wallet . sendTransaction ( transaction , connection ) ;
230
231
} else {
231
232
throw new Error ( "No test method found in program" ) ;
232
233
}
0 commit comments