diff --git a/lib/electrumx_rpc/electrumx.dart b/lib/electrumx_rpc/electrumx.dart index 847a92aa1..e09446e43 100644 --- a/lib/electrumx_rpc/electrumx.dart +++ b/lib/electrumx_rpc/electrumx.dart @@ -17,9 +17,9 @@ import 'package:decimal/decimal.dart'; import 'package:event_bus/event_bus.dart'; import 'package:stackwallet/electrumx_rpc/rpc.dart'; import 'package:stackwallet/exceptions/electrumx/no_such_transaction.dart'; -import 'package:stackwallet/networking/tor_service.dart'; import 'package:stackwallet/services/event_bus/events/global/tor_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/global_event_bus.dart'; +import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/prefs.dart'; import 'package:uuid/uuid.dart'; diff --git a/lib/electrumx_rpc/rpc.dart b/lib/electrumx_rpc/rpc.dart index a6335bf9e..5d0f503b8 100644 --- a/lib/electrumx_rpc/rpc.dart +++ b/lib/electrumx_rpc/rpc.dart @@ -15,7 +15,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:mutex/mutex.dart'; import 'package:stackwallet/networking/socks_socket.dart'; -import 'package:stackwallet/networking/tor_service.dart'; +import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/prefs.dart'; diff --git a/lib/main.dart b/lib/main.dart index 2eb63fdb0..d919e0ae7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -38,7 +38,6 @@ import 'package:stackwallet/models/models.dart'; import 'package:stackwallet/models/node_model.dart'; import 'package:stackwallet/models/notification_model.dart'; import 'package:stackwallet/models/trade_wallet_lookup.dart'; -import 'package:stackwallet/networking/tor_service.dart'; import 'package:stackwallet/pages/home_view/home_view.dart'; import 'package:stackwallet/pages/intro_view.dart'; import 'package:stackwallet/pages/loading_view.dart'; @@ -60,6 +59,7 @@ import 'package:stackwallet/services/locale_service.dart'; import 'package:stackwallet/services/node_service.dart'; import 'package:stackwallet/services/notifications_api.dart'; import 'package:stackwallet/services/notifications_service.dart'; +import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/services/trade_service.dart'; import 'package:stackwallet/themes/theme_providers.dart'; import 'package:stackwallet/themes/theme_service.dart'; diff --git a/lib/networking/http.dart b/lib/networking/http.dart index 5ab41a5d8..62c8d225e 100644 --- a/lib/networking/http.dart +++ b/lib/networking/http.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:socks5_proxy/socks_client.dart'; -import 'package:stackwallet/networking/tor_service.dart'; +import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/logger.dart'; // WIP wrapper layer diff --git a/lib/pages/home_view/home_view.dart b/lib/pages/home_view/home_view.dart index 71427ab4c..b611421a9 100644 --- a/lib/pages/home_view/home_view.dart +++ b/lib/pages/home_view/home_view.dart @@ -119,7 +119,7 @@ class _HomeViewState extends ConsumerState { Widget _buildTorIcon(TorConnectionStatus status) { switch (status) { - case TorConnectionStatus.unableToConnect: + case TorConnectionStatus.disconnected: return SvgPicture.asset( Assets.svg.tor, color: Theme.of(context).extension()!.textSubtitle3, @@ -261,7 +261,7 @@ class _HomeViewState extends ConsumerState { color: Theme.of(context) .extension()! .backgroundAppBar, - icon: _buildTorIcon(TorConnectionStatus.unableToConnect), + icon: _buildTorIcon(TorConnectionStatus.disconnected), onPressed: () { Navigator.of(context) .pushNamed(TorSettingsView.routeName); diff --git a/lib/pages/home_view/sub_widgets/tor_connection_status_changed_event.dart b/lib/pages/home_view/sub_widgets/tor_connection_status_changed_event.dart index 00682d32e..0a395b6a5 100644 --- a/lib/pages/home_view/sub_widgets/tor_connection_status_changed_event.dart +++ b/lib/pages/home_view/sub_widgets/tor_connection_status_changed_event.dart @@ -9,14 +9,15 @@ */ import 'package:stackwallet/utilities/logger.dart'; -enum TorConnectionStatus { unableToConnect, connected, connecting } +enum TorConnectionStatus { disconnected, connecting, connected } class TorConnectionStatusChangedEvent { TorConnectionStatus newStatus; + String message = ""; - TorConnectionStatusChangedEvent(this.newStatus) { + TorConnectionStatusChangedEvent(this.newStatus, this.message) { Logging.instance.log( - "TorSyncStatusChangedEvent fired with arg newStatus = $newStatus", + "TorSyncStatusChangedEvent fired with arg newStatus = $newStatus ($message)", level: LogLevel.Info); } } diff --git a/lib/pages/settings_views/global_settings_view/tor_settings/tor_settings_view.dart b/lib/pages/settings_views/global_settings_view/tor_settings/tor_settings_view.dart index 731f31f1a..241cd1cd6 100644 --- a/lib/pages/settings_views/global_settings_view/tor_settings/tor_settings_view.dart +++ b/lib/pages/settings_views/global_settings_view/tor_settings/tor_settings_view.dart @@ -35,11 +35,11 @@ class TorSettingsView extends ConsumerStatefulWidget { } class _TorSettingsViewState extends ConsumerState { - TorConnectionStatus _networkStatus = TorConnectionStatus.unableToConnect; + TorConnectionStatus _networkStatus = TorConnectionStatus.disconnected; Widget _buildTorIcon(TorConnectionStatus status) { switch (status) { - case TorConnectionStatus.unableToConnect: + case TorConnectionStatus.disconnected: return Stack( alignment: AlignmentDirectional.center, children: [ @@ -97,7 +97,7 @@ class _TorSettingsViewState extends ConsumerState { Widget _buildTorStatus(TorConnectionStatus status) { switch (status) { - case TorConnectionStatus.unableToConnect: + case TorConnectionStatus.disconnected: return Text( "Disconnected", style: STextStyles.itemSubtitle(context).copyWith( diff --git a/lib/pages_desktop_specific/desktop_menu.dart b/lib/pages_desktop_specific/desktop_menu.dart index 62aa30ec8..bf5239bda 100644 --- a/lib/pages_desktop_specific/desktop_menu.dart +++ b/lib/pages_desktop_specific/desktop_menu.dart @@ -61,7 +61,7 @@ class _DesktopMenuState extends ConsumerState { Widget _buildTorIcon(TorConnectionStatus status) { switch (status) { - case TorConnectionStatus.unableToConnect: + case TorConnectionStatus.disconnected: return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -218,7 +218,7 @@ class _DesktopMenuState extends ConsumerState { .watch(selectedSettingsMenuItemStateProvider.state) .state = 4; }, - child: _buildTorIcon(TorConnectionStatus.unableToConnect)), + child: _buildTorIcon(TorConnectionStatus.disconnected)), ), const SizedBox( height: 40, diff --git a/lib/networking/tor_service.dart b/lib/services/tor_service.dart similarity index 62% rename from lib/networking/tor_service.dart rename to lib/services/tor_service.dart index 2a13a8006..074e62e6e 100644 --- a/lib/networking/tor_service.dart +++ b/lib/services/tor_service.dart @@ -1,6 +1,8 @@ import 'dart:io'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:stackwallet/pages/home_view/sub_widgets/tor_connection_status_changed_event.dart'; +import 'package:stackwallet/services/event_bus/global_event_bus.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:tor/tor.dart'; @@ -34,15 +36,34 @@ class TorService { } try { + GlobalEventBus.instance.fire( + TorConnectionStatusChangedEvent( + TorConnectionStatus.connecting, + "Tor connection status changed: connecting", + ), + ); await _tor.start(); // no exception or error so we can (probably?) assume tor // has started successfully _enabled = true; + GlobalEventBus.instance.fire( + TorConnectionStatusChangedEvent( + TorConnectionStatus.connected, + "Tor connection status changed: connect ($_enabled)", + ), + ); } catch (e, s) { Logging.instance.log( "TorService.start failed: $e\n$s", level: LogLevel.Warning, ); + // _enabled should already be false + GlobalEventBus.instance.fire( + TorConnectionStatusChangedEvent( + TorConnectionStatus.disconnected, + "Tor connection status changed: $_enabled (failed)", + ), + ); rethrow; } } @@ -61,6 +82,12 @@ class TorService { // no exception or error so we can (probably?) assume tor // has started successfully _enabled = false; + GlobalEventBus.instance.fire( + TorConnectionStatusChangedEvent( + TorConnectionStatus.disconnected, + "Tor connection status changed: $_enabled (disabled)", + ), + ); } catch (e, s) { Logging.instance.log( "TorService.stop failed: $e\n$s",