|
@@ -1,19 +1,30 @@
|
|
|
-import type { EventEmitter, WalletName } from '@solana/wallet-adapter-base';
|
|
|
|
|
import {
|
|
import {
|
|
|
BaseMessageSignerWalletAdapter,
|
|
BaseMessageSignerWalletAdapter,
|
|
|
|
|
+ isVersionedTransaction,
|
|
|
scopePollingDetectionStrategy,
|
|
scopePollingDetectionStrategy,
|
|
|
WalletAccountError,
|
|
WalletAccountError,
|
|
|
WalletConnectionError,
|
|
WalletConnectionError,
|
|
|
WalletDisconnectedError,
|
|
WalletDisconnectedError,
|
|
|
|
|
+ WalletError,
|
|
|
WalletNotConnectedError,
|
|
WalletNotConnectedError,
|
|
|
WalletNotReadyError,
|
|
WalletNotReadyError,
|
|
|
WalletPublicKeyError,
|
|
WalletPublicKeyError,
|
|
|
WalletReadyState,
|
|
WalletReadyState,
|
|
|
|
|
+ WalletSendTransactionError,
|
|
|
WalletSignMessageError,
|
|
WalletSignMessageError,
|
|
|
WalletSignTransactionError,
|
|
WalletSignTransactionError,
|
|
|
|
|
+ type EventEmitter,
|
|
|
|
|
+ type SendTransactionOptions,
|
|
|
|
|
+ type WalletName,
|
|
|
} from '@solana/wallet-adapter-base';
|
|
} from '@solana/wallet-adapter-base';
|
|
|
-import type { Transaction } from '@solana/web3.js';
|
|
|
|
|
-import { PublicKey } from '@solana/web3.js';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ PublicKey,
|
|
|
|
|
+ type Connection,
|
|
|
|
|
+ type SendOptions,
|
|
|
|
|
+ type Transaction,
|
|
|
|
|
+ type TransactionSignature,
|
|
|
|
|
+ type VersionedTransaction,
|
|
|
|
|
+} from '@solana/web3.js';
|
|
|
|
|
|
|
|
interface TokenPocketWalletEvents {
|
|
interface TokenPocketWalletEvents {
|
|
|
connect(...args: unknown[]): unknown;
|
|
connect(...args: unknown[]): unknown;
|
|
@@ -24,8 +35,12 @@ interface TokenPocketWallet extends EventEmitter<TokenPocketWalletEvents> {
|
|
|
isTokenPocket?: boolean;
|
|
isTokenPocket?: boolean;
|
|
|
publicKey?: { toBytes(): Uint8Array };
|
|
publicKey?: { toBytes(): Uint8Array };
|
|
|
isConnected: boolean;
|
|
isConnected: boolean;
|
|
|
- signTransaction(transaction: Transaction): Promise<Transaction>;
|
|
|
|
|
- signAllTransactions(transactions: Transaction[]): Promise<Transaction[]>;
|
|
|
|
|
|
|
+ signAndSendTransaction<T extends Transaction | VersionedTransaction>(
|
|
|
|
|
+ transaction: T,
|
|
|
|
|
+ options?: SendOptions
|
|
|
|
|
+ ): Promise<{ signature: TransactionSignature }>;
|
|
|
|
|
+ signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
|
|
|
+ signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
|
|
|
signMessage(message: Uint8Array): Promise<{ signature: Uint8Array }>;
|
|
signMessage(message: Uint8Array): Promise<{ signature: Uint8Array }>;
|
|
|
connect(): Promise<void>;
|
|
connect(): Promise<void>;
|
|
|
disconnect(): Promise<void>;
|
|
disconnect(): Promise<void>;
|
|
@@ -141,7 +156,40 @@ export class TokenPocketWalletAdapter extends BaseMessageSignerWalletAdapter {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
|
|
|
|
|
|
|
+ async sendTransaction<T extends Transaction | VersionedTransaction>(
|
|
|
|
|
+ transaction: T,
|
|
|
|
|
+ connection: Connection,
|
|
|
|
|
+ options: SendTransactionOptions = {}
|
|
|
|
|
+ ): Promise<TransactionSignature> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const wallet = this._wallet;
|
|
|
|
|
+ if (!wallet) throw new WalletNotConnectedError();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const { signers, ...sendOptions } = options;
|
|
|
|
|
+
|
|
|
|
|
+ if (isVersionedTransaction(transaction)) {
|
|
|
|
|
+ signers?.length && transaction.sign(signers);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ transaction = (await this.prepareTransaction(transaction, connection, sendOptions)) as T;
|
|
|
|
|
+ signers?.length && (transaction as Transaction).partialSign(...signers);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sendOptions.preflightCommitment = sendOptions.preflightCommitment || connection.commitment;
|
|
|
|
|
+
|
|
|
|
|
+ const { signature } = await wallet.signAndSendTransaction(transaction, sendOptions);
|
|
|
|
|
+ return signature;
|
|
|
|
|
+ } catch (error: any) {
|
|
|
|
|
+ if (error instanceof WalletError) throw error;
|
|
|
|
|
+ throw new WalletSendTransactionError(error?.message, error);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error: any) {
|
|
|
|
|
+ this.emit('error', error);
|
|
|
|
|
+ throw error;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T> {
|
|
|
try {
|
|
try {
|
|
|
const wallet = this._wallet;
|
|
const wallet = this._wallet;
|
|
|
if (!wallet) throw new WalletNotConnectedError();
|
|
if (!wallet) throw new WalletNotConnectedError();
|
|
@@ -157,7 +205,7 @@ export class TokenPocketWalletAdapter extends BaseMessageSignerWalletAdapter {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
|
|
|
|
|
|
|
+ async signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]> {
|
|
|
try {
|
|
try {
|
|
|
const wallet = this._wallet;
|
|
const wallet = this._wallet;
|
|
|
if (!wallet) throw new WalletNotConnectedError();
|
|
if (!wallet) throw new WalletNotConnectedError();
|