fix receive option switching after ln invoice is generated (#3119)
What changed, and why it matters
This commit fixes a UI bug in Cake Wallet's receive screen. Previously, after generating a Lightning Network invoice, the app could keep showing that Lightning invoice even when the user switched to a different receive option (like a regular Bitcoin address). The fix makes the app check the wallet's actual current payment type instead of relying on a cached value.
No immediate security action required. This is a functional bug fix for UI consistency. Users should ensure they are on the expected receive option before sharing a payment request, as with any wallet.
Security signals we found
UI state desynchronization between selected receive option and displayed payment URI
Potential display of incorrect payment type/address to the user
No cryptographic, authentication, or input validation changes
Evidence from the diff
The change is in WalletAddressListViewModelBase. The isLightning computed property previously checked whether uri was a LightningPaymentRequest, which could remain true after the user switched away from Lightning. It now checks whether wallet.walletAddresses.getPaymentUri(_amount) returns a LightningPaymentRequest. Additionally, getPaymentUri() now only returns the cached _lnPaymentRequest when isLightning is true, preventing a stale Lightning URI from being returned after the user switches receive options.
Changed components
lib/view_model/wallet_address_list/wallet_address_list_view_model.dartReceive screen / payment URI generationLightning Network invoice displayInspect captured patch +2 / −2
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 f4563818..3620b138 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
@@ -197,7 +197,7 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
amount: _amount,
contractAddress: (tokenCurrency as Erc20Token).contractAddress);
}
- if (_lnPaymentRequest != null) return _lnPaymentRequest!;
+ if (isLightning && _lnPaymentRequest != null) return _lnPaymentRequest!;
return wallet.walletAddresses.getPaymentUri(_amount);
}
@@ -550,7 +550,7 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
wallet.type == WalletType.bitcoin && bitcoin!.hasSelectedSilentPayments(wallet);
@computed
- bool get isLightning => wallet.type == WalletType.bitcoin && (uri is LightningPaymentRequest);
+ bool get isLightning => wallet.type == WalletType.bitcoin && (wallet.walletAddresses.getPaymentUri(_amount) is LightningPaymentRequest);
@computed
bool get isZCashTransparent {
Why this scored 17/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.