From 8acf8bdfb21cabad9cd16c296465d01199b54a51 Mon Sep 17 00:00:00 2001 From: Rafael Date: Thu, 10 Oct 2024 11:10:12 -0300 Subject: [PATCH] feat: add onError exception (#1743) --- cw_bitcoin/lib/electrum_wallet.dart | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 877b108b7..0be83c624 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -1315,7 +1315,7 @@ abstract class ElectrumWalletBase // Set the balance of all non-silent payment addresses to 0 before updating walletAddresses.allAddresses.forEach((addr) { - if(addr is! BitcoinSilentPaymentAddressRecord) addr.balance = 0; + if (addr is! BitcoinSilentPaymentAddressRecord) addr.balance = 0; }); await Future.wait(walletAddresses.allAddresses.map((address) async { @@ -1825,6 +1825,8 @@ abstract class ElectrumWalletBase Future> _fetchAddressHistory( BitcoinAddressRecord addressRecord, int? currentHeight) async { + String txid = ""; + try { final Map historiesWithDetails = {}; @@ -1834,7 +1836,7 @@ abstract class ElectrumWalletBase addressRecord.setAsUsed(); await Future.wait(history.map((transaction) async { - final txid = transaction['tx_hash'] as String; + txid = transaction['tx_hash'] as String; final height = transaction['height'] as int; final storedTx = transactionHistory.transactions[txid]; @@ -1865,8 +1867,12 @@ abstract class ElectrumWalletBase } return historiesWithDetails; - } catch (e) { - print(e.toString()); + } catch (e, stacktrace) { + _onError?.call(FlutterErrorDetails( + exception: "$txid - $e", + stack: stacktrace, + library: this.runtimeType.toString(), + )); return {}; } }