mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-24 16:18:48 +00:00
improvements and fix on change nodes
This commit is contained in:
parent
835c7d941b
commit
0cc1f0806e
2 changed files with 24 additions and 17 deletions
|
@ -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>(),
|
||||
|
|
|
@ -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,22 +58,23 @@ abstract class TorViewModelBase with Store {
|
|||
|
||||
Future<void> connectOrDisconnectNodeToProxy({required bool connect}) async {
|
||||
final appStore = getIt.get<AppStore>();
|
||||
if (appStore.wallet != null) {
|
||||
final node = _settingsStore.getCurrentNode(appStore.wallet!.type);
|
||||
if (connect && (node.socksProxyAddress?.isEmpty ?? true)) {
|
||||
node.socksProxyAddress = "${InternetAddress.loopbackIPv4.address}:${torInstance.port}";
|
||||
} else if (!connect) {
|
||||
node.socksProxyAddress = null;
|
||||
}
|
||||
|
||||
bool torOnly = _settingsStore.torConnectionMode == TorConnectionMode.torOnly;
|
||||
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash]
|
||||
.contains(appStore.wallet!.type)) {
|
||||
bitcoin!.setTorOnly(appStore.wallet!, torOnly);
|
||||
}
|
||||
|
||||
await appStore.wallet!.connectToNode(node: node);
|
||||
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}";
|
||||
} else if (!connect) {
|
||||
node.socksProxyAddress = null;
|
||||
}
|
||||
|
||||
bool torOnly = _settingsStore.torConnectionMode == TorConnectionMode.torOnly;
|
||||
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash]
|
||||
.contains(appStore.wallet!.type)) {
|
||||
bitcoin!.setTorOnly(appStore.wallet!, torOnly);
|
||||
}
|
||||
|
||||
await appStore.wallet!.connectToNode(node: node);
|
||||
}
|
||||
|
||||
Future<void> disconnectFromNode() async {
|
||||
|
|
Loading…
Reference in a new issue