diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index b2036c3f6..ff8ffc2ed 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -61,6 +61,7 @@ Future defaultSettingsMigration( await sharedPreferences.setInt( PreferencesKey.currentBalanceDisplayModeKey, BalanceDisplayMode.availableBalance.raw); + await sharedPreferences.setBool('disable_fiat', false); await sharedPreferences.setBool('save_recipient_address', true); await resetToDefault(nodes); await changeMoneroCurrentNodeToDefault( diff --git a/lib/entities/preferences_key.dart b/lib/entities/preferences_key.dart index 6cf7e5608..62c458fa0 100644 --- a/lib/entities/preferences_key.dart +++ b/lib/entities/preferences_key.dart @@ -9,6 +9,7 @@ class PreferencesKey { static const currentTransactionPriorityKeyLegacy = 'current_fee_priority'; static const currentBalanceDisplayModeKey = 'current_balance_display_mode'; static const shouldSaveRecipientAddressKey = 'save_recipient_address'; + static const shouldDisableFiatKey = 'disable_fiat'; static const allowBiometricalAuthenticationKey = 'allow_biometrical_authentication'; static const currentTheme = 'current_theme'; diff --git a/lib/reactions/fiat_rate_update.dart b/lib/reactions/fiat_rate_update.dart index 784a14e82..fb40a26e3 100644 --- a/lib/reactions/fiat_rate_update.dart +++ b/lib/reactions/fiat_rate_update.dart @@ -27,7 +27,9 @@ Future startFiatRateUpdate(AppStore appStore, SettingsStore settingsStore, if (appStore.wallet!.type == WalletType.haven) { await updateHavenRate(fiatConversionStore); } else { - fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice( + fiatConversionStore.prices[appStore.wallet!.currency] = + settingsStore.shouldDisableFiat ? 0.0 + : await FiatConversionService.fetchPrice( appStore.wallet!.currency, settingsStore.fiatCurrency); } } catch(e) { diff --git a/lib/src/screens/dashboard/widgets/transactions_page.dart b/lib/src/screens/dashboard/widgets/transactions_page.dart index 8ab7c0efb..9e09bae8c 100644 --- a/lib/src/screens/dashboard/widgets/transactions_page.dart +++ b/lib/src/screens/dashboard/widgets/transactions_page.dart @@ -57,7 +57,9 @@ class TransactionsPage extends StatelessWidget { formattedDate: DateFormat('HH:mm') .format(transaction.date), formattedAmount: item.formattedCryptoAmount, - formattedFiatAmount: item.formattedFiatAmount, + formattedFiatAmount: + dashboardViewModel.balanceViewModel.disableFiat + ? '' : item.formattedFiatAmount, isPending: transaction.isPending)); } diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index aa3079197..4128fb9f2 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -74,9 +74,12 @@ class ExchangeTradePage extends BasePage { } class ExchangeTradeForm extends StatefulWidget { - ExchangeTradeForm(this.exchangeTradeViewModel); + ExchangeTradeForm(this.exchangeTradeViewModel) + : disableFiat = + exchangeTradeViewModel.sendViewModel.balanceViewModel.disableFiat; final ExchangeTradeViewModel exchangeTradeViewModel; + final bool disableFiat; @override ExchangeTradeState createState() => ExchangeTradeState(); @@ -378,9 +381,11 @@ class ExchangeTradeState extends State { }); }, actionLeftButton: () => Navigator.of(context).pop(), - feeFiatAmount: widget.exchangeTradeViewModel.sendViewModel.pendingTransactionFeeFiatAmount + feeFiatAmount: widget.disableFiat ? '' + : widget.exchangeTradeViewModel.sendViewModel.pendingTransactionFeeFiatAmount + ' ' + widget.exchangeTradeViewModel.sendViewModel.fiat.title, - fiatAmountValue: widget.exchangeTradeViewModel.sendViewModel + fiatAmountValue: widget.disableFiat ? '' + : widget.exchangeTradeViewModel.sendViewModel .pendingTransactionFiatAmount + ' ' + widget.exchangeTradeViewModel.sendViewModel.fiat.title, diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index e0cfff517..8815d8c58 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -386,16 +386,14 @@ class SendPage extends BasePage { amount: S.of(context).send_amount, amountValue: sendViewModel.pendingTransaction!.amountFormatted, - fiatAmountValue: - sendViewModel.pendingTransactionFiatAmount + - ' ' + - sendViewModel.fiat.title, + fiatAmountValue: sendViewModel.balanceViewModel.disableFiat + ? '' : sendViewModel.pendingTransactionFiatAmount + + ' ' + sendViewModel.fiat.title, fee: S.of(context).send_fee, feeValue: sendViewModel.pendingTransaction!.feeFormatted, - feeFiatAmount: - sendViewModel.pendingTransactionFeeFiatAmount + - ' ' + - sendViewModel.fiat.title, + feeFiatAmount: sendViewModel.balanceViewModel.disableFiat + ? '' : sendViewModel.pendingTransactionFeeFiatAmount + + ' ' + sendViewModel.fiat.title, outputs: sendViewModel.outputs, rightButtonText: S.of(context).ok, leftButtonText: S.of(context).cancel, diff --git a/lib/src/screens/send/widgets/send_card.dart b/lib/src/screens/send/widgets/send_card.dart index dc589923f..7e7194f88 100644 --- a/lib/src/screens/send/widgets/send_card.dart +++ b/lib/src/screens/send/widgets/send_card.dart @@ -332,6 +332,8 @@ class SendCardState extends State ], ), )), + sendViewModel.balanceViewModel.disableFiat ? + Container () : Padding( padding: const EdgeInsets.only(top: 20), child: BaseTextFormField( @@ -438,8 +440,8 @@ class SendCardState extends State Padding( padding: EdgeInsets.only(top: 5), - child: Text( - output + child: sendViewModel.balanceViewModel.disableFiat ? + Container () : Text(output .estimatedFeeFiatAmount + ' ' + sendViewModel diff --git a/lib/src/screens/settings/settings.dart b/lib/src/screens/settings/settings.dart index 3f6f41e7b..4a1f6bcb0 100644 --- a/lib/src/screens/settings/settings.dart +++ b/lib/src/screens/settings/settings.dart @@ -29,18 +29,20 @@ class SettingsPage extends BasePage { @override Widget body(BuildContext context) { // FIX-ME: Added `context` it was not used here before, maby bug ? - return SectionStandardList( + return Observer(builder: (_) { + final sections = settingsViewModel.getSections(); + return SectionStandardList( context: context, - sectionCount: settingsViewModel.sections.length, + sectionCount: sections.length, itemCounter: (int sectionIndex) { - if (sectionIndex < settingsViewModel.sections.length) { - return settingsViewModel.sections[sectionIndex].length; + if (sectionIndex < sections.length) { + return sections[sectionIndex].length; } return 0; }, itemBuilder: (_, sectionIndex, itemIndex) { - final item = settingsViewModel.sections[sectionIndex][itemIndex]; + final item = sections[sectionIndex][itemIndex]; if (item is PickerListItem) { return Observer(builder: (_) { @@ -94,5 +96,6 @@ class SettingsPage extends BasePage { return Container(); }); + }); } } diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 2b3105a34..5afd2c107 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -29,6 +29,7 @@ abstract class SettingsStoreBase with Store { required FiatCurrency initialFiatCurrency, required BalanceDisplayMode initialBalanceDisplayMode, required bool initialSaveRecipientAddress, + required bool initialDisableFiat, required bool initialAllowBiometricalAuthentication, required ThemeBase initialTheme, required int initialPinLength, @@ -46,6 +47,7 @@ abstract class SettingsStoreBase with Store { fiatCurrency = initialFiatCurrency, balanceDisplayMode = initialBalanceDisplayMode, shouldSaveRecipientAddress = initialSaveRecipientAddress, + shouldDisableFiat = initialDisableFiat, allowBiometricalAuthentication = initialAllowBiometricalAuthentication, currentTheme = initialTheme, pinCodeLength = initialPinLength, @@ -87,6 +89,12 @@ abstract class SettingsStoreBase with Store { PreferencesKey.shouldSaveRecipientAddressKey, shouldSaveRecipientAddress)); + reaction( + (_) => shouldDisableFiat, + (bool shouldDisableFiat) => sharedPreferences.setBool( + PreferencesKey.shouldDisableFiatKey, + shouldDisableFiat)); + reaction( (_) => currentTheme, (ThemeBase theme) => @@ -140,6 +148,9 @@ abstract class SettingsStoreBase with Store { @observable bool shouldSaveRecipientAddress; + @observable + bool shouldDisableFiat; + @observable bool allowBiometricalAuthentication; @@ -218,6 +229,8 @@ abstract class SettingsStoreBase with Store { // FIX-ME: Check for which default value we should have here final shouldSaveRecipientAddress = sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? false; + final shouldDisableFiat = + sharedPreferences.getBool(PreferencesKey.shouldDisableFiatKey) ?? false; final allowBiometricalAuthentication = sharedPreferences .getBool(PreferencesKey.allowBiometricalAuthenticationKey) ?? false; @@ -283,6 +296,7 @@ abstract class SettingsStoreBase with Store { initialFiatCurrency: currentFiatCurrency, initialBalanceDisplayMode: currentBalanceDisplayMode, initialSaveRecipientAddress: shouldSaveRecipientAddress, + initialDisableFiat: shouldDisableFiat, initialAllowBiometricalAuthentication: allowBiometricalAuthentication, initialTheme: savedTheme, actionlistDisplayMode: actionListDisplayMode, diff --git a/lib/view_model/dashboard/balance_view_model.dart b/lib/view_model/dashboard/balance_view_model.dart index 75d107b89..40502bb84 100644 --- a/lib/view_model/dashboard/balance_view_model.dart +++ b/lib/view_model/dashboard/balance_view_model.dart @@ -71,6 +71,9 @@ abstract class BalanceViewModelBase with Store { @computed BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode; + @computed + bool get disableFiat => settingsStore.shouldDisableFiat; + @computed String get asset { final typeFormatted = walletTypeToString(appStore.wallet!.type); @@ -180,8 +183,8 @@ abstract class BalanceViewModelBase with Store { return MapEntry(key, BalanceRecord( availableBalance: '---', additionalBalance: '---', - fiatAdditionalBalance: '---', - fiatAvailableBalance: '---', + fiatAdditionalBalance: disableFiat ? '' : '---', + fiatAvailableBalance: disableFiat ? '' : '---', asset: key, formattedAssetTitle: _formatterAsset(key))); } @@ -192,17 +195,17 @@ abstract class BalanceViewModelBase with Store { // throw Exception('Price is null for: $key'); // } - final additionalFiatBalance = fiatCurrency.toString() - + ' ' + final additionalFiatBalance = disableFiat ? '' : (fiatCurrency.toString() + + ' ' + _getFiatBalance( price: price, - cryptoAmount: value.formattedAdditionalBalance); + cryptoAmount: value.formattedAdditionalBalance)); - final availableFiatBalance = fiatCurrency.toString() - + ' ' + final availableFiatBalance = disableFiat ? '' : (fiatCurrency.toString() + + ' ' + _getFiatBalance( price: price, - cryptoAmount: value.formattedAvailableBalance); + cryptoAmount: value.formattedAvailableBalance)); return MapEntry(key, BalanceRecord( availableBalance: value.formattedAvailableBalance, diff --git a/lib/view_model/settings/settings_view_model.dart b/lib/view_model/settings/settings_view_model.dart index 96b2e7bdd..23ea0fded 100644 --- a/lib/view_model/settings/settings_view_model.dart +++ b/lib/view_model/settings/settings_view_model.dart @@ -61,7 +61,6 @@ abstract class SettingsViewModelBase with Store { : itemHeaders = {}, _walletType = wallet.type, _biometricAuth = BiometricAuth(), - sections = >[], currentVersion = '' { PackageInfo.fromPlatform().then( (PackageInfo packageInfo) => currentVersion = packageInfo.version); @@ -98,7 +97,7 @@ abstract class SettingsViewModelBase with Store { //} - sections = [ + getSections = () => [ [ SwitcherListItem( title: S.current.settings_display_balance, @@ -111,7 +110,7 @@ abstract class SettingsViewModelBase with Store { } }, ), - if (!isHaven) + if (!isHaven && !shouldDisableFiat) PickerListItem( title: S.current.settings_currency, searchHintText: S.current.search_currency, @@ -183,6 +182,11 @@ abstract class SettingsViewModelBase with Store { return LanguageService.list[code]?.toLowerCase().contains(searchText) ?? false; }, ), + SwitcherListItem( + title: 'S.current.disable_fiat', + value: () => shouldDisableFiat, + onValueChange: (_, bool value) => + setShouldDisableFiat(value)), SwitcherListItem( title: S.current.settings_allow_biometrical_authentication, value: () => allowBiometricalAuthentication, @@ -208,6 +212,7 @@ abstract class SettingsViewModelBase with Store { setAllowBiometricalAuthentication(value); } }), + ChoicesListItem( title: S.current.color_theme, items: ThemeList.all, @@ -275,6 +280,10 @@ abstract class SettingsViewModelBase with Store { bool get shouldSaveRecipientAddress => _settingsStore.shouldSaveRecipientAddress; + @computed + bool get shouldDisableFiat => + _settingsStore.shouldDisableFiat; + @computed bool get allowBiometricalAuthentication => _settingsStore.allowBiometricalAuthentication; @@ -285,7 +294,7 @@ abstract class SettingsViewModelBase with Store { bool get isBitcoinBuyEnabled => _settingsStore.isBitcoinBuyEnabled; final Map itemHeaders; - List> sections; + late List> Function() getSections; final SettingsStore _settingsStore; final YatStore _yatStore; final WalletType _walletType; @@ -303,6 +312,10 @@ abstract class SettingsViewModelBase with Store { void setShouldSaveRecipientAddress(bool value) => _settingsStore.shouldSaveRecipientAddress = value; + @action + void setShouldDisableFiat(bool value) => + _settingsStore.shouldDisableFiat = value; + @action void setAllowBiometricalAuthentication(bool value) => _settingsStore.allowBiometricalAuthentication = value;