1- import type { EventEmitter , WalletName } from '@solana/wallet-adapter-base' ;
21import {
32 BaseMessageSignerWalletAdapter ,
3+ isVersionedTransaction ,
44 scopePollingDetectionStrategy ,
55 WalletAccountError ,
66 WalletConnectionError ,
77 WalletDisconnectedError ,
8+ WalletError ,
89 WalletNotConnectedError ,
910 WalletNotReadyError ,
1011 WalletPublicKeyError ,
1112 WalletReadyState ,
13+ WalletSendTransactionError ,
1214 WalletSignMessageError ,
1315 WalletSignTransactionError ,
16+ type EventEmitter ,
17+ type SendTransactionOptions ,
18+ type WalletName ,
1419} from '@solana/wallet-adapter-base' ;
15- import type { Transaction } from '@solana/web3.js' ;
16- import { PublicKey } from '@solana/web3.js' ;
20+ import {
21+ PublicKey ,
22+ type Connection ,
23+ type SendOptions ,
24+ type Transaction ,
25+ type TransactionSignature ,
26+ type VersionedTransaction ,
27+ } from '@solana/web3.js' ;
1728
1829interface TokenPocketWalletEvents {
1930 connect ( ...args : unknown [ ] ) : unknown ;
@@ -24,8 +35,12 @@ interface TokenPocketWallet extends EventEmitter<TokenPocketWalletEvents> {
2435 isTokenPocket ?: boolean ;
2536 publicKey ?: { toBytes ( ) : Uint8Array } ;
2637 isConnected : boolean ;
27- signTransaction ( transaction : Transaction ) : Promise < Transaction > ;
28- signAllTransactions ( transactions : Transaction [ ] ) : Promise < Transaction [ ] > ;
38+ signAndSendTransaction < T extends Transaction | VersionedTransaction > (
39+ transaction : T ,
40+ options ?: SendOptions
41+ ) : Promise < { signature : TransactionSignature } > ;
42+ signTransaction < T extends Transaction | VersionedTransaction > ( transaction : T ) : Promise < T > ;
43+ signAllTransactions < T extends Transaction | VersionedTransaction > ( transactions : T [ ] ) : Promise < T [ ] > ;
2944 signMessage ( message : Uint8Array ) : Promise < { signature : Uint8Array } > ;
3045 connect ( ) : Promise < void > ;
3146 disconnect ( ) : Promise < void > ;
@@ -141,7 +156,40 @@ export class TokenPocketWalletAdapter extends BaseMessageSignerWalletAdapter {
141156 }
142157 }
143158
144- async signTransaction < T extends Transaction > ( transaction : T ) : Promise < T > {
159+ async sendTransaction < T extends Transaction | VersionedTransaction > (
160+ transaction : T ,
161+ connection : Connection ,
162+ options : SendTransactionOptions = { }
163+ ) : Promise < TransactionSignature > {
164+ try {
165+ const wallet = this . _wallet ;
166+ if ( ! wallet ) throw new WalletNotConnectedError ( ) ;
167+
168+ try {
169+ const { signers, ...sendOptions } = options ;
170+
171+ if ( isVersionedTransaction ( transaction ) ) {
172+ signers ?. length && transaction . sign ( signers ) ;
173+ } else {
174+ transaction = ( await this . prepareTransaction ( transaction , connection , sendOptions ) ) as T ;
175+ signers ?. length && ( transaction as Transaction ) . partialSign ( ...signers ) ;
176+ }
177+
178+ sendOptions . preflightCommitment = sendOptions . preflightCommitment || connection . commitment ;
179+
180+ const { signature } = await wallet . signAndSendTransaction ( transaction , sendOptions ) ;
181+ return signature ;
182+ } catch ( error : any ) {
183+ if ( error instanceof WalletError ) throw error ;
184+ throw new WalletSendTransactionError ( error ?. message , error ) ;
185+ }
186+ } catch ( error : any ) {
187+ this . emit ( 'error' , error ) ;
188+ throw error ;
189+ }
190+ }
191+
192+ async signTransaction < T extends Transaction | VersionedTransaction > ( transaction : T ) : Promise < T > {
145193 try {
146194 const wallet = this . _wallet ;
147195 if ( ! wallet ) throw new WalletNotConnectedError ( ) ;
@@ -157,7 +205,7 @@ export class TokenPocketWalletAdapter extends BaseMessageSignerWalletAdapter {
157205 }
158206 }
159207
160- async signAllTransactions < T extends Transaction > ( transactions : T [ ] ) : Promise < T [ ] > {
208+ async signAllTransactions < T extends Transaction | VersionedTransaction > ( transactions : T [ ] ) : Promise < T [ ] > {
161209 try {
162210 const wallet = this . _wallet ;
163211 if ( ! wallet ) throw new WalletNotConnectedError ( ) ;
0 commit comments