Merge pull request #1506 from cypherstack/fix/sol-add-token-new-wallet
What changed, and why it matters
This commit fixes a user-interface bug in Stack Wallet's Solana token-add flow. Previously, when a user created a new Solana wallet while trying to add a Solana token, the wallet picker could see the newly created wallet in the database before the wallet was fully registered in the running app. This caused the picker to show a wallet row that it could not actually look up, sometimes leading to a crash or confusing 'no wallets' state. The fix makes the picker ignore wallets that are not yet fully registered, and triggers a rebuild once registration completes. There is no security vulnerability here; it is a reliability/UX fix.
No security action required. Treat as a normal bug-fix/UX merge. If desired, verify the new test passes and that the Solana token-add flow behaves correctly on both mobile and desktop.
Security signals we found
No cryptographic or signing code changed
No network or RPC behavior changed
No authentication, authorization, or permission logic changed
No input parsing of untrusted data introduced
Change is purely UI state synchronization for wallet list display
Evidence from the diff
The patch modifies the Solana token wallet selection screen to filter pAllWalletsInfo against pWallets.wallets (registered wallets only). It introduces a temporary StateProvider (newSolWalletTriggerTempUntilHiveCompletelyDeleted) that is toggled when a Solana wallet creation/restoration flow completes, causing the picker to rebuild and include the now-registered wallet. A new unit test verifies that unregistered wallets are skipped and that the picker rebuilds correctly after registration. The changes are localized to UI state management and do not alter cryptography, transaction signing, network calls, or access controls.
Changed components
lib/pages/add_wallet_views/select_wallet_for_sol_token_view.dartlib/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dartlib/pages/add_wallet_views/verify_recovery_phrase_view/verify_recovery_phrase_view.darttest/pages/add_wallet_views/select_wallet_for_sol_token_view_test.dartInspect captured patch +241 / −101
### 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,11 +398,19 @@ 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(
- context,
- ).popUntil(ModalRoute.withName(DesktopHomeView.routeName));
+ Navigator.of(context)
+ .popUntil(ModalRoute.withName(DesktopHomeView.routeName));
} else {
if (isCreateSpecialEthWallet) {
Navigator.of(context).popUntil(
@@ -493,42 +502,42 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
case FormInputStatus.empty:
color = Theme.of(context).extension<StackColors>()!.textFieldDefaultBG;
prefixColor = Theme.of(context).extension<StackColors>()!.textSubtitle2;
- borderColor = Theme.of(
- context,
- ).extension<StackColors>()!.textFieldDefaultBG;
+ borderColor = Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldDefaultBG;
break;
case FormInputStatus.invalid:
color = Theme.of(context).extension<StackColors>()!.textFieldErrorBG;
- prefixColor = Theme.of(
- context,
- ).extension<StackColors>()!.textFieldErrorSearchIconLeft;
- borderColor = Theme.of(
- context,
- ).extension<StackColors>()!.textFieldErrorBorder;
+ prefixColor = Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldErrorSearchIconLeft;
+ borderColor = Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldErrorBorder;
suffixIcon = SvgPicture.asset(
Assets.svg.alertCircle,
width: 16,
height: 16,
- color: Theme.of(
- context,
- ).extension<StackColors>()!.textFieldErrorSearchIconRight,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldErrorSearchIconRight,
);
break;
case FormInputStatus.valid:
color = Theme.of(context).extension<StackColors>()!.textFieldSuccessBG;
- prefixColor = Theme.of(
- context,
- ).extension<StackColors>()!.textFieldSuccessSearchIconLeft;
- borderColor = Theme.of(
- context,
- ).extension<StackColors>()!.textFieldSuccessBorder;
+ prefixColor = Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldSuccessSearchIconLeft;
+ borderColor = Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldSuccessBorder;
suffixIcon = SvgPicture.asset(
Assets.svg.checkCircle,
width: 16,
height: 16,
- color: Theme.of(
- context,
- ).extension<StackColors>()!.textFieldSuccessSearchIconRight,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldSuccessSearchIconRight,
);
break;
}
@@ -717,20 +726,19 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
- semanticsLabel:
- "View QR Code Button. Opens Camera To Scan QR Code For Restoring Wallet.",
+ semanticsLabel: "View QR Code Button. Opens Camera To Scan QR Code For Restoring Wallet.",
key: const Key("restoreWalletViewQrCodeButton"),
size: 36,
shadows: const [],
- color: Theme.of(
- context,
- ).extension<StackColors>()!.background,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .background,
icon: QrCodeIcon(
width: 20,
height: 20,
- color: Theme.of(
- context,
- ).extension<StackColors>()!.accentColorDark,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorDark,
),
onPressed: scanMnemonicQr,
),
@@ -745,20 +753,19 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
- semanticsLabel:
- "Paste Button. Pastes From Clipboard For Restoring Wallet.",
+ semanticsLabel: "Paste Button. Pastes From Clipboard For Restoring Wallet.",
key: const Key("restoreWalletPasteButton"),
size: 36,
shadows: const [],
- color: Theme.of(
- context,
- ).extension<StackColors>()!.background,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .background,
icon: ClipboardIcon(
width: 20,
height: 20,
- color: Theme.of(
- context,
- ).extension<StackColors>()!.accentColorDark,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorDark,
),
onPressed: pasteMnemonic,
),
@@ -815,9 +822,9 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
Assets.svg.clipboard,
width: 22,
height: 22,
- color: Theme.of(
- context,
- ).extension<StackColors>()!.buttonTextSecondary,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .buttonTextSecondary,
),
const SizedBox(width: 8),
Text(
@@ -1198,9 +1205,9 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
},
controller: _controllers[i - 1],
style: STextStyles.field(context).copyWith(
- color: Theme.of(
- context,
- ).extension<StackColors>()!.textRestore,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textRestore,
fontSize: isDesktop ? 16 : 14,
),
),
### lib/pages/add_wallet_views/select_wallet_for_sol_token_view.dart
@@ -9,6 +9,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
+
import '../../models/add_wallet_list_entity/sub_classes/coin_entity.dart';
import '../../models/add_wallet_list_entity/sub_classes/sol_token_entity.dart';
import 'add_token_view/edit_wallet_tokens_view.dart';
@@ -17,6 +18,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';
@@ -29,16 +31,15 @@ import '../../widgets/eth_wallet_radio.dart';
import '../../widgets/rounded_container.dart';
import '../../widgets/rounded_white_container.dart';
import '../../widgets/wallet_info_row/wallet_info_row.dart';
+
import 'package:tuple/tuple.dart';
-final newSolWalletTriggerTempUntilHiveCompletelyDeleted =
- StateProvider((ref) => false);
+final newSolWalletTriggerTempUntilHiveCompletelyDeleted = StateProvider(
+ (ref) => false,
+);
class SelectWalletForSolTokenView extends ConsumerStatefulWidget {
- const SelectWalletForSolTokenView({
- super.key,
- required this.entity,
- });
+ const SelectWalletForSolTokenView({super.key, required this.entity});
static const String routeName = "/selectWalletForSolTokenView";
@@ -58,15 +59,13 @@ class _SelectWalletForSolTokenViewState
void _onContinue() {
Navigator.of(context).pushNamed(
EditWalletTokensView.routeName,
- arguments: Tuple2(
- _selectedWalletId!,
- [widget.entity.token.address],
- ),
+ arguments: Tuple2(_selectedWalletId!, [widget.entity.token.address]),
);
}
void _onAddNewSolWallet() {
- ref.read(newSolWalletTriggerTempUntilHiveCompletelyDeleted.notifier).state = true;
+ ref.read(newSolWalletTriggerTempUntilHiveCompletelyDeleted.notifier).state =
+ true;
Navigator.of(context).pushNamed(
CreateOrRestoreWalletView.routeName,
arguments: CoinEntity(widget.entity.cryptoCurrency),
@@ -75,9 +74,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;
@@ -93,15 +103,21 @@ class _SelectWalletForSolTokenViewState
return WillPopScope(
onWillPop: () async {
- ref.read(newSolWalletTriggerTempUntilHiveCompletelyDeleted.notifier).state = false;
+ ref
+ .read(
+ newSolWalletTriggerTempUntilHiveCompletelyDeleted.notifier,
+ )
+ .state =
+ false;
return true;
},
child: ConditionalParent(
condition: !isDesktop,
builder: (child) => Background(
child: Scaffold(
- backgroundColor:
- Theme.of(context).extension<StackColors>()!.background,
+ backgroundColor: Theme.of(context)
+ .extension<StackColors>()!
+ .background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () {
@@ -110,10 +126,7 @@ class _SelectWalletForSolTokenViewState
),
),
body: SafeArea(
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: child,
- ),
+ child: Padding(padding: const EdgeInsets.all(16), child: child),
),
),
),
@@ -124,48 +137,36 @@ class _SelectWalletForSolTokenViewState
isCompactHeight: false,
leading: AppBarBackButton(),
),
- body: SizedBox(
- width: 500,
- child: child,
- ),
+ body: SizedBox(width: 500, child: child),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- if (isDesktop)
- const SizedBox(
- height: 24,
- ),
+ if (isDesktop) const SizedBox(height: 24),
Text(
"Select Solana wallet",
textAlign: TextAlign.center,
style: isDesktop
? STextStyles.desktopH2(context)
: STextStyles.pageTitleH1(context),
),
- SizedBox(
- height: isDesktop ? 16 : 8,
- ),
+ SizedBox(height: isDesktop ? 16 : 8),
Text(
"You are adding a Solana token.",
textAlign: TextAlign.center,
style: isDesktop
? STextStyles.desktopSubtitleH2(context)
: STextStyles.subtitle(context),
),
- const SizedBox(
- height: 8,
- ),
+ const SizedBox(height: 8),
Text(
"You must choose a Solana wallet in order to use ${widget.entity.name}",
textAlign: TextAlign.center,
style: isDesktop
? STextStyles.desktopSubtitleH2(context)
: STextStyles.subtitle(context),
),
- SizedBox(
- height: isDesktop ? 60 : 16,
- ),
+ SizedBox(height: isDesktop ? 60 : 16),
solWalletIds.isEmpty
? RoundedWhiteContainer(
padding: EdgeInsets.all(isDesktop ? 16 : 12),
@@ -193,9 +194,8 @@ class _SelectWalletForSolTokenViewState
child: ListView.separated(
itemCount: solWalletIds.length,
shrinkWrap: true,
- separatorBuilder: (_, __) => SizedBox(
- height: isDesktop ? 12 : 6,
- ),
+ separatorBuilder: (_, __) =>
+ SizedBox(height: isDesktop ? 12 : 6),
itemBuilder: (_, index) {
return RoundedContainer(
padding: EdgeInsets.all(isDesktop ? 16 : 8),
@@ -206,33 +206,25 @@ class _SelectWalletForSolTokenViewState
},
color: isDesktop
? Theme.of(context)
- .extension<StackColors>()!
- .popupBG
+ .extension<StackColors>()!
+ .popupBG
: _selectedWalletId == solWalletIds[index]
- ? Theme.of(context)
- .extension<StackColors>()!
- .highlight
- : Colors.transparent,
+ ? Theme.of(context)
+ .extension<StackColors>()!
+ .highlight
+ : Colors.transparent,
child: isDesktop
? EthWalletRadio(
walletId: solWalletIds[index],
selectedWalletId: _selectedWalletId,
)
- : WalletInfoRow(
- walletId: solWalletIds[index],
- ),
+ : WalletInfoRow(walletId: solWalletIds[index]),
);
},
),
),
- if (solWalletIds.isEmpty || isDesktop)
- const SizedBox(
- height: 16,
- ),
- if (isDesktop)
- const SizedBox(
- height: 16,
- ),
+ if (solWalletIds.isEmpty || isDesktop) const SizedBox(height: 16),
+ if (isDesktop) const SizedBox(height: 16),
solWalletIds.isEmpty
? PrimaryButton(
label: "Add new Solana wallet",
### 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) {
### test/pages/add_wallet_views/select_wallet_for_sol_token_view_test.dart
@@ -0,0 +1,131 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:platform/platform.dart' as platform;
+import 'package:stackwallet/models/add_wallet_list_entity/sub_classes/sol_token_entity.dart';
+import 'package:stackwallet/models/isar/stack_theme.dart';
+import 'package:stackwallet/pages/add_wallet_views/select_wallet_for_sol_token_view.dart';
+import 'package:stackwallet/providers/global/wallets_provider.dart';
+import 'package:stackwallet/services/wallets.dart';
+import 'package:stackwallet/themes/stack_colors.dart';
+import 'package:stackwallet/themes/theme_service.dart';
+import 'package:stackwallet/utilities/default_sol_tokens.dart';
+import 'package:stackwallet/utilities/util.dart';
+import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
+import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
+import 'package:stackwallet/wallets/isar/providers/all_wallets_info_provider.dart';
+import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
+import 'package:stackwallet/wallets/wallet/wallet.dart';
+
+import '../../sample_data/theme_json.dart';
+
+void main() {
+ late platform.Platform originalPlatform;
+
+ setUp(() => originalPlatform = Util.layoutPlatform);
+ tearDown(() => Util.layoutPlatform = originalPlatform);
+
+ final token = DefaultSolTokens.list.first;
+
+ // Wallet.create saves the info to the db before the verify step adds the
+ // wallet to pWallets, so the picker can see a wallet it can't look up yet.
+ Future<WalletInfo> pumpWithUnregisteredWallet(
+ WidgetTester tester,
+ _FakeWallets wallets, {
+ List<String> walletTokens = const [],
+ }) async {
+ final info = WalletInfo.createNew(
+ coin: Solana(CryptoCurrencyNetwork.main),
+ name: "new sol wallet",
+ );
+ final theme = StackTheme.fromJson(json: lightThemeJsonMap);
+
+ await tester.pumpWidget(
+ ProviderScope(
+ overrides: [
+ pThemeService.overrideWithValue(_TestThemeService(theme)),
+ pAllWalletsInfo.overrideWithValue([info]),
+ pWallets.overrideWithValue(wallets),
+ pWalletTokenAddresses.overrideWithProvider(
+ (walletId) => Provider((_) => walletTokens),
+ ),
+ ],
+ child: MaterialApp(
+ theme: ThemeData(
+ extensions: [StackColors.fromStackColorTheme(theme)],
+ ),
+ home: SelectWalletForSolTokenView(entity: SolTokenEntity(token)),
+ ),
+ ),
+ );
+ await tester.pump();
+ return info;
+ }
+
+ for (final os in ["android", "linux"]) {
+ testWidgets("$os picker skips a wallet that isn't registered yet", (
+ tester,
+ ) async {
+ Util.layoutPlatform = platform.FakePlatform(operatingSystem: os);
+ await pumpWithUnregisteredWallet(tester, _FakeWallets());
+
+ expect(tester.takeException(), isNull);
+ expect(find.text("You do not have any Solana wallets"), findsOneWidget);
+ expect(find.text("Add new Solana wallet"), findsOneWidget);
+ });
+ }
+
+ testWidgets("picker rebuilds when the new wallet is registered", (
+ tester,
+ ) async {
+ Util.layoutPlatform = platform.FakePlatform(operatingSystem: "android");
+ final wallets = _FakeWallets();
+ // The wallet already holds the token, so once it is registered the
+ // picker shows the "already have" message instead of building a row.
+ final info = await pumpWithUnregisteredWallet(
+ tester,
+ wallets,
+ walletTokens: [token.address],
+ );
+ expect(find.text("You do not have any Solana wallets"), findsOneWidget);
+
+ wallets.registered.add(_FakeWallet(info.walletId));
+ final container = ProviderScope.containerOf(
+ tester.element(find.byType(SelectWalletForSolTokenView)),
+ );
+ final trigger = container.read(
+ newSolWalletTriggerTempUntilHiveCompletelyDeleted.notifier,
+ );
+ trigger.state = !trigger.state;
+ await tester.pump();
+
+ expect(tester.takeException(), isNull);
+ expect(
+ find.text("All current Solana wallets already have ${token.name}"),
+ findsOneWidget,
+ );
+ });
+}
+
+class _TestThemeService extends Fake implements ThemeService {
+ _TestThemeService(this.theme);
+
+ final StackTheme theme;
+
+ @override
+ StackTheme? getTheme({required String themeId}) => theme;
+}
+
+class _FakeWallets extends Fake implements Wallets {
+ final List<Wallet> registered = [];
+
+ @override
+ List<Wallet> get wallets => registered;
+}
+
+class _FakeWallet extends Fake implements Wallet {
+ _FakeWallet(this.walletId);
+
+ @override
+ final String walletId;
+}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.