From 0832e62719bbf413985c8df0e6e644548730a10a Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 8 Feb 2024 00:10:44 +0200 Subject: [PATCH] fix generate new electrum address (#1294) * add side address validation * Remove auto size text [skip ci] --------- Co-authored-by: OmarHatem --- cw_bitcoin/lib/bitcoin_address_record.dart | 2 +- cw_bitcoin/lib/electrum_wallet_addresses.dart | 15 ++++++++++++++- lib/bitcoin/cw_bitcoin.dart | 2 +- lib/src/screens/receive/widgets/qr_widget.dart | 5 +---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cw_bitcoin/lib/bitcoin_address_record.dart b/cw_bitcoin/lib/bitcoin_address_record.dart index f2cd63904..676edb4a5 100644 --- a/cw_bitcoin/lib/bitcoin_address_record.dart +++ b/cw_bitcoin/lib/bitcoin_address_record.dart @@ -28,7 +28,7 @@ class BitcoinAddressRecord { } final String address; - final bool isHidden; + bool isHidden; final int index; int _txCount; int _balance; diff --git a/cw_bitcoin/lib/electrum_wallet_addresses.dart b/cw_bitcoin/lib/electrum_wallet_addresses.dart index a60a7e8ec..850d58f40 100644 --- a/cw_bitcoin/lib/electrum_wallet_addresses.dart +++ b/cw_bitcoin/lib/electrum_wallet_addresses.dart @@ -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 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 addrWithTransactions) { + addrWithTransactions.forEach((element) { + if (element.address != getAddress(index: element.index, hd: mainHd)) element.isHidden = true; + }); + } } diff --git a/lib/bitcoin/cw_bitcoin.dart b/lib/bitcoin/cw_bitcoin.dart index 6836cc4dc..688825013 100644 --- a/lib/bitcoin/cw_bitcoin.dart +++ b/lib/bitcoin/cw_bitcoin.dart @@ -65,7 +65,7 @@ class CWBitcoin extends Bitcoin { @override Future 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(); } diff --git a/lib/src/screens/receive/widgets/qr_widget.dart b/lib/src/screens/receive/widgets/qr_widget.dart index bedb3b526..bbfd4d5c1 100644 --- a/lib/src/screens/receive/widgets/qr_widget.dart +++ b/lib/src/screens/receive/widgets/qr_widget.dart @@ -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: [ 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,