From afcd6d14dcd9dd662b1902370b9f9a41c98cb31a Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 8 Sep 2023 15:50:25 -0500 Subject: [PATCH] add just one row of the needed tor status network status dialog row --- .../wallet_network_settings_view.dart | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/lib/pages/settings_views/wallet_settings_view/wallet_network_settings_view/wallet_network_settings_view.dart b/lib/pages/settings_views/wallet_settings_view/wallet_network_settings_view/wallet_network_settings_view.dart index b447a53ee..249f6b51b 100644 --- a/lib/pages/settings_views/wallet_settings_view/wallet_network_settings_view/wallet_network_settings_view.dart +++ b/lib/pages/settings_views/wallet_settings_view/wallet_network_settings_view/wallet_network_settings_view.dart @@ -27,8 +27,10 @@ import 'package:stackwallet/services/coins/wownero/wownero_wallet.dart'; import 'package:stackwallet/services/event_bus/events/global/blocks_remaining_event.dart'; import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/events/global/refresh_percent_changed_event.dart'; +import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/global_event_bus.dart'; +import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; @@ -92,6 +94,13 @@ class _WalletNetworkSettingsViewState late int _blocksRemaining; bool _advancedIsExpanded = false; + /// The current status of the Tor connection. + late TorConnectionStatus _torConnectionStatus; + + /// The subscription to the TorConnectionStatusChangedEvent. + late final StreamSubscription + _torConnectionStatusSubscription; + Future _attemptRescan() async { if (!Platform.isLinux) await Wakelock.enable(); @@ -268,6 +277,25 @@ class _WalletNetworkSettingsViewState // } // }, // ); + + // Initialize the TorConnectionStatus. + _torConnectionStatus = ref.read(pTorService).enabled + ? TorConnectionStatus.connected + : TorConnectionStatus.disconnected; + + // Subscribe to the TorConnectionStatusChangedEvent. + _torConnectionStatusSubscription = + eventBus.on().listen( + (event) async { + // Rebuild the widget. + setState(() { + _torConnectionStatus = event.newStatus; + }); + + // TODO implement spinner or animations and control from here + }, + ); + super.initState(); } @@ -749,6 +777,53 @@ class _WalletNetworkSettingsViewState SizedBox( height: isDesktop ? 32 : 20, ), + if (TorService.sharedInstance.enabled) + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Tor status", + textAlign: TextAlign.left, + style: isDesktop + ? STextStyles.desktopTextExtraExtraSmall(context) + : STextStyles.smallMed12(context), + ), + GestureDetector( + onTap: () { + TorService.sharedInstance.stop(); + }, + child: Text( + "Disconnect", + style: STextStyles.link2(context), + ), + ), + ], + ), + if (!TorService.sharedInstance.enabled) + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Tor status", + textAlign: TextAlign.left, + style: isDesktop + ? STextStyles.desktopTextExtraExtraSmall(context) + : STextStyles.smallMed12(context), + ), + GestureDetector( + onTap: () { + TorService.sharedInstance.start(); + }, + child: Text( + "Connect", + style: STextStyles.link2(context), + ), + ), + ], + ), + SizedBox( + height: isDesktop ? 12 : 9, + ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [