feat: add onError exception (#1743)
Rafael committed
Oct 10, 2024 at 11:10 UTC
8acf8bdfb21cabad9cd16c296465d01199b54a51
1 file changed
+10
-4
cw_bitcoin/lib/electrum_wallet.dart
+10
-4
@@ -1315,7 +1315,7 @@ abstract class ElectrumWalletBase
1315
1316
// Set the balance of all non-silent payment addresses to 0 before updating
1317
walletAddresses.allAddresses.forEach((addr) {
1318
- if(addr is! BitcoinSilentPaymentAddressRecord) addr.balance = 0;
1318
+ if (addr is! BitcoinSilentPaymentAddressRecord) addr.balance = 0;
1319
});
1320
1321
await Future.wait(walletAddresses.allAddresses.map((address) async {
@@ -1825,6 +1825,8 @@ abstract class ElectrumWalletBase
1825
1826
Future<Map<String, ElectrumTransactionInfo>> _fetchAddressHistory(
1827
BitcoinAddressRecord addressRecord, int? currentHeight) async {
1828
+ String txid = "";
1829
+
1830
try {
1831
final Map<String, ElectrumTransactionInfo> historiesWithDetails = {};
1832
@@ -1834,7 +1836,7 @@ abstract class ElectrumWalletBase
1836
addressRecord.setAsUsed();
1837
1838
await Future.wait(history.map((transaction) async {
1837
- final txid = transaction['tx_hash'] as String;
1839
+ txid = transaction['tx_hash'] as String;
1840
final height = transaction['height'] as int;
1841
final storedTx = transactionHistory.transactions[txid];
1842
@@ -1865,8 +1867,12 @@ abstract class ElectrumWalletBase
1867
}
1868
1869
return historiesWithDetails;
1868
- } catch (e) {
1869
- print(e.toString());
1870
+ } catch (e, stacktrace) {
1871
+ _onError?.call(FlutterErrorDetails(
1872
+ exception: "$txid - $e",
1873
+ stack: stacktrace,
1874
+ library: this.runtimeType.toString(),
1875
+ ));
1876
return {};
1877
}
1878
}