Skip to content

Commit

Permalink
fix generate new electrum address (#1294)
Browse files Browse the repository at this point in the history
* add side address validation

* Remove auto size text [skip ci]

---------

Co-authored-by: OmarHatem <[email protected]>
  • Loading branch information
Serhii-Borodenko and OmarHatem28 authored Feb 7, 2024
1 parent 26fe288 commit 0832e62
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cw_bitcoin/lib/bitcoin_address_record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BitcoinAddressRecord {
}

final String address;
final bool isHidden;
bool isHidden;
final int index;
int _txCount;
int _balance;
Expand Down
15 changes: 14 additions & 1 deletion cw_bitcoin/lib/electrum_wallet_addresses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
});
}
}
2 changes: 1 addition & 1 deletion lib/bitcoin/cw_bitcoin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
5 changes: 1 addition & 4 deletions lib/src/screens/receive/widgets/qr_widget.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0832e62

Please sign in to comment.