make tor warning appear everytime and proxy act like torOnly is enabled

This commit is contained in:
Matthew Fosse 2024-03-18 12:02:03 -07:00
parent ecdb49adea
commit 2cf257d194
2 changed files with 41 additions and 6 deletions

View file

@ -1,6 +1,7 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
import 'package:flutter/material.dart';
@ -44,9 +45,13 @@ class MainActions {
return;
}
if (viewModel.isTorEnabled && viewModel.settingsStore.shouldShowTorBuyWarning) {
if (viewModel.isTorEnabled /*&& viewModel.settingsStore.shouldShowTorBuyWarning*/) {
viewModel.settingsStore.shouldShowTorBuyWarning = false;
await _showErrorDialog(context, S.of(context).warning, S.of(context).tor_enabled_warning);
bool cont = await _showWarningDialog(
context, S.of(context).warning, S.of(context).tor_enabled_warning);
if (!cont) {
return;
}
}
final defaultBuyProvider = viewModel.defaultBuyProvider;
@ -105,9 +110,13 @@ class MainActions {
return;
}
if (viewModel.isTorEnabled && viewModel.settingsStore.shouldShowTorSellWarning) {
if (viewModel.isTorEnabled /*&& viewModel.settingsStore.shouldShowTorSellWarning*/) {
viewModel.settingsStore.shouldShowTorSellWarning = false;
await _showErrorDialog(context, S.of(context).warning, S.of(context).tor_enabled_warning);
bool cont = await _showWarningDialog(
context, S.of(context).warning, S.of(context).tor_enabled_warning);
if (!cont) {
return;
}
}
final defaultSellProvider = viewModel.defaultSellProvider;
@ -135,4 +144,22 @@ class MainActions {
},
);
}
static Future<bool> _showWarningDialog(
BuildContext context, String title, String errorMessage) async {
bool? response = await showPopUp<bool>(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: title,
alertContent: errorMessage,
rightButtonText: S.of(context).ok,
actionRightButton: () => Navigator.of(context).pop(true),
leftButtonText: S.of(context).cancel,
actionLeftButton: () => Navigator.of(context).pop(false),
);
},
);
return response ?? false;
}
}

View file

@ -96,6 +96,10 @@ class ProxyWrapper {
torEnabled = false;
}
if (torEnabled) {
torConnectionMode = TorConnectionMode.torOnly;
}
if (torEnabled && torConnectionStatus == TorConnectionStatus.connecting) {
throw Exception("Tor is still connecting");
}
@ -168,6 +172,10 @@ class ProxyWrapper {
torEnabled = false;
}
if (torEnabled) {
torConnectionMode = TorConnectionMode.torOnly;
}
if (torEnabled && torConnectionStatus == TorConnectionStatus.connecting) {
throw Exception("Tor is still connecting");
}