improvements and fix on change nodes

This commit is contained in:
Matthew Fosse 2024-03-01 12:21:06 -08:00
parent 835c7d941b
commit 0cc1f0806e
2 changed files with 24 additions and 17 deletions

View file

@ -725,7 +725,7 @@ Future<void> setup({
getIt.registerFactory(() => TrocadorProvidersViewModel(getIt.get<SettingsStore>()));
getIt.registerSingleton(TorViewModel(getIt.get<SettingsStore>()));
getIt.registerSingleton(TorViewModel(getIt.get<SettingsStore>(), getIt.get<SettingsStore>().nodes));
getIt.registerSingleton(ProxyWrapper(
settingsStore: getIt.get<SettingsStore>(),
torViewModel: getIt.get<TorViewModel>(),

View file

@ -19,7 +19,7 @@ class TorViewModel = TorViewModelBase with _$TorViewModel;
enum TorConnectionStatus { connecting, connected, disconnected }
abstract class TorViewModelBase with Store {
TorViewModelBase(this._settingsStore) {
TorViewModelBase(this._settingsStore, this.nodes) {
reaction((_) => torConnectionMode, (TorConnectionMode mode) async {
if (mode == TorConnectionMode.enabled || mode == TorConnectionMode.torOnly) {
startTor();
@ -35,10 +35,16 @@ abstract class TorViewModelBase with Store {
await connectOrDisconnectNodeToProxy(connect: true);
}
});
this.nodes.observe((change) async {
if (change.newValue != null && change.key != null) {
await connectOrDisconnectNodeToProxy(connect: true);
}
});
}
bool torStarted = false;
final SettingsStore _settingsStore;
final ObservableMap<WalletType, Node> nodes;
Tor torInstance = Tor.instance;
@computed
@ -52,7 +58,9 @@ abstract class TorViewModelBase with Store {
Future<void> connectOrDisconnectNodeToProxy({required bool connect}) async {
final appStore = getIt.get<AppStore>();
if (appStore.wallet != null) {
if (appStore.wallet == null) {
return;
}
final node = _settingsStore.getCurrentNode(appStore.wallet!.type);
if (connect && (node.socksProxyAddress?.isEmpty ?? true)) {
node.socksProxyAddress = "${InternetAddress.loopbackIPv4.address}:${torInstance.port}";
@ -68,7 +76,6 @@ abstract class TorViewModelBase with Store {
await appStore.wallet!.connectToNode(node: node);
}
}
Future<void> disconnectFromNode() async {
final appStore = getIt.get<AppStore>();