clearer error when restoring unavailable wallet from qr (#3743)
What changed, and why it matters
This commit adds a clearer error message when a user tries to restore a wallet type that is not available in the current app. It prevents confusing behavior by throwing a specific exception early in the QR-code restore process, rather than letting the restore proceed with an unsupported wallet type.
No immediate action required. This is a low-risk hardening/UX improvement. Review whether `BadWalletTypeException` is caught and surfaced appropriately to the user, and verify that `availableWalletTypes` is correctly generated per app variant (Cake Wallet vs Monero.com).
Security signals we found
Input validation added for wallet type derived from QR code URI
Fail-fast exception prevents further processing of unsupported wallet type
Uses generated allowlist (`availableWalletTypes`) for wallet type enforcement
Evidence from the diff
The change imports wallet_types.g.dart and adds a guard clause in WalletRestoreFromQRCode that checks whether the parsed walletType is in availableWalletTypes. If not, it throws BadWalletTypeException with the message “This wallet cannot be used in this app.” This is a defensive UX/hardening change that fails fast during QR-based wallet restoration.
Changed components
lib/view_model/restore/wallet_restore_from_qr_code.dartInspect captured patch +5 / −0
### lib/view_model/restore/wallet_restore_from_qr_code.dart
@@ -9,6 +9,7 @@ import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
+import "package:cake_wallet/wallet_types.g.dart";
import 'package:cw_core/currency_for_wallet_type.dart';
import "package:cw_core/exceptions/cake_exception.dart";
import 'package:cw_core/wallet_type.dart';
@@ -152,6 +153,10 @@ class WalletRestoreFromQRCode {
final uri = Uri.parse(formattedUri);
Map<String, dynamic> queryParameters = {...uri.queryParameters};
+ if(!availableWalletTypes.contains(walletType)) {
+ throw BadWalletTypeException("This wallet cannot be used in this app.", walletType);
+ }
+
if (queryParameters['seed'] == null) {
queryParameters['seed'] = _extractSeedPhraseFromUrl(code, walletType);
}Why this scored 32/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.