Skip to content

Commit 4bb73bc

Browse files
authored
Support versioned transactions in NuFi wallet adapter (anza-xyz#744)
* Support versioned transactions in NuFi adapter * Create shiny-squids-marry.md
1 parent f62ce36 commit 4bb73bc

2 files changed

Lines changed: 33 additions & 15 deletions

File tree

.changeset/shiny-squids-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solana/wallet-adapter-nufi": patch
3+
---
4+
5+
Support versioned transactions in NuFi adapter

packages/wallets/nufi/src/adapter.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { EventEmitter, SendTransactionOptions, WalletName } from '@solana/wallet-adapter-base';
22
import {
3-
BaseMessageSignerWalletAdapter,
3+
isVersionedTransaction,
44
scopePollingDetectionStrategy,
5+
BaseMessageSignerWalletAdapter,
56
WalletAccountError,
67
WalletConnectionError,
78
WalletDisconnectedError,
@@ -15,7 +16,13 @@ import {
1516
WalletSignMessageError,
1617
WalletSignTransactionError,
1718
} from '@solana/wallet-adapter-base';
18-
import type { Connection, Transaction, TransactionSignature } from '@solana/web3.js';
19+
import type {
20+
Connection,
21+
Transaction,
22+
VersionedTransaction,
23+
TransactionSignature,
24+
TransactionVersion,
25+
} from '@solana/web3.js';
1926
import { PublicKey } from '@solana/web3.js';
2027

2128
interface NufiWalletEvents {
@@ -27,9 +34,11 @@ interface NufiWallet extends EventEmitter<NufiWalletEvents> {
2734
isNufi?: boolean;
2835
publicKey?: { toBytes(): Uint8Array };
2936
isConnected: boolean;
30-
signTransaction(transaction: Transaction): Promise<Transaction>;
31-
signAllTransactions(transactions: Transaction[]): Promise<Transaction[]>;
32-
signAndSendTransaction(transaction: Transaction): Promise<{ signature: TransactionSignature }>;
37+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
38+
signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
39+
signAndSendTransaction<T extends Transaction | VersionedTransaction>(
40+
transaction: T
41+
): Promise<{ signature: TransactionSignature }>;
3342
signMessage(message: Uint8Array): Promise<{ signature: Uint8Array }>;
3443
connect(): Promise<void>;
3544
disconnect(): Promise<void>;
@@ -50,7 +59,7 @@ export class NufiWalletAdapter extends BaseMessageSignerWalletAdapter {
5059
url = 'https://nu.fi';
5160
icon =
5261
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjIiIGhlaWdodD0iMjMiIHZpZXdCb3g9IjAgMCAyMiAyMyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iIzIxMjEyMSIgLz4KPHBhdGggZD0iTTQuMzA5OTkgOS4wMDAwOEM1LjMwODc3IDYuMjA0MDEgNy45ODA2OSA0LjIwMzA4IDExLjEyIDQuMjAzMDhDMTQuMjU5MiA0LjIwMzA4IDE2LjkzMTEgNi4yMDQwMSAxNy45Mjk5IDkuMDAwMDhDMTcuOTc5IDkuMTM3NDcgMTguMTA3NCA5LjIzMjE4IDE4LjI1MzMgOS4yMzIxOEgyMS4wNTk0QzIxLjI3MjUgOS4yMzIxOCAyMS40MzE3IDkuMDM1NzYgMjEuMzc5NCA4LjgyOTE5QzIwLjIxOTUgNC4yNDM2MiAxNi4wNjYgMC44NTAzNDIgMTEuMTIgMC44NTAzNDJDNi4xNzM5MSAwLjg1MDM0MiAyLjAyMDQyIDQuMjQzNjIgMC44NjA0NjggOC44MjkxOEMwLjgwODIxMyA5LjAzNTc2IDAuOTY3NDM0IDkuMjMyMTggMS4xODA1MiA5LjIzMjE4SDMuOTg2NTlDNC4xMzI0OSA5LjIzMjE4IDQuMjYwOTEgOS4xMzc0NyA0LjMwOTk5IDkuMDAwMDhaIiBmaWxsPSIjQzZGRjAwIi8+CjxwYXRoIGQ9Ik0zLjk4NjU5IDEzLjYzMjdDNC4xMzI0OSAxMy42MzI3IDQuMjYwOTEgMTMuNzI3NCA0LjMwOTk5IDEzLjg2NDhDNS4zMDg3NyAxNi42NjA4IDcuOTgwNjkgMTguNjYxOCAxMS4xMiAxOC42NjE4QzE0LjI1OTIgMTguNjYxOCAxNi45MzExIDE2LjY2MDggMTcuOTI5OSAxMy44NjQ4QzE3Ljk3OSAxMy43Mjc0IDE4LjEwNzQgMTMuNjMyNyAxOC4yNTMzIDEzLjYzMjdIMjEuMDU5NEMyMS4yNzI1IDEzLjYzMjcgMjEuNDMxNyAxMy44MjkxIDIxLjM3OTQgMTQuMDM1N0MyMC4yMTk1IDE4LjYyMTIgMTYuMDY2IDIyLjAxNDUgMTEuMTIgMjIuMDE0NUM2LjE3MzkxIDIyLjAxNDUgMi4wMjA0MiAxOC42MjEyIDAuODYwNDY4IDE0LjAzNTdDMC44MDgyMTMgMTMuODI5MSAwLjk2NzQzNCAxMy42MzI3IDEuMTgwNTIgMTMuNjMyN0gzLjk4NjU5WiIgZmlsbD0iI0M2RkYwMCIvPgo8cGF0aCBkPSJNOS4yNTQ5OSA5LjIzMjE4QzkuMDY5ODMgOS4yMzIxOCA4LjkxOTcyIDkuMzgyMjkgOC45MTk3MiA5LjU2NzQ2VjEzLjI5NzRDOC45MTk3MiAxMy40ODI1IDkuMDY5ODMgMTMuNjMyNyA5LjI1NDk5IDEzLjYzMjdIMTIuOTg0OUMxMy4xNzAxIDEzLjYzMjcgMTMuMzIwMiAxMy40ODI1IDEzLjMyMDIgMTMuMjk3NFY5LjU2NzQ2QzEzLjMyMDIgOS4zODIyOSAxMy4xNzAxIDkuMjMyMTggMTIuOTg0OSA5LjIzMjE4SDkuMjU0OTlaIiBmaWxsPSIjQzZGRjAwIi8+Cjwvc3ZnPgo=';
53-
readonly supportedTransactionVersions = null;
62+
supportedTransactionVersions: ReadonlySet<TransactionVersion> = new Set(['legacy', 0]);
5463

5564
private _connecting = false;
5665
private _wallet: NufiWallet | null = null;
@@ -150,8 +159,8 @@ export class NufiWalletAdapter extends BaseMessageSignerWalletAdapter {
150159
this.emit('disconnect');
151160
}
152161

153-
async sendTransaction(
154-
transaction: Transaction,
162+
async sendTransaction<T extends Transaction | VersionedTransaction>(
163+
transaction: T,
155164
connection: Connection,
156165
options: SendTransactionOptions = {}
157166
): Promise<TransactionSignature> {
@@ -162,10 +171,14 @@ export class NufiWalletAdapter extends BaseMessageSignerWalletAdapter {
162171
try {
163172
const { signers, ...sendOptions } = options;
164173

165-
transaction = await this.prepareTransaction(transaction, connection, sendOptions);
166-
167-
signers?.length && transaction.partialSign(...signers);
174+
if (isVersionedTransaction(transaction)) {
175+
signers?.length && transaction.sign(signers);
176+
} else {
177+
transaction = (await this.prepareTransaction(transaction, connection, sendOptions)) as T;
178+
signers?.length && (transaction as Transaction).partialSign(...signers);
179+
}
168180

181+
sendOptions.preflightCommitment = sendOptions.preflightCommitment || connection.commitment;
169182
const { signature } = await wallet.signAndSendTransaction(transaction);
170183
return signature;
171184
} catch (error: any) {
@@ -178,13 +191,13 @@ export class NufiWalletAdapter extends BaseMessageSignerWalletAdapter {
178191
}
179192
}
180193

181-
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
194+
async signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T> {
182195
try {
183196
const wallet = this._wallet;
184197
if (!wallet) throw new WalletNotConnectedError();
185198

186199
try {
187-
return ((await wallet.signTransaction(transaction)) as T) || transaction;
200+
return (await wallet.signTransaction(transaction)) || transaction;
188201
} catch (error: any) {
189202
throw new WalletSignTransactionError(error?.message, error);
190203
}
@@ -194,13 +207,13 @@ export class NufiWalletAdapter extends BaseMessageSignerWalletAdapter {
194207
}
195208
}
196209

197-
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
210+
async signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]> {
198211
try {
199212
const wallet = this._wallet;
200213
if (!wallet) throw new WalletNotConnectedError();
201214

202215
try {
203-
return ((await wallet.signAllTransactions(transactions)) as T[]) || transactions;
216+
return (await wallet.signAllTransactions(transactions)) || transactions;
204217
} catch (error: any) {
205218
throw new WalletSignTransactionError(error?.message, error);
206219
}

0 commit comments

Comments
 (0)