Keep Enable Lightning toggle visible after disabling it (#3702)
What changed, and why it matters
This commit changes how the app decides whether to show the 'Enable Lightning' toggle and when to close the Lightning wallet. It keeps the toggle visible after a user turns Lightning off, and it now closes the Lightning wallet connection when Lightning is disabled. There is no clear security bug being fixed; it looks like a UI/UX and resource-cleanup improvement.
No immediate security action required. Treat as a normal functional/UI update. If reviewing further, verify that lightningWallet?.close() properly releases resources and does not leak secrets, and that hasLightningSupport cannot be tricked into enabling Lightning for wallets without a seed.
Security signals we found
Resource cleanup: Lightning wallet connection is explicitly closed when disabled
UI state change: toggle remains visible after disabling Lightning
Getter logic change: hasLightningSupport now depends on seed presence and Lightning availability rather than initialized SDK instance
Evidence from the diff
The patch modifies two files in cw_bitcoin. In bitcoin_wallet.dart, when the Lightning toggle is disabled, it now calls lightningWallet?.close() before nulling the wallet. It also assigns the created Lightning wallet to walletAddresses.lightningWallet. The hasLightningSupport getter is changed from checking lightningWallet?.sdk != null to checking seed != null && LightningWallet.isAvailable. The receive-page option check adds isLightningInitialized. In electrum_wallet_addresses.dart, lightningWallet is changed from final to mutable so it can be assigned after wallet creation.
Changed components
cw_bitcoin/lib/bitcoin_wallet.dartcw_bitcoin/lib/electrum_wallet_addresses.dartLightning wallet enable/disable flowBitcoin receive page Lightning optionInspect captured patch +5 / −3
### cw_bitcoin/lib/bitcoin_wallet.dart
@@ -160,9 +160,11 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
lnurlDomain: "cake.cash",
cachedAddress: cachedLightningAddress,
);
+ walletAddresses.lightningWallet = lightningWallet;
walletAddresses.setLightningAddress(walletInfo.name);
}
} else {
+ lightningWallet?.close();
lightningWallet = null;
}
});
@@ -426,7 +428,7 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
bool get hasPayjoinSupport => keys.privateKey.isNotEmpty;
@override
- bool get hasLightningSupport => lightningWallet?.sdk != null;
+ bool get hasLightningSupport => seed != null && LightningWallet.isAvailable;
bool get isPayjoinAvailable => unspentCoinsInfo.values
.where((element) => element.walletId == id && element.isSending && !element.isFrozen)
@@ -727,7 +729,7 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
if (option == BitcoinReceivePageOption.lightning) {
// Lightning is tied to the primary account only
- return !isExtraAccount && hasLightningSupport;
+ return !isExtraAccount && hasLightningSupport && isLightningInitialized;
}
if (option == BitcoinReceivePageOption.silent_payments) {
### cw_bitcoin/lib/electrum_wallet_addresses.dart
@@ -171,7 +171,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
final Bip32Slip10Secp256k1 legacyMainHd;
final Bip32Slip10Secp256k1 legacySideHd;
final bool isHardwareWallet;
- final LightningWallet? lightningWallet;
+ LightningWallet? lightningWallet;
@observable
ObservableMap<BitcoinAddressType, String> lockedReceiveAddressByType;Why this scored 22/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.