Hide unregistered Solana wallets in the add-token wallet picker
What changed, and why it matters
This commit fixes a UI crash in Stack Wallet's Solana token wallet picker. When creating or restoring a Solana wallet, the app temporarily saved the new wallet's details to the database before fully registering it in memory. The token picker could then try to display a wallet that wasn't fully ready yet, causing an error. The fix hides not-yet-registered wallets from the picker and refreshes the picker once registration is complete.
Treat as a stability/robustness fix rather than a critical security patch. Review whether other token pickers (e.g., select_wallet_for_token_view.dart) have the same unregistered-wallet exposure, and consider centralizing registration-before-read ordering to avoid similar crashes.
Security signals we found
UI crash / unhandled exception in wallet picker
Use of unregistered wallet ID before in-memory registration
Race condition between database write and provider registration
Defensive filtering added to prevent lookup failure
Evidence from the diff
The patch addresses a race/ordering issue between Wallet.create writing wallet info to Isar and pWallets.addWallet registering the wallet in the in-memory Wallets service. select_wallet_for_sol_token_view.dart now filters pAllWalletsInfo to only IDs present in pWallets.wallets, avoiding calls to Wallets.getWallet for unregistered wallets. It also watches newSolWalletTriggerTempUntilHiveCompletelyDeleted to rebuild. The verify and restore flows toggle that trigger after addWallet completes for Solana wallets.
Changed components
lib/pages/add_wallet_views/select_wallet_for_sol_token_view.dartlib/pages/add_wallet_views/verify_recovery_phrase_view/verify_recovery_phrase_view.dartlib/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dartSolana token add-wallet pickernewSolWalletTriggerTempUntilHiveCompletelyDeleted providerInspect captured patch +32 / −0
### lib/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dart
@@ -65,6 +65,7 @@ import '../../../wl_gen/interfaces/cs_wownero_interface.dart';
import '../../../wl_gen/interfaces/lib_xelis_interface.dart';
import '../../home_view/home_view.dart';
import '../add_token_view/edit_wallet_tokens_view.dart';
+import '../select_wallet_for_sol_token_view.dart';
import '../select_wallet_for_token_view.dart';
import '../verify_recovery_phrase_view/verify_recovery_phrase_view.dart';
import 'confirm_recovery_dialog.dart';
@@ -397,6 +398,15 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
.state;
}
+ // The Solana token wallet picker skips wallets that are not in
+ // pWallets yet, so tell it to rebuild now that this one is.
+ if (info.coin is Solana) {
+ final trigger = ref.read(
+ newSolWalletTriggerTempUntilHiveCompletelyDeleted.notifier,
+ );
+ trigger.state = !trigger.state;
+ }
+
if (mounted) {
if (isDesktop) {
Navigator.of(
### lib/pages/add_wallet_views/select_wallet_for_sol_token_view.dart
@@ -17,6 +17,7 @@ import 'verify_recovery_phrase_view/verify_recovery_phrase_view.dart';
import '../../themes/stack_colors.dart';
import '../../utilities/text_styles.dart';
import '../../utilities/util.dart';
+import '../../providers/global/wallets_provider.dart';
import '../../wallets/isar/providers/all_wallets_info_provider.dart';
import '../../wallets/isar/providers/wallet_info_provider.dart';
import '../../widgets/background.dart';
@@ -75,9 +76,20 @@ class _SelectWalletForSolTokenViewState
@override
Widget build(BuildContext context) {
+ // The wallet info is written to the db when a new wallet is created, but
+ // the wallet is only added to pWallets once its flow completes. Rebuild
+ // when that happens and skip wallets that are not registered yet.
+ ref.watch(newSolWalletTriggerTempUntilHiveCompletelyDeleted);
+ final registeredWalletIds = ref
+ .read(pWallets)
+ .wallets
+ .map((e) => e.walletId)
+ .toSet();
+
final solWalletInfos = ref
.watch(pAllWalletsInfo)
.where((e) => e.coin == widget.entity.cryptoCurrency)
+ .where((e) => registeredWalletIds.contains(e.walletId))
.toList();
final _hasSolWallets = solWalletInfos.isNotEmpty;
### lib/pages/add_wallet_views/verify_recovery_phrase_view/verify_recovery_phrase_view.dart
@@ -53,6 +53,7 @@ import '../../home_view/home_view.dart';
import '../add_token_view/edit_wallet_tokens_view.dart';
import '../new_wallet_options/new_wallet_options_view.dart';
import '../new_wallet_recovery_phrase_view/new_wallet_recovery_phrase_view.dart';
+import '../select_wallet_for_sol_token_view.dart';
import '../select_wallet_for_token_view.dart';
import 'sub_widgets/word_table.dart';
import 'verify_mnemonic_passphrase_dialog.dart';
@@ -305,6 +306,15 @@ class _VerifyRecoveryPhraseViewState
.state;
}
+ // The Solana token wallet picker skips wallets that are not in pWallets
+ // yet, so tell it to rebuild now that this one is.
+ if (_coin is Solana) {
+ final trigger = ref.read(
+ newSolWalletTriggerTempUntilHiveCompletelyDeleted.notifier,
+ );
+ trigger.state = !trigger.state;
+ }
+
if (mounted &&
ref.read(pNewWalletOptions)?.convertToViewOnly == true &&
widget.wallet is ViewOnlyOptionInterface) {Why this scored 24/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.