TxnLab / use-wallet

A framework agnostic wallet integration library for Algorand dApps
https://txnlab.gitbook.io/use-wallet
MIT License
82 stars 34 forks source link

fix(mnemonic): ensure account is initialized when signing transactions #294

Closed No-Cash-7970 closed 1 month ago

No-Cash-7970 commented 1 month ago

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.

I caught this bug in one of my automated tests where I attempt to sign a transaction after refreshing the page using the mnemonic wallet through use-wallet-react with Next.js. It fails with the message: [Wallet:MNEMONIC] Error signing transactions: Cannot read properties of null (reading 'addr'). For some reason, the account within the MnemonicWallet class isn't set despite the session being resumed successfully and the account being accessible through activeAccount.

I couldn't pin down exactly why or when this happens. However, I noticed most of the other wallets had the following line in their signTransactions() methods and the mnemonic wallet did not have anything similar.

const client = this.client || (await this.initializeClient())

Once a added the equivalent line in the mnemonic wallet's signTransactions() method, the bug went away and I didn't encounter any other issues. It appears I somehow encountered an odd edge case.

No-Cash-7970 commented 1 month ago

It turns out the issue was that the page wasn't fully loading in the tests. It was a bug in the tests, not use-wallet