From 3b38a730c305e2904165cf07681fbc9224086074 Mon Sep 17 00:00:00 2001 From: willn-cb <110487540+willn-cb@users.noreply.github.com> Date: Wed, 28 Feb 2024 08:55:26 -0800 Subject: [PATCH] Coinbase Wallet Adapter: Add supported transaction versions (#906) * Add supported transaction versions to coinbase wallet adapter * add changeset * typefix --------- Co-authored-by: Jordan Sexton --- .changeset/olive-turtles-walk.md | 5 ++++ packages/wallets/coinbase/src/adapter.ts | 37 +++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 .changeset/olive-turtles-walk.md diff --git a/.changeset/olive-turtles-walk.md b/.changeset/olive-turtles-walk.md new file mode 100644 index 000000000..5388a2448 --- /dev/null +++ b/.changeset/olive-turtles-walk.md @@ -0,0 +1,5 @@ +--- +'@solana/wallet-adapter-coinbase': patch +--- + +Add support for versioned transactions to Coinbase Wallet adapter diff --git a/packages/wallets/coinbase/src/adapter.ts b/packages/wallets/coinbase/src/adapter.ts index 01a8d42b5..08405e404 100644 --- a/packages/wallets/coinbase/src/adapter.ts +++ b/packages/wallets/coinbase/src/adapter.ts @@ -1,6 +1,7 @@ import type { EventEmitter, SendTransactionOptions, WalletName } from '@solana/wallet-adapter-base'; import { BaseMessageSignerWalletAdapter, + isVersionedTransaction, scopePollingDetectionStrategy, WalletAccountError, WalletConnectionError, @@ -14,7 +15,14 @@ import { WalletSendTransactionError, WalletSignTransactionError, } from '@solana/wallet-adapter-base'; -import type { Connection, SendOptions, Transaction, TransactionSignature } from '@solana/web3.js'; +import type { + Connection, + SendOptions, + Transaction, + VersionedTransaction, + TransactionSignature, + TransactionVersion, +} from '@solana/web3.js'; import { PublicKey } from '@solana/web3.js'; interface CoinbaseWalletEvents { @@ -24,10 +32,10 @@ interface CoinbaseWalletEvents { interface CoinbaseWallet extends EventEmitter { publicKey?: PublicKey; - signTransaction(transaction: Transaction): Promise; - signAllTransactions(transactions: Transaction[]): Promise; - signAndSendTransaction( - transaction: Transaction, + signTransaction(transaction: T): Promise; + signAllTransactions(transactions: T[]): Promise; + signAndSendTransaction( + transaction: T, options?: SendOptions ): Promise<{ signature: TransactionSignature }>; signMessage(message: Uint8Array): Promise<{ signature: Uint8Array }>; @@ -50,7 +58,7 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter { url = 'https://chrome.google.com/webstore/detail/coinbase-wallet-extension/hnfanknocfeofbddgcijnmhnfnkdnaad'; icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAyNCIgaGVpZ2h0PSIxMDI0IiB2aWV3Qm94PSIwIDAgMTAyNCAxMDI0IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8Y2lyY2xlIGN4PSI1MTIiIGN5PSI1MTIiIHI9IjUxMiIgZmlsbD0iIzAwNTJGRiIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTE1MiA1MTJDMTUyIDcxMC44MjMgMzEzLjE3NyA4NzIgNTEyIDg3MkM3MTAuODIzIDg3MiA4NzIgNzEwLjgyMyA4NzIgNTEyQzg3MiAzMTMuMTc3IDcxMC44MjMgMTUyIDUxMiAxNTJDMzEzLjE3NyAxNTIgMTUyIDMxMy4xNzcgMTUyIDUxMlpNNDIwIDM5NkM0MDYuNzQ1IDM5NiAzOTYgNDA2Ljc0NSAzOTYgNDIwVjYwNEMzOTYgNjE3LjI1NSA0MDYuNzQ1IDYyOCA0MjAgNjI4SDYwNEM2MTcuMjU1IDYyOCA2MjggNjE3LjI1NSA2MjggNjA0VjQyMEM2MjggNDA2Ljc0NSA2MTcuMjU1IDM5NiA2MDQgMzk2SDQyMFoiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPgo='; - readonly supportedTransactionVersions = null; + supportedTransactionVersions: ReadonlySet = new Set(['legacy', 0]); private _connecting: boolean; private _wallet: CoinbaseWallet | null; @@ -147,8 +155,8 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter { this.emit('disconnect'); } - async sendTransaction( - transaction: Transaction, + async sendTransaction( + transaction: T, connection: Connection, options: SendTransactionOptions = {} ): Promise { @@ -159,9 +167,12 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter { try { const { signers, ...sendOptions } = options; - transaction = await this.prepareTransaction(transaction, connection, sendOptions); - - signers?.length && transaction.partialSign(...signers); + 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; @@ -177,7 +188,7 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter { } } - async signTransaction(transaction: T): Promise { + async signTransaction(transaction: T): Promise { try { const wallet = this._wallet; if (!wallet) throw new WalletNotConnectedError(); @@ -193,7 +204,7 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter { } } - async signAllTransactions(transactions: T[]): Promise { + async signAllTransactions(transactions: T[]): Promise { try { const wallet = this._wallet; if (!wallet) throw new WalletNotConnectedError();