[skip ci] rework UI for disable fiat mode

This commit is contained in:
Serhii 2022-12-07 01:38:36 +02:00
parent 214c1fe0db
commit f4148e0989
9 changed files with 98 additions and 18 deletions

View file

@ -214,6 +214,7 @@ class BackupService {
final currentBitcoinElectrumSererId = data[PreferencesKey.currentBitcoinElectrumSererIdKey] as int?; final currentBitcoinElectrumSererId = data[PreferencesKey.currentBitcoinElectrumSererIdKey] as int?;
final currentLanguageCode = data[PreferencesKey.currentLanguageCode] as String?; final currentLanguageCode = data[PreferencesKey.currentLanguageCode] as String?;
final displayActionListMode = data[PreferencesKey.displayActionListModeKey] as int?; final displayActionListMode = data[PreferencesKey.displayActionListModeKey] as int?;
final fiatApiMode = data[PreferencesKey.currentFiatApiModeKey] as int?;
final currentPinLength = data[PreferencesKey.currentPinLength] as int?; final currentPinLength = data[PreferencesKey.currentPinLength] as int?;
final currentTheme = data[PreferencesKey.currentTheme] as int?; final currentTheme = data[PreferencesKey.currentTheme] as int?;
final currentDefaultSettingsMigrationVersion = data[PreferencesKey.currentDefaultSettingsMigrationVersion] as int?; final currentDefaultSettingsMigrationVersion = data[PreferencesKey.currentDefaultSettingsMigrationVersion] as int?;
@ -266,6 +267,10 @@ class BackupService {
await _sharedPreferences.setInt(PreferencesKey.displayActionListModeKey, await _sharedPreferences.setInt(PreferencesKey.displayActionListModeKey,
displayActionListMode); displayActionListMode);
if (fiatApiMode != null)
await _sharedPreferences.setInt(PreferencesKey.currentFiatApiModeKey,
fiatApiMode);
if (currentPinLength != null) if (currentPinLength != null)
await _sharedPreferences.setInt(PreferencesKey.currentPinLength, await _sharedPreferences.setInt(PreferencesKey.currentPinLength,
currentPinLength); currentPinLength);
@ -427,6 +432,8 @@ class BackupService {
_sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority), _sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority),
PreferencesKey.moneroTransactionPriority: PreferencesKey.moneroTransactionPriority:
_sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority), _sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority),
PreferencesKey.currentFiatApiModeKey:
_sharedPreferences.getInt(PreferencesKey.currentFiatApiModeKey),
}; };
return json.encode(preferences); return json.encode(preferences);

View file

