From 835c7d941be4f756337c613605491ab69316cc15 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Fri, 1 Mar 2024 12:11:06 -0800 Subject: [PATCH] improvements --- lib/view_model/settings/tor_view_model.dart | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/view_model/settings/tor_view_model.dart b/lib/view_model/settings/tor_view_model.dart index 4282e799d..798a93b43 100644 --- a/lib/view_model/settings/tor_view_model.dart +++ b/lib/view_model/settings/tor_view_model.dart @@ -27,6 +27,14 @@ abstract class TorViewModelBase with Store { stopTor(); } }); + reaction((_) => torConnectionStatus, (TorConnectionStatus status) async { + if (status == TorConnectionStatus.connecting) { + await disconnectFromNode(); + } + if (status == TorConnectionStatus.connected) { + await connectOrDisconnectNodeToProxy(connect: true); + } + }); } bool torStarted = false; @@ -62,18 +70,17 @@ abstract class TorViewModelBase with Store { } } + Future disconnectFromNode() async { + final appStore = getIt.get(); + appStore.wallet!.syncStatus = NotConnectedSyncStatus(); + await appStore.wallet!.connectToNode(node: Node(uri: "http://127.0.0.1")); + } + @action Future startTor() async { try { torConnectionStatus = TorConnectionStatus.connecting; - // stop monero from syncing before tor is connected by connecting to a dummy node: - final appStore = getIt.get(); - if (appStore.wallet != null && appStore.wallet!.type == WalletType.monero) { - appStore.wallet!.syncStatus = NotConnectedSyncStatus(); - await appStore.wallet!.connectToNode(node: Node(uri: "http://127.0.0.1")); - } - if (!torStarted) { torStarted = true; torInstance = await Tor.init();