diff --git a/cw_bitcoin/lib/electrum_balance.dart b/cw_bitcoin/lib/electrum_balance.dart index ce6b73778..fb0f059d8 100644 --- a/cw_bitcoin/lib/electrum_balance.dart +++ b/cw_bitcoin/lib/electrum_balance.dart @@ -7,8 +7,8 @@ class ElectrumBalance extends Balance { required this.confirmed, required this.unconfirmed, required this.frozen, - this.secondConfirmed, - this.secondUnconfirmed, + this.secondConfirmed = 0, + this.secondUnconfirmed = 0, }) : super( confirmed, unconfirmed, @@ -32,8 +32,8 @@ class ElectrumBalance extends Balance { int confirmed; int unconfirmed; final int frozen; - int? secondConfirmed; - int? secondUnconfirmed; + int secondConfirmed = 0; + int secondUnconfirmed = 0; @override String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen); @@ -51,7 +51,12 @@ class ElectrumBalance extends Balance { String get formattedSecondAvailableBalance => bitcoinAmountToString(amount: secondConfirmed ?? 0); @override - String get formattedSecondAdditionalBalance => bitcoinAmountToString(amount: secondUnconfirmed ?? 0); + String get formattedSecondAdditionalBalance => + bitcoinAmountToString(amount: secondUnconfirmed ?? 0); + + @override + String get formattedFullAvailableBalance => + bitcoinAmountToString(amount: confirmed + (secondConfirmed ?? 0) - frozen); String toJSON() => json.encode({ 'confirmed': confirmed, diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 1babeaa6a..8fbb50ec3 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -869,7 +869,7 @@ abstract class ElectrumWalletBase final totalAmount = amount + fee; - if (totalAmount > balance[currency]!.confirmed) { + if (totalAmount > (balance[currency]!.confirmed + balance[currency]!.secondConfirmed)) { throw BitcoinTransactionWrongBalanceException(); } diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index 0cde7ab03..8b2861af0 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -676,8 +676,10 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { try { mwebUtxosBox.values.forEach((utxo) { if (utxo.height > 0) { + // confirmed += utxo.value.toInt(); confirmedMweb += utxo.value.toInt(); } else { + // unconfirmed += utxo.value.toInt(); unconfirmedMweb += utxo.value.toInt(); } }); diff --git a/cw_bitcoin/lib/litecoin_wallet_addresses.dart b/cw_bitcoin/lib/litecoin_wallet_addresses.dart index dd590f124..3a7856516 100644 --- a/cw_bitcoin/lib/litecoin_wallet_addresses.dart +++ b/cw_bitcoin/lib/litecoin_wallet_addresses.dart @@ -122,6 +122,10 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with Future getChangeAddress({List? outputs, UtxoDetails? utxoDetails}) async { // use regular change address on peg in, otherwise use mweb for change address: + if (!mwebEnabled) { + return super.getChangeAddress(); + } + if (outputs != null && utxoDetails != null) { // check if this is a PEGIN: bool outputsToMweb = false; @@ -134,6 +138,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with outputsToMweb = true; } } + // TODO: this doesn't respect coin control because it doesn't know which available inputs are selected utxoDetails.availableInputs.forEach((element) { if (element.address.contains("mweb")) { comesFromMweb = true; @@ -144,6 +149,11 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with if (isPegIn && mwebEnabled) { return super.getChangeAddress(); } + + // use regular change address if it's not an mweb tx: + if (!comesFromMweb && !outputsToMweb) { + return super.getChangeAddress(); + } } if (mwebEnabled) { diff --git a/cw_core/lib/balance.dart b/cw_core/lib/balance.dart index 579a6da8f..09ca8efbb 100644 --- a/cw_core/lib/balance.dart +++ b/cw_core/lib/balance.dart @@ -13,4 +13,6 @@ abstract class Balance { String get formattedUnAvailableBalance => ''; String get formattedSecondAvailableBalance => ''; String get formattedSecondAdditionalBalance => ''; + String get formattedFullAvailableBalance => ''; + String get formattedFullUnAvailableBalance => ''; } diff --git a/lib/src/screens/receive/widgets/address_list.dart b/lib/src/screens/receive/widgets/address_list.dart index 8dfbedec1..de01f6879 100644 --- a/lib/src/screens/receive/widgets/address_list.dart +++ b/lib/src/screens/receive/widgets/address_list.dart @@ -1,3 +1,6 @@ + +import 'dart:math'; + import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/routes.dart'; @@ -35,7 +38,7 @@ class AddressList extends StatelessWidget { separatorBuilder: (context, _) => const HorizontalSectionDivider(), shrinkWrap: true, physics: NeverScrollableScrollPhysics(), - itemCount: addressListViewModel.items.length, + itemCount: min(addressListViewModel.items.length, 100),// TODO: don't show all 1000 mweb addresses itemBuilder: (context, index) { final item = addressListViewModel.items[index]; Widget cell = Container(); diff --git a/lib/view_model/dashboard/balance_view_model.dart b/lib/view_model/dashboard/balance_view_model.dart index 467b94241..2d917c820 100644 --- a/lib/view_model/dashboard/balance_view_model.dart +++ b/lib/view_model/dashboard/balance_view_model.dart @@ -369,21 +369,17 @@ abstract class BalanceViewModelBase with Store { } bool _hasSecondAdditionalBalanceForWalletType(WalletType type) { - // return _walletBalance.secondAdditional != null && _walletBalance.secondAdditional! != 0; - // if (wallet.type == WalletType.litecoin && settingsStore.mwebEnabled) { - // return true; - // } - // return false; - return true; + if (wallet.type == WalletType.litecoin /*&& settingsStore.mwebEnabled*/) { + return true; + } + return false; } bool _hasSecondAvailableBalanceForWalletType(WalletType type) { - // return _walletBalance.secondAdditional != null && _walletBalance.secondAdditional! != 0; - // if (wallet.type == WalletType.litecoin && settingsStore.mwebEnabled) { - // return true; - // } - // return false; - return true; + if (wallet.type == WalletType.litecoin /*&& settingsStore.mwebEnabled*/) { + return true; + } + return false; } @computed diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 22c083455..04a914a84 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -217,7 +217,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor PendingTransaction? pendingTransaction; @computed - String get balance => wallet.balance[selectedCryptoCurrency]!.formattedAvailableBalance; + String get balance => wallet.balance[selectedCryptoCurrency]!.formattedFullAvailableBalance; @computed bool get isFiatDisabled => balanceViewModel.isFiatDisabled;