proxy node + theme fixes

This commit is contained in:
Matthew Fosse 2024-01-04 12:06:55 -05:00
parent 139e10d9a1
commit ea6bdd02df
6 changed files with 58 additions and 29 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

View file

@ -1,27 +1,36 @@
import 'dart:io';
import 'package:cake_wallet/core/generate_wallet_password.dart';
import 'package:cake_wallet/core/key_service.dart';
import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/settings/tor_connection.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tor/tor.dart';
class WalletLoadingService {
WalletLoadingService(
this.sharedPreferences, this.keyService, this.walletServiceFactory);
this.sharedPreferences,
this.keyService,
this.walletServiceFactory,
this.settingsStore,
);
final SharedPreferences sharedPreferences;
final KeyService keyService;
final WalletService Function(WalletType type) walletServiceFactory;
final SettingsStore settingsStore;
Future<void> renameWallet(
WalletType type, String name, String newName) async {
Future<void> renameWallet(WalletType type, String name, String newName) async {
final walletService = walletServiceFactory.call(type);
final password = await keyService.getWalletPassword(walletName: name);
// Save the current wallet's password to the new wallet name's key
await keyService.saveWalletPassword(
walletName: newName, password: password);
await keyService.saveWalletPassword(walletName: newName, password: password);
// Delete previous wallet name from keyService to keep only new wallet's name
// otherwise keeps duplicate (old and new names)
await keyService.deleteWalletPassword(walletName: name);
@ -46,6 +55,15 @@ class WalletLoadingService {
await updateMoneroWalletPassword(wallet);
}
final mode = settingsStore.torConnectionMode;
if (mode == TorConnectionMode.enabled || mode == TorConnectionMode.onionOnly && (Tor.instance.port != -1)) {
final node = settingsStore.getCurrentNode(wallet.type);
if (node.socksProxyAddress?.isEmpty ?? true) {
node.socksProxyAddress = "${InternetAddress.loopbackIPv4.address}:${Tor.instance.port}";
}
wallet.connectToNode(node: node);
}
return wallet;
}
@ -61,11 +79,9 @@ class WalletLoadingService {
// Save new generated password with backup key for case where
// wallet will change password, but it will fail to update in secure storage
final bakWalletName = '#__${wallet.name}_bak__#';
await keyService.saveWalletPassword(
walletName: bakWalletName, password: password);
await keyService.saveWalletPassword(walletName: bakWalletName, password: password);
await wallet.changePassword(password);
await keyService.saveWalletPassword(
walletName: wallet.name, password: password);
await keyService.saveWalletPassword(walletName: wallet.name, password: password);
isPasswordUpdated = true;
await sharedPreferences.setBool(key, isPasswordUpdated);
}

View file

@ -352,17 +352,21 @@ Future<void> setup({
walletInfoSource: _walletInfoSource));
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, WalletType, void>(
(type, _) => AdvancedPrivacySettingsViewModel(type, getIt.get<SettingsStore>()));
(type, _) => AdvancedPrivacySettingsViewModel(type, getIt.get<SettingsStore>()));
getIt.registerFactory<WalletLoadingService>(() => WalletLoadingService(
getIt.get<SharedPreferences>(),
getIt.get<KeyService>(),
(WalletType type) => getIt.get<WalletService>(param1: type)));
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) =>
WalletNewVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
getIt.get<AdvancedPrivacySettingsViewModel>(param1: type),type: type));
getIt.get<SharedPreferences>(),
getIt.get<KeyService>(),
(WalletType type) => getIt.get<WalletService>(param1: type),
getIt.get<SettingsStore>(),
));
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) => WalletNewVM(
getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type),
_walletInfoSource,
getIt.get<AdvancedPrivacySettingsViewModel>(param1: type),
type: type));
getIt.registerFactoryParam<WalletRestorationFromQRVM, WalletType, void>((WalletType type, _) {
return WalletRestorationFromQRVM(getIt.get<AppStore>(),
@ -815,8 +819,7 @@ Future<void> setup({
.registerFactory<DFXBuyProvider>(() => DFXBuyProvider(wallet: getIt.get<AppStore>().wallet!));
getIt.registerFactory<MoonPaySellProvider>(() => MoonPaySellProvider(
settingsStore: getIt.get<AppStore>().settingsStore,
wallet: getIt.get<AppStore>().wallet!));
settingsStore: getIt.get<AppStore>().settingsStore, wallet: getIt.get<AppStore>().wallet!));
getIt.registerFactory<OnRamperBuyProvider>(() => OnRamperBuyProvider(
getIt.get<AppStore>().settingsStore,
@ -929,8 +932,7 @@ Future<void> setup({
(param1, isCreate) => NewWalletTypePage(onTypeSelected: param1, isCreate: isCreate ?? true));
getIt.registerFactoryParam<PreSeedPage, int, void>(
(seedPhraseLength, _)
=> PreSeedPage(seedPhraseLength));
(seedPhraseLength, _) => PreSeedPage(seedPhraseLength));
getIt.registerFactoryParam<TradeDetailsViewModel, Trade, void>((trade, _) =>
TradeDetailsViewModel(
@ -964,7 +966,7 @@ Future<void> setup({
getIt.registerFactory(() => BuyAmountViewModel());
getIt.registerFactoryParam<BuySellOptionsPage, bool, void>(
(isBuyOption, _) => BuySellOptionsPage(getIt.get<DashboardViewModel>(), isBuyOption));
(isBuyOption, _) => BuySellOptionsPage(getIt.get<DashboardViewModel>(), isBuyOption));
getIt.registerFactory(() {
final wallet = getIt.get<AppStore>().wallet;

View file

@ -60,10 +60,9 @@ class SyncIndicator extends StatelessWidget {
return Container(
width: 15,
margin: EdgeInsets.only(left: 12, bottom: 2),
child: Image.asset(
'assets/images/tor_icon.png',
color: dashboardViewModel.isTorConnected ? null : Colors.white,
),
child: dashboardViewModel.isTorConnected
? Image.asset('assets/images/tor_icon.png')
: Image.asset('assets/images/tor_icon_disabled.png'),
);
}),
],

View file

@ -4,6 +4,9 @@ import 'package:cake_wallet/src/screens/settings/widgets/settings_picker_cell.da
import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart';
import 'package:cake_wallet/src/screens/settings/widgets/settings_tor_status.dart';
import 'package:cake_wallet/src/screens/settings/widgets/wallet_connect_button.dart';
import 'package:cake_wallet/themes/extensions/balance_page_theme.dart';
import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
import 'package:cake_wallet/utils/device_info.dart';
import 'package:cake_wallet/utils/feature_flag.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
@ -105,7 +108,7 @@ class ConnectionSyncPage extends BasePage {
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25), topRight: Radius.circular(25)),
color: const Color.fromARGB(255, 236, 244, 255),
color: Theme.of(context).extension<CakeTextTheme>()!.textfieldUnderlineColor,
),
);
}),
@ -115,7 +118,7 @@ class ConnectionSyncPage extends BasePage {
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(25), bottomRight: Radius.circular(25)),
color: const Color.fromARGB(255, 236, 244, 255),
color: Theme.of(context).extension<CakeTextTheme>()!.textfieldUnderlineColor,
),
title: S.current.tor_status,
isSelected: false,

View file

@ -16,6 +16,7 @@ import 'package:cake_wallet/entities/sort_balance_types.dart';
import 'package:cake_wallet/entities/wallet_list_order_types.dart';
import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/exchange/provider/trocador_exchange_provider.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/view_model/settings/sync_mode.dart';
import 'package:cake_wallet/utils/device_info.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
@ -325,6 +326,14 @@ abstract class SettingsStoreBase with Store {
await Tor.init();
await Tor.instance.enable();
// connect to node through the proxy:
final appStore = getIt.get<AppStore>();
final node = getCurrentNode(appStore.wallet!.type);
if (node.socksProxyAddress?.isEmpty ?? true) {
node.socksProxyAddress = "${InternetAddress.loopbackIPv4.address}:${Tor.instance.port}";
}
appStore.wallet!.connectToNode(node: node);
shouldStartTorOnLaunch = true;
} else {
Tor.instance.disable();