From c9d1cb09522b561ffcfddea60d78e3aa442d5617 Mon Sep 17 00:00:00 2001 From: No-Cash-7970 Date: Fri, 11 Oct 2024 12:30:58 -0700 Subject: [PATCH] fix(mnemonic): ensure account is initialized when signing transactions This fixes the bug where signing transactions with the mnemonic wallet fails under certain circumstances because the account is not initialized despite being in a valid connection session. --- packages/use-wallet/src/wallets/mnemonic.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/use-wallet/src/wallets/mnemonic.ts b/packages/use-wallet/src/wallets/mnemonic.ts index a729d1cf..44846053 100644 --- a/packages/use-wallet/src/wallets/mnemonic.ts +++ b/packages/use-wallet/src/wallets/mnemonic.ts @@ -226,6 +226,8 @@ export class MnemonicWallet extends BaseWallet { this.logger.debug('Signing transactions...', { txnGroup, indexesToSign }) let txnsToSign: algosdk.Transaction[] = [] + const account = this.account || this.initializeAccount() + // Determine type and process transactions for signing if (isTransactionArray(txnGroup)) { const flatTxns: algosdk.Transaction[] = flattenTxnGroup(txnGroup) @@ -236,7 +238,7 @@ export class MnemonicWallet extends BaseWallet { } // Sign transactions - const signedTxns = txnsToSign.map((txn) => txn.signTxn(this.account!.sk)) + const signedTxns = txnsToSign.map((txn) => txn.signTxn(account.sk)) this.logger.debug('Transactions signed successfully', { signedTxns }) return signedTxns } catch (error: any) {