From 3fb18bf2dbc1d59a15ade876a74c52a696b6cd46 Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 26 Nov 2024 12:46:18 -0600 Subject: [PATCH] info dialog if node settings and current TOR status will cause sync issues on wallet open --- lib/pages/pinpad_views/lock_screen_view.dart | 17 ++++ .../sub_widgets/favorite_card.dart | 14 +++ .../sub_widgets/wallet_list_item.dart | 15 +++ .../my_stack_view/coin_wallets_table.dart | 19 ++++ .../my_stack_view/wallet_summary_table.dart | 14 +++ .../show_node_tor_settings_mismatch.dart | 97 +++++++++++++++++++ lib/widgets/wallet_card.dart | 14 +++ 7 files changed, 190 insertions(+) create mode 100644 lib/utilities/show_node_tor_settings_mismatch.dart diff --git a/lib/pages/pinpad_views/lock_screen_view.dart b/lib/pages/pinpad_views/lock_screen_view.dart index 711a25a45..5d630ba4f 100644 --- a/lib/pages/pinpad_views/lock_screen_view.dart +++ b/lib/pages/pinpad_views/lock_screen_view.dart @@ -16,6 +16,7 @@ import 'package:mutex/mutex.dart'; import '../../notifications/show_flush_bar.dart'; // import 'package:stackwallet/providers/global/has_authenticated_start_state_provider.dart'; +import '../../providers/global/node_service_provider.dart'; import '../../providers/global/prefs_provider.dart'; import '../../providers/global/secure_store_provider.dart'; import '../../providers/global/wallets_provider.dart'; @@ -25,7 +26,9 @@ import '../../utilities/assets.dart'; import '../../utilities/biometrics.dart'; import '../../utilities/flutter_secure_storage_interface.dart'; import '../../utilities/show_loading.dart'; +import '../../utilities/show_node_tor_settings_mismatch.dart'; import '../../utilities/text_styles.dart'; +import '../../utilities/util.dart'; import '../../wallets/wallet/intermediate/lib_monero_wallet.dart'; import '../../widgets/background.dart'; import '../../widgets/custom_buttons/app_bar_icon_button.dart'; @@ -101,6 +104,20 @@ class _LockscreenViewState extends ConsumerState { final walletId = widget.routeOnSuccessArguments as String; final wallet = ref.read(pWallets).getWallet(walletId); + + final canContinue = await checkShowNodeTorSettingsMismatch( + context: context, + currency: wallet.cryptoCurrency, + prefs: ref.read(prefsChangeNotifierProvider), + nodeService: ref.read(nodeServiceChangeNotifierProvider), + allowCancel: false, + rootNavigator: Util.isDesktop, + ); + + if (!canContinue) { + return; + } + final Future loadFuture; if (wallet is LibMoneroWallet) { loadFuture = diff --git a/lib/pages/wallets_view/sub_widgets/favorite_card.dart b/lib/pages/wallets_view/sub_widgets/favorite_card.dart index 48d0d1257..26e11624a 100644 --- a/lib/pages/wallets_view/sub_widgets/favorite_card.dart +++ b/lib/pages/wallets_view/sub_widgets/favorite_card.dart @@ -22,6 +22,7 @@ import '../../../utilities/amount/amount.dart'; import '../../../utilities/amount/amount_formatter.dart'; import '../../../utilities/constants.dart'; import '../../../utilities/show_loading.dart'; +import '../../../utilities/show_node_tor_settings_mismatch.dart'; import '../../../utilities/text_styles.dart'; import '../../../utilities/util.dart'; import '../../../wallets/crypto_currency/coins/firo.dart'; @@ -117,6 +118,19 @@ class _FavoriteCardState extends ConsumerState { onTap: () async { final wallet = ref.read(pWallets).getWallet(walletId); + final canContinue = await checkShowNodeTorSettingsMismatch( + context: context, + currency: coin, + prefs: ref.read(prefsChangeNotifierProvider), + nodeService: ref.read(nodeServiceChangeNotifierProvider), + allowCancel: true, + rootNavigator: Util.isDesktop, + ); + + if (!canContinue) { + return; + } + final Future loadFuture; if (wallet is LibMoneroWallet) { loadFuture = diff --git a/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart b/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart index 3ac87eb2e..767770ba9 100644 --- a/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart +++ b/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart @@ -21,6 +21,7 @@ import '../../../themes/stack_colors.dart'; import '../../../utilities/amount/amount.dart'; import '../../../utilities/constants.dart'; import '../../../utilities/show_loading.dart'; +import '../../../utilities/show_node_tor_settings_mismatch.dart'; import '../../../utilities/text_styles.dart'; import '../../../utilities/util.dart'; import '../../../wallets/crypto_currency/crypto_currency.dart'; @@ -83,6 +84,20 @@ class WalletListItem extends ConsumerWidget { .read(pWallets) .wallets .firstWhere((e) => e.info.coin == coin); + + final canContinue = await checkShowNodeTorSettingsMismatch( + context: context, + currency: coin, + prefs: ref.read(prefsChangeNotifierProvider), + nodeService: ref.read(nodeServiceChangeNotifierProvider), + allowCancel: true, + rootNavigator: Util.isDesktop, + ); + + if (!canContinue) { + return; + } + final Future loadFuture; if (wallet is LibMoneroWallet) { loadFuture = diff --git a/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart b/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart index 7771c33f5..8da907ca3 100644 --- a/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart +++ b/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart @@ -12,10 +12,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../providers/global/active_wallet_provider.dart'; +import '../../providers/global/node_service_provider.dart'; +import '../../providers/global/prefs_provider.dart'; import '../../providers/global/wallets_provider.dart'; import '../../themes/stack_colors.dart'; import '../../utilities/constants.dart'; import '../../utilities/show_loading.dart'; +import '../../utilities/show_node_tor_settings_mismatch.dart'; import '../../utilities/util.dart'; import '../../wallets/crypto_currency/crypto_currency.dart'; import '../../wallets/wallet/intermediate/lib_monero_wallet.dart'; @@ -81,6 +84,22 @@ class CoinWalletsTable extends ConsumerWidget { final wallet = ref.read(pWallets).getWallet(walletIds[i]); + + final canContinue = + await checkShowNodeTorSettingsMismatch( + context: context, + currency: coin, + prefs: ref.read(prefsChangeNotifierProvider), + nodeService: + ref.read(nodeServiceChangeNotifierProvider), + allowCancel: true, + rootNavigator: Util.isDesktop, + ); + + if (!canContinue) { + return; + } + final Future loadFuture; if (wallet is LibMoneroWallet) { loadFuture = wallet diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart index b30ffb17a..5df82cc0f 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart @@ -20,6 +20,7 @@ import '../../themes/coin_icon_provider.dart'; import '../../themes/stack_colors.dart'; import '../../utilities/amount/amount.dart'; import '../../utilities/show_loading.dart'; +import '../../utilities/show_node_tor_settings_mismatch.dart'; import '../../utilities/text_styles.dart'; import '../../utilities/util.dart'; import '../../wallets/crypto_currency/crypto_currency.dart'; @@ -123,6 +124,19 @@ class _DesktopWalletSummaryRowState final wallet = ref.read(pWallets).wallets.firstWhere( (e) => e.cryptoCurrency.identifier == widget.coin.identifier); + final canContinue = await checkShowNodeTorSettingsMismatch( + context: context, + currency: wallet.cryptoCurrency, + prefs: ref.read(prefsChangeNotifierProvider), + nodeService: ref.read(nodeServiceChangeNotifierProvider), + allowCancel: true, + rootNavigator: Util.isDesktop, + ); + + if (!canContinue) { + return; + } + final Future loadFuture; if (wallet is LibMoneroWallet) { loadFuture = diff --git a/lib/utilities/show_node_tor_settings_mismatch.dart b/lib/utilities/show_node_tor_settings_mismatch.dart new file mode 100644 index 000000000..6c2490b51 --- /dev/null +++ b/lib/utilities/show_node_tor_settings_mismatch.dart @@ -0,0 +1,97 @@ +import 'package:flutter/material.dart'; + +import '../services/node_service.dart'; +import '../wallets/crypto_currency/crypto_currency.dart'; +import '../widgets/conditional_parent.dart'; +import '../widgets/desktop/desktop_dialog.dart'; +import '../widgets/desktop/primary_button.dart'; +import '../widgets/desktop/secondary_button.dart'; +import '../widgets/stack_dialog.dart'; +import 'prefs.dart'; +import 'text_styles.dart'; +import 'util.dart'; + +Future checkShowNodeTorSettingsMismatch({ + required BuildContext context, + required CryptoCurrency currency, + required Prefs prefs, + required NodeService nodeService, + required bool allowCancel, + bool rootNavigator = false, +}) async { + final node = + nodeService.getPrimaryNodeFor(currency: currency) ?? currency.defaultNode; + if (prefs.useTor) { + if (node.torEnabled) { + return true; + } + } else { + if (node.clearnetEnabled) { + return true; + } + } + + final result = await showDialog( + context: context, + barrierDismissible: false, + builder: (context) => ConditionalParent( + condition: Util.isDesktop, + builder: (child) => DesktopDialog( + maxHeight: double.infinity, + child: Padding( + padding: const EdgeInsets.all(32), + child: child, + ), + ), + child: ConditionalParent( + condition: !Util.isDesktop, + builder: (child) => StackDialogBase( + child: child, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + "Attention! Node connection issue detected. " + "The current node will not sync due to its connectivity settings. " + "Please adjust the node settings or enable/disable TOR.", + style: STextStyles.w600_16(context), + ), + SizedBox( + height: Util.isDesktop ? 32 : 24, + ), + Row( + children: [ + allowCancel + ? Expanded( + child: SecondaryButton( + buttonHeight: Util.isDesktop ? ButtonHeight.l : null, + label: "Cancel", + onPressed: () { + Navigator.of(context).pop(false); + }, + ), + ) + : const Spacer(), + SizedBox( + width: Util.isDesktop ? 24 : 16, + ), + Expanded( + child: PrimaryButton( + buttonHeight: Util.isDesktop ? ButtonHeight.l : null, + label: "Continue", + onPressed: () { + Navigator.of(context).pop(true); + }, + ), + ), + ], + ), + ], + ), + ), + ), + ); + + return result ?? true; +} diff --git a/lib/widgets/wallet_card.dart b/lib/widgets/wallet_card.dart index 79ab0d41d..814d4b321 100644 --- a/lib/widgets/wallet_card.dart +++ b/lib/widgets/wallet_card.dart @@ -23,6 +23,7 @@ import '../providers/providers.dart'; import '../utilities/constants.dart'; import '../utilities/logger.dart'; import '../utilities/show_loading.dart'; +import '../utilities/show_node_tor_settings_mismatch.dart'; import '../utilities/util.dart'; import '../wallets/isar/providers/eth/current_token_wallet_provider.dart'; import '../wallets/wallet/impl/ethereum_wallet.dart'; @@ -95,6 +96,19 @@ class SimpleWalletCard extends ConsumerWidget { final wallet = ref.read(pWallets).getWallet(walletId); + final canContinue = await checkShowNodeTorSettingsMismatch( + context: context, + currency: wallet.cryptoCurrency, + prefs: ref.read(prefsChangeNotifierProvider), + nodeService: ref.read(nodeServiceChangeNotifierProvider), + allowCancel: true, + rootNavigator: Util.isDesktop, + ); + + if (!canContinue) { + return; + } + if (context.mounted) { final Future loadFuture; if (wallet is LibMoneroWallet) {