From 931b6fb9d21da949ff0bba9d8d36b6d3cdf142b9 Mon Sep 17 00:00:00 2001 From: Omar Date: Sun, 9 Aug 2026 16:01:34 +0200 Subject: [PATCH] guard regeneration of lightning address --- cw_bitcoin/lib/electrum_wallet_addresses.dart | 4 ++++ lib/bitcoin/cw_bitcoin.dart | 6 ++++++ .../wallet_address_list/wallet_address_list_view_model.dart | 3 ++- tool/configure.dart | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cw_bitcoin/lib/electrum_wallet_addresses.dart b/cw_bitcoin/lib/electrum_wallet_addresses.dart index 239977ecb..0beb02d25 100644 --- a/cw_bitcoin/lib/electrum_wallet_addresses.dart +++ b/cw_bitcoin/lib/electrum_wallet_addresses.dart @@ -442,6 +442,10 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { @action BaseBitcoinAddressRecord generateNewAddress({String label = ''}) { + if (addressPageType is LightningAddressType) { + throw Exception("Lightning addresses cannot be rotated"); + } + if (addressPageType == SilentPaymentsAddresType.p2sp && silentAddress != null) { final currentSilentAddressIndex = silentAddresses .where((addressRecord) => addressRecord.type != SegwitAddresType.p2tr) diff --git a/lib/bitcoin/cw_bitcoin.dart b/lib/bitcoin/cw_bitcoin.dart index ae1018319..c2343dfe1 100644 --- a/lib/bitcoin/cw_bitcoin.dart +++ b/lib/bitcoin/cw_bitcoin.dart @@ -317,6 +317,12 @@ class CWBitcoin extends Bitcoin { return bitcoinWallet.walletAddresses.addressPageType == SilentPaymentsAddresType.p2sp; } + @override + bool hasSelectedLightning(Object wallet) { + final bitcoinWallet = wallet as ElectrumWallet; + return bitcoinWallet.walletAddresses.addressPageType is LightningAddressType; + } + @override BitcoinAddressType getBitcoinAddressType(ReceivePageOption option) { switch (option) { diff --git a/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart b/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart index 0610381cb..9841661d5 100644 --- a/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart +++ b/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart @@ -614,7 +614,8 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo @computed bool get isLightning => - wallet.type == WalletType.bitcoin && selectedCurrency == CryptoCurrency.btcln; + wallet.type == WalletType.bitcoin && + (selectedCurrency == CryptoCurrency.btcln || bitcoin!.hasSelectedLightning(wallet)); @computed bool get isZCashTransparent { diff --git a/tool/configure.dart b/tool/configure.dart index 19e1521fd..93cb2d598 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -149,6 +149,7 @@ import 'package:cw_bitcoin/bitcoin_amount_format.dart'; import 'package:cw_bitcoin/bitcoin_address_record.dart'; import 'package:cw_bitcoin/bitcoin_wallet_addresses.dart'; import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart'; +import 'package:cw_bitcoin/lightning/lightning_addres_type.dart'; import 'package:cw_bitcoin/lightning/pending_lightning_transaction.dart'; import 'package:cw_bitcoin/litecoin_wallet_service.dart'; import 'package:cw_bitcoin/litecoin_wallet.dart'; @@ -245,6 +246,7 @@ abstract class Bitcoin { ReceivePageOption getLitecoinMwebReceivePageOption(); bool isPayjoinAvailable(Object wallet); bool hasSelectedSilentPayments(Object wallet); + bool hasSelectedLightning(Object wallet); bool isBitcoinReceivePageOption(ReceivePageOption option); BitcoinAddressType getOptionToType(ReceivePageOption option); bool hasTaprootInput(PendingTransaction pendingTransaction);