@ -20,6 +20,8 @@ import 'package:cake_wallet/exchange/trade.dart';
import 'package:encrypt/encrypt.dart' as encrypt; import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'fiat_api_mode.dart';
const newCakeWalletMoneroUri = 'xmr-node.cakewallet.com:18081'; const newCakeWalletMoneroUri = 'xmr-node.cakewallet.com:18081';
const cakeWalletBitcoinElectrumUri = 'electrum.cakewallet.com:50002'; const cakeWalletBitcoinElectrumUri = 'electrum.cakewallet.com:50002';
const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002'; const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002';
@ -61,7 +63,9 @@ Future defaultSettingsMigration(
await sharedPreferences.setInt( await sharedPreferences.setInt(
PreferencesKey.currentBalanceDisplayModeKey, PreferencesKey.currentBalanceDisplayModeKey,
BalanceDisplayMode.availableBalance.raw); BalanceDisplayMode.availableBalance.raw);
await sharedPreferences.setBool('disable_fiat', false); await sharedPreferences.setInt(
PreferencesKey.currentFiatApiModeKey,
FiatApiMode.enabled.raw);
await sharedPreferences.setBool('save_recipient_address', true); await sharedPreferences.setBool('save_recipient_address', true);
await resetToDefault(nodes); await resetToDefault(nodes);
await changeMoneroCurrentNodeToDefault( await changeMoneroCurrentNodeToDefault(
@ -140,6 +144,10 @@ Future defaultSettingsMigration(
await addOnionNode(nodes); await addOnionNode(nodes);
break; break;
case 19:
await updateFiatApiModes(sharedPreferences);
break;
default: default:
break; break;
} }
@ -350,6 +358,14 @@ Future<void> updateDisplayModes(SharedPreferences sharedPreferences) async {
PreferencesKey.currentBalanceDisplayModeKey, balanceDisplayMode); PreferencesKey.currentBalanceDisplayModeKey, balanceDisplayMode);
} }
Future<void> updateFiatApiModes(SharedPreferences sharedPreferences) async {
final currentFiatApiMode =
sharedPreferences.getInt(PreferencesKey.currentFiatApiModeKey) ?? -1;
final fiatApiMode = currentFiatApiMode < 1 ? 2 : 1;
await sharedPreferences.setInt(
PreferencesKey.currentFiatApiModeKey, fiatApiMode);
}
Future<void> generateBackupPassword(FlutterSecureStorage secureStorage) async { Future<void> generateBackupPassword(FlutterSecureStorage secureStorage) async {
final key = generateStoreKeyFor(key: SecretStoreKey.backupPassword); final key = generateStoreKeyFor(key: SecretStoreKey.backupPassword);

View file

@ -0,0 +1,39 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cw_core/enumerable_item.dart';
class FiatApiMode extends EnumerableItem<int> with Serializable<int> {
const FiatApiMode({required String title, required int raw}) : super(title: title, raw: raw);
static const all = [FiatApiMode.enabled, FiatApiMode.torOnly, FiatApiMode.disabled];
static const enabled = FiatApiMode(raw: 0, title: 'Enabled');
static const torOnly = FiatApiMode(raw: 1, title: 'Tor only');
static const disabled = FiatApiMode(raw: 2, title: 'Disabled');
static FiatApiMode deserialize({required int raw}) {
switch (raw) {
case 0:
return enabled;
case 1:
return torOnly;
case 2:
return disabled;
default:
throw Exception('Unexpected token: $raw for FiatApiMode deserialize');
}
}
@override
String toString() {
switch (this) {
case FiatApiMode.enabled:
return 'enable';
case FiatApiMode.torOnly:
return 'torOnly';
case FiatApiMode.disabled:
return 'disable';
default:
return '';
}
}
}

View file

@ -9,7 +9,7 @@ class PreferencesKey {
static const currentTransactionPriorityKeyLegacy = 'current_fee_priority'; static const currentTransactionPriorityKeyLegacy = 'current_fee_priority';
static const currentBalanceDisplayModeKey = 'current_balance_display_mode'; static const currentBalanceDisplayModeKey = 'current_balance_display_mode';
static const shouldSaveRecipientAddressKey = 'save_recipient_address'; static const shouldSaveRecipientAddressKey = 'save_recipient_address';
static const shouldDisableFiatKey = 'disable_fiat'; static const currentFiatApiModeKey = 'current_fiat_api_mode';
static const allowBiometricalAuthenticationKey = static const allowBiometricalAuthenticationKey =
'allow_biometrical_authentication'; 'allow_biometrical_authentication';
static const disableExchangeKey = 'disable_exchange'; static const disableExchangeKey = 'disable_exchange';

View file

@ -331,7 +331,7 @@ class SendCardState extends State<SendCard>
], ],
), ),
)), )),
if (sendViewModel.balanceViewModel.disableFiat) if (!sendViewModel.balanceViewModel.disableFiat)
Padding( Padding(
padding: const EdgeInsets.only(top: 20), padding: const EdgeInsets.only(top: 20),
child: BaseTextFormField( child: BaseTextFormField(

View file

@ -1,9 +1,12 @@
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/screens/settings/widgets/settings_choices_cell.dart';
import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart'; import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart';
import 'package:cake_wallet/view_model/settings/privacy_settings_view_model.dart'; import 'package:cake_wallet/view_model/settings/privacy_settings_view_model.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
class PrivacyPage extends BasePage { class PrivacyPage extends BasePage {
PrivacyPage(this._privacySettingsViewModel); PrivacyPage(this._privacySettingsViewModel);
@ -18,10 +21,17 @@ class PrivacyPage extends BasePage {
return Container( return Container(
padding: EdgeInsets.only(top: 10), padding: EdgeInsets.only(top: 10),
child: Observer(builder: (_) { child: Observer(builder: (_) {
return Observer(builder: (_) {
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
SettingsChoicesCell(
ChoicesListItem<FiatApiMode>(
title: 'Fiat api',
items: FiatApiMode.all,
selectedItem: _privacySettingsViewModel.fiatApiMode,
onItemSelected: (FiatApiMode mode) => _privacySettingsViewModel.setFiatMode(mode),
),
),
SettingsSwitcherCell( SettingsSwitcherCell(
title: S.current.disable_exchange, title: S.current.disable_exchange,
value: _privacySettingsViewModel.disableExchange, value: _privacySettingsViewModel.disableExchange,
@ -36,7 +46,6 @@ class PrivacyPage extends BasePage {
}) })
], ],
); );
});
}), }),
); );
} }

