From af7fe0509969da18ae6f778210814bc020ca907e Mon Sep 17 00:00:00 2001 From: Omar Hatem Date: Thu, 21 Mar 2024 16:31:05 +0200 Subject: [PATCH] Generic fixes (#1342) * handle balance exceptions in estimating All exchange * Fix trades not showing --- cw_bitcoin/lib/electrum_wallet_addresses.dart | 4 ++- lib/bitcoin/cw_bitcoin.dart | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet_addresses.dart b/cw_bitcoin/lib/electrum_wallet_addresses.dart index 828bda8af..69d0a6385 100644 --- a/cw_bitcoin/lib/electrum_wallet_addresses.dart +++ b/cw_bitcoin/lib/electrum_wallet_addresses.dart @@ -220,7 +220,9 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { Future updateAddressesInBox() async { try { addressesMap.clear(); - addressesMap[address] = ''; + _addresses.forEach((addressRecord) { + addressesMap[addressRecord.address] = addressRecord.name; + }); await saveAddressesInBox(); } catch (e) { print(e.toString()); diff --git a/lib/bitcoin/cw_bitcoin.dart b/lib/bitcoin/cw_bitcoin.dart index 709dc9a04..78423a8c3 100644 --- a/lib/bitcoin/cw_bitcoin.dart +++ b/lib/bitcoin/cw_bitcoin.dart @@ -127,19 +127,23 @@ class CWBitcoin extends Bitcoin { final p2shAddr = sk.getPublic().toP2pkhInP2sh(); final p2wpkhAddr = sk.getPublic().toP2wpkhAddress(); - final estimatedTx = await electrumWallet.estimateTxFeeAndInputsToUse( - 0, - true, - // Deposit address + change address - [p2shAddr, p2wpkhAddr], - [ - BitcoinOutput(address: p2shAddr, value: BigInt.zero), - BitcoinOutput(address: p2wpkhAddr, value: BigInt.zero) - ], - null, - priority as BitcoinTransactionPriority); + try { + final estimatedTx = await electrumWallet.estimateTxFeeAndInputsToUse( + 0, + true, + // Deposit address + change address + [p2shAddr, p2wpkhAddr], + [ + BitcoinOutput(address: p2shAddr, value: BigInt.zero), + BitcoinOutput(address: p2wpkhAddr, value: BigInt.zero) + ], + null, + priority as BitcoinTransactionPriority); - return estimatedTx.amount; + return estimatedTx.amount; + } catch (_) { + return 0; + } } @override