diff --git a/lib/di.dart b/lib/di.dart index d2988b574..da415f220 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -98,6 +98,7 @@ import 'package:cake_wallet/view_model/settings/other_settings_view_model.dart'; import 'package:cake_wallet/view_model/settings/privacy_settings_view_model.dart'; import 'package:cake_wallet/view_model/settings/security_settings_view_model.dart'; import 'package:cake_wallet/view_model/advanced_privacy_settings_view_model.dart'; +import 'package:cake_wallet/view_model/settings/tor_view_model.dart'; import 'package:cake_wallet/view_model/settings/trocador_providers_view_model.dart'; import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_item.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_edit_view_model.dart'; @@ -227,6 +228,7 @@ import 'package:cake_wallet/src/screens/receive/fullscreen_qr_page.dart'; import 'package:cake_wallet/core/wallet_loading_service.dart'; import 'package:cw_core/crypto_currency.dart'; import 'package:cake_wallet/entities/qr_view_data.dart'; +import 'package:tor/tor.dart'; import 'buy/dfx/dfx_buy_provider.dart'; import 'core/totp_request_details.dart'; @@ -294,6 +296,11 @@ Future setup({ : ThemeList.darkTheme, ); + if (settingsStore.shouldStartTorOnLaunch) { + await Tor.instance.enable(); + await Tor.instance.start(); + } + if (_isSetupFinished) { return; } @@ -710,6 +717,8 @@ Future setup({ getIt.registerFactory(() => TrocadorProvidersViewModel(getIt.get())); + getIt.registerFactory(() => TorViewModel(getIt.get())); + getIt.registerFactory(() { return OtherSettingsViewModel(getIt.get(), getIt.get().wallet!); }); @@ -799,8 +808,8 @@ Future setup({ getIt.registerFactory( () => RobinhoodBuyProvider(wallet: getIt.get().wallet!)); - getIt.registerFactory( - () => DFXBuyProvider(wallet: getIt.get().wallet!)); + getIt + .registerFactory(() => DFXBuyProvider(wallet: getIt.get().wallet!)); getIt.registerFactory(() => OnRamperBuyProvider( settingsStore: getIt.get().settingsStore, @@ -1125,8 +1134,7 @@ Future setup({ getIt.registerFactory(() => IoniaAccountCardsPage(getIt.get())); getIt.registerFactory(() => AnonPayApi( - apiMode: getIt.get().exchangeStatus, - wallet: getIt.get().wallet!)); + apiMode: getIt.get().exchangeStatus, wallet: getIt.get().wallet!)); getIt.registerFactory(() => DesktopWalletSelectionDropDown(getIt.get(), getIt.get())); @@ -1188,7 +1196,7 @@ Future setup({ () => WalletConnectConnectionsView(web3walletService: getIt.get())); getIt.registerFactory(() => NFTViewModel(appStore, getIt.get())); - getIt.registerFactory(() => TorPage(getIt.get())); + getIt.registerFactory(() => TorPage(getIt.get(), getIt.get())); _isSetupFinished = true; } diff --git a/lib/src/screens/settings/tor_page.dart b/lib/src/screens/settings/tor_page.dart index 863be3b9e..533e343eb 100644 --- a/lib/src/screens/settings/tor_page.dart +++ b/lib/src/screens/settings/tor_page.dart @@ -3,25 +3,28 @@ import 'dart:io'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/store/app_store.dart'; +import 'package:cake_wallet/view_model/settings/tor_view_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:tor/tor.dart'; class TorPage extends BasePage { final AppStore appStore; + final TorViewModel model; - TorPage(this.appStore); + TorPage(this.appStore, this.model); @override Widget body(BuildContext context) { - return TorPageBody(appStore); + return TorPageBody(appStore, model); } } class TorPageBody extends StatefulWidget { final AppStore appStore; + final TorViewModel model; - const TorPageBody(this.appStore, {Key? key}) : super(key: key); + const TorPageBody(this.appStore, this.model, {Key? key}) : super(key: key); @override State createState() => _TorPageBodyState(); @@ -87,7 +90,7 @@ class _TorPageBodyState extends State { if (value == null) { return; } - widget.appStore.settingsStore.shouldStartTorOnLaunch = value; + widget.model.updateStartOnLaunch(value); } @override diff --git a/lib/view_model/settings/tor_view_model.dart b/lib/view_model/settings/tor_view_model.dart new file mode 100644 index 000000000..1138644ca --- /dev/null +++ b/lib/view_model/settings/tor_view_model.dart @@ -0,0 +1,18 @@ +import 'package:cake_wallet/store/settings_store.dart'; +import 'package:mobx/mobx.dart'; + +part 'tor_view_model.g.dart'; + +class TorViewModel = TorViewModelBase with _$TorViewModel; + +abstract class TorViewModelBase with Store { + + TorViewModelBase(this._settingsStore); + + final SettingsStore _settingsStore; + + @action + Future updateStartOnLaunch(bool value) async { + _settingsStore.shouldStartTorOnLaunch = value; + } +}