diff --git a/packages/core/base/src/adapter.ts b/packages/core/base/src/adapter.ts index e8be957d7..39c90b956 100644 --- a/packages/core/base/src/adapter.ts +++ b/packages/core/base/src/adapter.ts @@ -1,16 +1,8 @@ -import type { - Connection, - PublicKey, - SendOptions, - Signer, - Transaction, - TransactionSignature, - TransactionVersion, -} from '@solana/web3.js'; +import type { Connection, PublicKey, SendOptions, Signer, Transaction, TransactionSignature } from '@solana/web3.js'; import EventEmitter from 'eventemitter3'; import type { WalletError } from './errors.js'; import { WalletNotConnectedError } from './errors.js'; -import type { TransactionOrVersionedTransaction } from './types.js'; +import type { SupportedTransactionVersions, TransactionOrVersionedTransaction } from './types.js'; export { EventEmitter }; @@ -29,10 +21,7 @@ export interface SendTransactionOptions extends SendOptions { // https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d export type WalletName = T & { __brand__: 'WalletName' }; -export interface WalletAdapterProps< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null -> { +export interface WalletAdapterProps { name: WalletName; url: string; icon: string; @@ -46,16 +35,13 @@ export interface WalletAdapterProps< disconnect(): Promise; sendTransaction( - transaction: TransactionOrVersionedTransaction, + transaction: TransactionOrVersionedTransaction, connection: Connection, options?: SendTransactionOptions ): Promise; } -export type WalletAdapter< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null -> = WalletAdapterProps & EventEmitter; +export type WalletAdapter = WalletAdapterProps & EventEmitter; /** * A wallet's readiness describes a series of states that the wallet can be in, @@ -86,12 +72,9 @@ export enum WalletReadyState { Unsupported = 'Unsupported', } -export abstract class BaseWalletAdapter< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null - > +export abstract class BaseWalletAdapter extends EventEmitter - implements WalletAdapter + implements WalletAdapter { abstract name: WalletName; abstract url: string; @@ -109,7 +92,7 @@ export abstract class BaseWalletAdapter< abstract disconnect(): Promise; abstract sendTransaction( - transaction: TransactionOrVersionedTransaction, + transaction: TransactionOrVersionedTransaction, connection: Connection, options?: SendTransactionOptions ): Promise; diff --git a/packages/core/base/src/signer.ts b/packages/core/base/src/signer.ts index b0a6bab75..81533a219 100644 --- a/packages/core/base/src/signer.ts +++ b/packages/core/base/src/signer.ts @@ -1,35 +1,26 @@ -import type { Connection, TransactionSignature, TransactionVersion } from '@solana/web3.js'; +import type { Connection, TransactionSignature } from '@solana/web3.js'; import type { SendTransactionOptions, WalletAdapter, WalletAdapterProps } from './adapter.js'; import { BaseWalletAdapter } from './adapter.js'; import { WalletSendTransactionError, WalletSignTransactionError } from './errors.js'; import type { TransactionOrVersionedTransaction } from './types.js'; -export interface SignerWalletAdapterProps< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null -> extends WalletAdapterProps { - signTransaction( - transaction: TransactionOrVersionedTransaction - ): Promise>; - signAllTransactions( - transactions: TransactionOrVersionedTransaction[] - ): Promise[]>; +export interface SignerWalletAdapterProps extends WalletAdapterProps { + signTransaction>( + transaction: T + ): Promise; + signAllTransactions>( + transactions: T[] + ): Promise; } -export type SignerWalletAdapter< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null -> = WalletAdapter & SignerWalletAdapterProps; - -export abstract class BaseSignerWalletAdapter< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null - > - extends BaseWalletAdapter - implements SignerWalletAdapter +export type SignerWalletAdapter = WalletAdapter & SignerWalletAdapterProps; + +export abstract class BaseSignerWalletAdapter + extends BaseWalletAdapter + implements SignerWalletAdapter { async sendTransaction( - transaction: TransactionOrVersionedTransaction, + transaction: TransactionOrVersionedTransaction, connection: Connection, options: SendTransactionOptions = {} ): Promise { @@ -91,13 +82,13 @@ export abstract class BaseSignerWalletAdapter< } } - abstract signTransaction( - transaction: TransactionOrVersionedTransaction - ): Promise>; + abstract signTransaction>( + transaction: T + ): Promise; - async signAllTransactions( - transactions: TransactionOrVersionedTransaction[] - ): Promise[]> { + async signAllTransactions>( + transactions: T[] + ): Promise { for (const transaction of transactions) { if ('message' in transaction) { if (!this.supportedTransactionVersions) @@ -113,7 +104,7 @@ export abstract class BaseSignerWalletAdapter< } } - const signedTransactions: TransactionOrVersionedTransaction[] = []; + const signedTransactions: T[] = []; for (const transaction of transactions) { signedTransactions.push(await this.signTransaction(transaction)); } @@ -121,25 +112,16 @@ export abstract class BaseSignerWalletAdapter< } } -export interface MessageSignerWalletAdapterProps< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null -> extends WalletAdapterProps { +export interface MessageSignerWalletAdapterProps extends WalletAdapterProps { signMessage(message: Uint8Array): Promise; } -export type MessageSignerWalletAdapter< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null -> = WalletAdapter & - MessageSignerWalletAdapterProps; - -export abstract class BaseMessageSignerWalletAdapter< - Name extends string = string, - SupportedTransactionVersions extends Set | null = Set | null - > - extends BaseSignerWalletAdapter - implements MessageSignerWalletAdapter +export type MessageSignerWalletAdapter = WalletAdapter & + MessageSignerWalletAdapterProps; + +export abstract class BaseMessageSignerWalletAdapter + extends BaseSignerWalletAdapter + implements MessageSignerWalletAdapter { abstract signMessage(message: Uint8Array): Promise; } diff --git a/packages/core/base/src/types.ts b/packages/core/base/src/types.ts index 65247a098..57c74fbda 100644 --- a/packages/core/base/src/types.ts +++ b/packages/core/base/src/types.ts @@ -10,5 +10,8 @@ export enum WalletAdapterNetwork { Devnet = 'devnet', } -export type TransactionOrVersionedTransaction | null> = - SupportedTransactionVersions extends null ? Transaction : Transaction | VersionedTransaction; +export type SupportedTransactionVersions = Set | null; + +export type TransactionOrVersionedTransaction = S extends null + ? Transaction + : Transaction | VersionedTransaction;