View file

@ -17,8 +17,10 @@ import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cw_core/node.dart'; import 'package:cw_core/node.dart';
import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/entities/action_list_display_mode.dart'; import 'package:cake_wallet/entities/action_list_display_mode.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets; import 'package:cake_wallet/.secrets.g.dart' as secrets;
part 'settings_store.g.dart'; part 'settings_store.g.dart';
class SettingsStore = SettingsStoreBase with _$SettingsStore; class SettingsStore = SettingsStoreBase with _$SettingsStore;
@ -29,7 +31,7 @@ abstract class SettingsStoreBase with Store {
required FiatCurrency initialFiatCurrency, required FiatCurrency initialFiatCurrency,
required BalanceDisplayMode initialBalanceDisplayMode, required BalanceDisplayMode initialBalanceDisplayMode,
required bool initialSaveRecipientAddress, required bool initialSaveRecipientAddress,
required bool initialDisableFiat, required FiatApiMode initialFiatMode,
required bool initialAllowBiometricalAuthentication, required bool initialAllowBiometricalAuthentication,
required bool initialExchangeEnabled, required bool initialExchangeEnabled,
required ThemeBase initialTheme, required ThemeBase initialTheme,
@ -48,7 +50,7 @@ abstract class SettingsStoreBase with Store {
fiatCurrency = initialFiatCurrency, fiatCurrency = initialFiatCurrency,
balanceDisplayMode = initialBalanceDisplayMode, balanceDisplayMode = initialBalanceDisplayMode,
shouldSaveRecipientAddress = initialSaveRecipientAddress, shouldSaveRecipientAddress = initialSaveRecipientAddress,
shouldDisableFiat = initialDisableFiat, fiatApiMode = initialFiatMode,
allowBiometricalAuthentication = initialAllowBiometricalAuthentication, allowBiometricalAuthentication = initialAllowBiometricalAuthentication,
disableExchange = initialExchangeEnabled, disableExchange = initialExchangeEnabled,
currentTheme = initialTheme, currentTheme = initialTheme,
@ -92,10 +94,9 @@ abstract class SettingsStoreBase with Store {
shouldSaveRecipientAddress)); shouldSaveRecipientAddress));
reaction( reaction(
(_) => shouldDisableFiat, (_) => fiatApiMode,
(bool shouldDisableFiat) => sharedPreferences.setBool( (FiatApiMode mode) => sharedPreferences.setInt(
PreferencesKey.shouldDisableFiatKey, PreferencesKey.currentFiatApiModeKey, mode.serialize()));
shouldDisableFiat));
reaction( reaction(
(_) => currentTheme, (_) => currentTheme,
@ -148,10 +149,10 @@ abstract class SettingsStoreBase with Store {
BalanceDisplayMode balanceDisplayMode; BalanceDisplayMode balanceDisplayMode;
@observable @observable
bool shouldSaveRecipientAddress; FiatApiMode fiatApiMode;
@observable @observable
bool shouldDisableFiat; bool shouldSaveRecipientAddress;
@observable @observable
bool allowBiometricalAuthentication; bool allowBiometricalAuthentication;
@ -234,8 +235,9 @@ abstract class SettingsStoreBase with Store {
// FIX-ME: Check for which default value we should have here // FIX-ME: Check for which default value we should have here
final shouldSaveRecipientAddress = final shouldSaveRecipientAddress =
sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? false; sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? false;
final shouldDisableFiat = final currentFiatApiMode = FiatApiMode.deserialize(
sharedPreferences.getBool(PreferencesKey.shouldDisableFiatKey) ?? false; raw: sharedPreferences
.getInt(PreferencesKey.currentFiatApiModeKey)!);
final allowBiometricalAuthentication = sharedPreferences final allowBiometricalAuthentication = sharedPreferences
.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ?? .getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
false; false;
@ -303,7 +305,7 @@ abstract class SettingsStoreBase with Store {
initialFiatCurrency: currentFiatCurrency, initialFiatCurrency: currentFiatCurrency,
initialBalanceDisplayMode: currentBalanceDisplayMode, initialBalanceDisplayMode: currentBalanceDisplayMode,
initialSaveRecipientAddress: shouldSaveRecipientAddress, initialSaveRecipientAddress: shouldSaveRecipientAddress,
initialDisableFiat: shouldDisableFiat, initialFiatMode: currentFiatApiMode,
initialAllowBiometricalAuthentication: allowBiometricalAuthentication, initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
initialExchangeEnabled: disableExchange, initialExchangeEnabled: disableExchange,
initialTheme: savedTheme, initialTheme: savedTheme,

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cw_core/transaction_history.dart'; import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/balance.dart'; import 'package:cw_core/balance.dart';
@ -10,7 +11,6 @@ import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
import 'package:cake_wallet/store/app_store.dart'; import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart'; import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:flutter/cupertino.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
part 'balance_view_model.g.dart'; part 'balance_view_model.g.dart';
@ -72,7 +72,7 @@ abstract class BalanceViewModelBase with Store {
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode; BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
@computed @computed
bool get disableFiat => settingsStore.shouldDisableFiat; bool get disableFiat => settingsStore.fiatApiMode == FiatApiMode.disabled;
@computed @computed
String get asset { String get asset {

View file

@ -1,5 +1,6 @@
import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/store/settings_store.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
part 'privacy_settings_view_model.g.dart'; part 'privacy_settings_view_model.g.dart';
@ -16,9 +17,15 @@ abstract class PrivacySettingsViewModelBase with Store {
@computed @computed
bool get shouldSaveRecipientAddress => _settingsStore.shouldSaveRecipientAddress; bool get shouldSaveRecipientAddress => _settingsStore.shouldSaveRecipientAddress;
@computed
FiatApiMode get fiatApiMode => _settingsStore.fiatApiMode;
@action @action
void setShouldSaveRecipientAddress(bool value) => _settingsStore.shouldSaveRecipientAddress = value; void setShouldSaveRecipientAddress(bool value) => _settingsStore.shouldSaveRecipientAddress = value;
@action @action
void setEnableExchange(bool value) => _settingsStore.disableExchange = value; void setEnableExchange(bool value) => _settingsStore.disableExchange = value;
@action
void setFiatMode(FiatApiMode mode) => _settingsStore.fiatApiMode = mode;
} }