fix generate new electrum address (#1294)

* add side address validation

* Remove auto size text [skip ci]

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii 2024-02-08 00:10:44 +02:00 committed by GitHub
parent 26fe28891d
commit 0832e62719
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 7 deletions

View file

@ -28,7 +28,7 @@ class BitcoinAddressRecord {
}
final String address;
final bool isHidden;
bool isHidden;
final int index;
int _txCount;
int _balance;

View file

@ -53,7 +53,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
String get address {
if (isEnabledAutoGenerateSubaddress) {
if (receiveAddresses.isEmpty) {
final newAddress = generateNewAddress().address;
final newAddress = generateNewAddress(hd: mainHd).address;
return walletInfo.type == WalletType.bitcoinCash ? toCashAddr(newAddress) : newAddress;
}
final receiveAddress = receiveAddresses.first.address;
@ -215,6 +215,13 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
List<BitcoinAddressRecord> addrs;
if (addresses.isNotEmpty) {
if(!isHidden) {
final receiveAddressesList = addresses.where((addr) => !addr.isHidden).toList();
validateSideHdAddresses(receiveAddressesList);
}
addrs = addresses.where((addr) => addr.isHidden == isHidden).toList();
} else {
addrs = await _createNewAddresses(
@ -296,4 +303,10 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
final transactionHistory = await electrumClient.getHistory(sh);
return transactionHistory.isNotEmpty;
}
void validateSideHdAddresses(List<BitcoinAddressRecord> addrWithTransactions) {
addrWithTransactions.forEach((element) {
if (element.address != getAddress(index: element.index, hd: mainHd)) element.isHidden = true;
});
}
}

View file

@ -65,7 +65,7 @@ class CWBitcoin extends Bitcoin {
@override
Future<void> generateNewAddress(Object wallet, String label) async {
final bitcoinWallet = wallet as ElectrumWallet;
await bitcoinWallet.walletAddresses.generateNewAddress(label: label);
await bitcoinWallet.walletAddresses.generateNewAddress(label: label, hd: bitcoinWallet.hd);
await wallet.save();
}

View file

@ -1,4 +1,3 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:cake_wallet/entities/qr_view_data.dart';
import 'package:cake_wallet/themes/extensions/qr_code_theme.dart';
import 'package:cake_wallet/routes.dart';
@ -7,7 +6,6 @@ import 'package:cake_wallet/src/screens/receive/widgets/currency_input_field.dar
import 'package:cake_wallet/utils/brightness_util.dart';
import 'package:cake_wallet/utils/show_bar.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@ -146,10 +144,9 @@ class QRWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: AutoSizeText(
child: Text(
addressListViewModel.address.address,
textAlign: TextAlign.center,
maxLines: addressListViewModel.wallet.type == WalletType.monero ? 2 : 1,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,