fix send and unspent screen

This commit is contained in:
Serhii 2023-08-15 13:53:52 +03:00
parent af58c45190
commit c1faead0ab
3 changed files with 13 additions and 14 deletions

View file

@ -667,11 +667,7 @@ abstract class ElectrumWalletBase
Future<ElectrumBalance> _fetchBalances() async { Future<ElectrumBalance> _fetchBalances() async {
final addresses = walletAddresses.addresses.toList(); final addresses = walletAddresses.addresses.toList();
final balanceFutures = <Future<Map<String, dynamic>>>[]; final balanceFutures = <Future<Map<String, dynamic>>>[];
var counter = addresses.length; for (var i = 0; i < addresses.length; i++) {
if (walletInfo.type == WalletType.bitcoinCash) counter = 1; //TODO: BCH: remove this check when supported
for (var i = 0; i < counter; i++) {
final addressRecord = addresses[i]; final addressRecord = addresses[i];
final sh = scriptHash(addressRecord.address, networkType: networkType); final sh = scriptHash(addressRecord.address, networkType: networkType);
final balanceFuture = electrumClient.getBalance(sh); final balanceFuture = electrumClient.getBalance(sh);

View file

@ -4,6 +4,7 @@ import 'package:cw_bitcoin/electrum.dart';
import 'package:cw_bitcoin/script_hash.dart'; import 'package:cw_bitcoin/script_hash.dart';
import 'package:cw_core/wallet_addresses.dart'; import 'package:cw_core/wallet_addresses.dart';
import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
part 'electrum_wallet_addresses.g.dart'; part 'electrum_wallet_addresses.g.dart';
@ -108,7 +109,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
if (changeAddresses.isEmpty) { if (changeAddresses.isEmpty) {
final newAddresses = await _createNewAddresses( final newAddresses = await _createNewAddresses(
gap, (walletInfo.type != WalletType.bitcoinCash ? gap : 0), //TODO: BCH: Fix this
hd: sideHd, hd: sideHd,
startIndex: totalCountOfChangeAddresses > 0 startIndex: totalCountOfChangeAddresses > 0
? totalCountOfChangeAddresses - 1 ? totalCountOfChangeAddresses - 1
@ -179,8 +180,8 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
} else { } else {
addrs = await _createNewAddresses( addrs = await _createNewAddresses(
isHidden isHidden
? defaultChangeAddressesCount ? walletInfo.type != WalletType.bitcoinCash ? defaultChangeAddressesCount : 0 //TODO: BCH: Fix this
: defaultReceiveAddressesCount, : walletInfo.type != WalletType.bitcoinCash ? defaultReceiveAddressesCount : 1, //TODO: BCH: Fix this
startIndex: 0, startIndex: 0,
hd: hd, hd: hd,
isHidden: isHidden); isHidden: isHidden);
@ -195,7 +196,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
} }
final start = addrs.length; final start = addrs.length;
final count = start + gap; final count = start + (walletInfo.type != WalletType.bitcoinCash ? gap : 0); //TODO: BCH: Fix this
final batch = await _createNewAddresses( final batch = await _createNewAddresses(
count, count,
startIndex: start, startIndex: start,
@ -222,8 +223,8 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
countOfReceiveAddresses += 1; countOfReceiveAddresses += 1;
}); });
if (countOfReceiveAddresses < defaultReceiveAddressesCount) { if (countOfReceiveAddresses < (walletInfo.type != WalletType.bitcoinCash ? defaultReceiveAddressesCount : 1)) { //TODO: BCH: Fix this
final addressesCount = defaultReceiveAddressesCount - countOfReceiveAddresses; final addressesCount = (walletInfo.type != WalletType.bitcoinCash ? defaultReceiveAddressesCount : 1) - countOfReceiveAddresses;
final newAddresses = await _createNewAddresses( final newAddresses = await _createNewAddresses(
addressesCount, addressesCount,
startIndex: countOfReceiveAddresses, startIndex: countOfReceiveAddresses,
@ -232,8 +233,8 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
addresses.addAll(newAddresses); addresses.addAll(newAddresses);
} }
if (countOfHiddenAddresses < defaultChangeAddressesCount) { if (countOfHiddenAddresses < (walletInfo.type != WalletType.bitcoinCash ? defaultChangeAddressesCount : 0)) { //TODO: BCH: Fix this
final addressesCount = defaultChangeAddressesCount - countOfHiddenAddresses; final addressesCount = (walletInfo.type != WalletType.bitcoinCash ? defaultChangeAddressesCount : 0) - countOfHiddenAddresses;
final newAddresses = await _createNewAddresses( final newAddresses = await _createNewAddresses(
addressesCount, addressesCount,
startIndex: countOfHiddenAddresses, startIndex: countOfHiddenAddresses,

View file

@ -174,7 +174,9 @@ abstract class SendViewModelBase with Store {
@computed @computed
bool get isElectrumWallet => bool get isElectrumWallet =>
_wallet.type == WalletType.bitcoin || _wallet.type == WalletType.litecoin; _wallet.type == WalletType.bitcoin ||
_wallet.type == WalletType.litecoin ||
_wallet.type == WalletType.bitcoinCash;
@observable @observable
CryptoCurrency selectedCryptoCurrency; CryptoCurrency selectedCryptoCurrency;