diff --git a/packages/use-wallet/src/__tests__/wallets/walletconnect.test.ts b/packages/use-wallet/src/__tests__/wallets/walletconnect.test.ts index 0ae52a4f..61109508 100644 --- a/packages/use-wallet/src/__tests__/wallets/walletconnect.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/walletconnect.test.ts @@ -537,6 +537,15 @@ describe('WalletConnect', () => { expect(result).toEqual([txn1.toByte()]) }) + + it('should return encoded signed transactions if the wallet returns untyped byte arrays', async () => { + const signedTxn = Array.from(txn1.toByte()) + mockSignClient.request.mockResolvedValueOnce([signedTxn]) + + const result = await wallet.signTransactions([txn1]) + + expect(result).toEqual([txn1.toByte()]) + }) }) describe('transactionSigner', () => { diff --git a/packages/use-wallet/src/wallets/walletconnect.ts b/packages/use-wallet/src/wallets/walletconnect.ts index 8dbc6c06..7240b501 100644 --- a/packages/use-wallet/src/wallets/walletconnect.ts +++ b/packages/use-wallet/src/wallets/walletconnect.ts @@ -40,7 +40,7 @@ type WalletConnectModalOptions = Pick< export type WalletConnectOptions = SignClientOptions & WalletConnectModalOptions -export type SignTxnsResponse = Array +export type SignTxnsResponse = Array export class SessionError extends Error { constructor(message: string) { @@ -518,10 +518,21 @@ export class WalletConnect extends BaseWallet { request }) - // Filter out unsigned transactions, convert base64 strings to Uint8Array + // Filter out unsigned transactions, convert signed transactions to Uint8Array const signedTxns = signTxnsResult.reduce((acc, value) => { if (value) { - const signedTxn = typeof value === 'string' ? base64ToByteArray(value) : value + let signedTxn: Uint8Array + if (typeof value === 'string') { + signedTxn = base64ToByteArray(value) + } else if (value instanceof Uint8Array) { + signedTxn = value + } else if (Array.isArray(value)) { + signedTxn = new Uint8Array(value) + } else { + // Log unexpected types for debugging + console.warn(`[${this.metadata.name}] Unexpected type in signTxnsResult`, value) + signedTxn = new Uint8Array() + } acc.push(signedTxn) } return acc