Merge branch 'CW-118-Allow-disabling-of-fiat' of https://github.com/cake-tech/cake_wallet into CW-118-Allow-disabling-of-fiat

This commit is contained in:
Serhii
2022-12-08 09:56:08 +02:00
28 changed files with 55 additions and 98 deletions
@@ -20,8 +20,6 @@ import 'package:cake_wallet/exchange/trade.dart';
import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:collection/collection.dart';
import 'fiat_api_mode.dart';
const newCakeWalletMoneroUri = 'xmr-node.cakewallet.com:18081';
const cakeWalletBitcoinElectrumUri = 'electrum.cakewallet.com:50002';
const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002';
@@ -63,9 +61,6 @@ Future defaultSettingsMigration(
await sharedPreferences.setInt(
PreferencesKey.currentBalanceDisplayModeKey,
BalanceDisplayMode.availableBalance.raw);
await sharedPreferences.setInt(
PreferencesKey.currentFiatApiModeKey,
FiatApiMode.enabled.raw);
await sharedPreferences.setBool('save_recipient_address', true);
await resetToDefault(nodes);
await changeMoneroCurrentNodeToDefault(
@@ -144,10 +139,6 @@ Future defaultSettingsMigration(
await addOnionNode(nodes);
break;
case 19:
await updateFiatApiModes(sharedPreferences);
break;
default:
break;
}
@@ -358,14 +349,6 @@ Future<void> updateDisplayModes(SharedPreferences sharedPreferences) async {
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 {
final key = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
-40
View File
@@ -1,40 +0,0 @@
import 'dart:async';
import 'package:cake_wallet/core/fiat_conversion_service.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/entities/update_haven_rate.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cw_core/wallet_type.dart';
Timer? _timer;
Future<void> startFiatRateUpdate(AppStore appStore, SettingsStore settingsStore,
FiatConversionStore fiatConversionStore) async {
if (_timer != null) {
return;
}
if (appStore.wallet != null) {
fiatConversionStore.prices[appStore.wallet!.currency] =
await FiatConversionService.fetchPrice(
appStore.wallet!.currency, settingsStore.fiatCurrency);
}
_timer = Timer.periodic(
Duration(seconds: 30),
(_) async {
try {
if (appStore.wallet!.type == WalletType.haven) {
await updateHavenRate(fiatConversionStore);
} else {
fiatConversionStore.prices[appStore.wallet!.currency] =
settingsStore.fiatApiMode == FiatApiMode.disabled ? 0.0
: await FiatConversionService.fetchPrice(
appStore.wallet!.currency, settingsStore.fiatCurrency);
}
} catch(e) {
print(e);
}
});
}
+2 -1
View File
@@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/fiat_conversion_service.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
@@ -12,7 +13,7 @@ void startCurrentFiatChangeReaction(AppStore appStore,
_onCurrentFiatCurrencyChangeDisposer?.reaction.dispose();
_onCurrentFiatCurrencyChangeDisposer = reaction(
(_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async {
if (appStore.wallet == null) {
if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) {
return;
}
+2 -1
View File
@@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/entities/update_haven_rate.dart';
import 'package:cw_core/transaction_history.dart';
@@ -87,7 +88,7 @@ void startCurrentWalletChangeReaction(AppStore appStore,
TransactionHistoryBase<TransactionInfo>, TransactionInfo>?
wallet) async {
try {
if (wallet == null) {
if (wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) {
return;
}
@@ -58,7 +58,7 @@ class TransactionsPage extends StatelessWidget {
.format(transaction.date),
formattedAmount: item.formattedCryptoAmount,
formattedFiatAmount:
dashboardViewModel.balanceViewModel.disableFiat
dashboardViewModel.balanceViewModel.isFiatDisabled
? '' : item.formattedFiatAmount,
isPending: transaction.isPending));
}
@@ -74,12 +74,9 @@ class ExchangeTradePage extends BasePage {
}
class ExchangeTradeForm extends StatefulWidget {
ExchangeTradeForm(this.exchangeTradeViewModel)
: disableFiat =
exchangeTradeViewModel.sendViewModel.balanceViewModel.disableFiat;
ExchangeTradeForm(this.exchangeTradeViewModel);
final ExchangeTradeViewModel exchangeTradeViewModel;
final bool disableFiat;
@override
ExchangeTradeState createState() => ExchangeTradeState();
+3 -3
View File
@@ -331,8 +331,8 @@ class SendCardState extends State<SendCard>
],
),
)),
if (!sendViewModel.balanceViewModel.disableFiat)
Padding(
if (!sendViewModel.isFiatDisabled)
Padding(
padding: const EdgeInsets.only(top: 20),
child: BaseTextFormField(
focusNode: fiatAmountFocus,
@@ -438,7 +438,7 @@ class SendCardState extends State<SendCard>
Padding(
padding:
EdgeInsets.only(top: 5),
child: sendViewModel.balanceViewModel.disableFiat
child: sendViewModel.isFiatDisabled
? const SizedBox(height: 14)
: Text(output
.estimatedFeeFiatAmount
+2 -5
View File
@@ -1,12 +1,9 @@
import 'package:cake_wallet/generated/i18n.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/view_model/settings/privacy_settings_view_model.dart';
import 'package:flutter/material.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 {
PrivacyPage(this._privacySettingsViewModel);
@@ -25,8 +22,8 @@ class PrivacyPage extends BasePage {
mainAxisSize: MainAxisSize.min,
children: [
SettingsSwitcherCell(
title: S.current.fiat_api,
value: _privacySettingsViewModel.fiatApiMode,
title: S.current.disable_fiat,
value: _privacySettingsViewModel.isFiatDisabled,
onValueChange: (BuildContext context, bool value) {
_privacySettingsViewModel.setFiatMode(value);
}),
+1 -1
View File
@@ -237,7 +237,7 @@ abstract class SettingsStoreBase with Store {
sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? false;
final currentFiatApiMode = FiatApiMode.deserialize(
raw: sharedPreferences
.getInt(PreferencesKey.currentFiatApiModeKey)!);
.getInt(PreferencesKey.currentFiatApiModeKey) ?? FiatApiMode.enabled.raw);
final allowBiometricalAuthentication = sharedPreferences
.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
false;
@@ -72,7 +72,7 @@ abstract class BalanceViewModelBase with Store {
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
@computed
bool get disableFiat => settingsStore.fiatApiMode == FiatApiMode.disabled;
bool get isFiatDisabled => settingsStore.fiatApiMode == FiatApiMode.disabled;
@computed
String get asset {
@@ -183,8 +183,8 @@ abstract class BalanceViewModelBase with Store {
return MapEntry(key, BalanceRecord(
availableBalance: '---',
additionalBalance: '---',
fiatAdditionalBalance: disableFiat ? '' : '---',
fiatAvailableBalance: disableFiat ? '' : '---',
fiatAdditionalBalance: isFiatDisabled ? '' : '---',
fiatAvailableBalance: isFiatDisabled ? '' : '---',
asset: key,
formattedAssetTitle: _formatterAsset(key)));
}
@@ -195,13 +195,13 @@ abstract class BalanceViewModelBase with Store {
// throw Exception('Price is null for: $key');
// }
final additionalFiatBalance = disableFiat ? '' : (fiatCurrency.toString()
final additionalFiatBalance = isFiatDisabled ? '' : (fiatCurrency.toString()
+ ' '
+ _getFiatBalance(
price: price,
cryptoAmount: value.formattedAdditionalBalance));
final availableFiatBalance = disableFiat ? '' : (fiatCurrency.toString()
final availableFiatBalance = isFiatDisabled ? '' : (fiatCurrency.toString()
+ ' '
+ _getFiatBalance(
price: price,
@@ -74,13 +74,13 @@ abstract class ExchangeTradeViewModelBase with Store {
@computed
String get pendingTransactionFiatAmountValueFormatted =>
sendViewModel.balanceViewModel.disableFiat
sendViewModel.isFiatDisabled
? '' : sendViewModel.pendingTransactionFiatAmount
+ ' ' + sendViewModel.fiat.title;
@computed
String get pendingTransactionFeeFiatAmountFormatted =>
sendViewModel.balanceViewModel.disableFiat
sendViewModel.isFiatDisabled
? '' : sendViewModel.pendingTransactionFeeFiatAmount
+ ' ' + sendViewModel.fiat.title;
+5 -2
View File
@@ -142,14 +142,17 @@ abstract class SendViewModelBase with Store {
@computed
String get balance => balanceViewModel.availableBalance;
@computed
bool get isFiatDisabled => balanceViewModel.isFiatDisabled;
@computed
String get pendingTransactionFiatAmountFormatted =>
balanceViewModel.disableFiat ? '' : pendingTransactionFiatAmount +
isFiatDisabled ? '' : pendingTransactionFiatAmount +
' ' + fiat.title;
@computed
String get pendingTransactionFeeFiatAmountFormatted =>
balanceViewModel.disableFiat ? '' : pendingTransactionFeeFiatAmount +
isFiatDisabled ? '' : pendingTransactionFeeFiatAmount +
' ' + fiat.title;
@computed
@@ -18,7 +18,7 @@ abstract class PrivacySettingsViewModelBase with Store {
bool get shouldSaveRecipientAddress => _settingsStore.shouldSaveRecipientAddress;
@computed
bool get fiatApiMode => _settingsStore.fiatApiMode == FiatApiMode.disabled;
bool get isFiatDisabled => _settingsStore.fiatApiMode == FiatApiMode.disabled;
@action
void setShouldSaveRecipientAddress(bool value) => _settingsStore.shouldSaveRecipientAddress = value;