Merge branch 'main' of https://github.com/cake-tech/cake_wallet into CW-239-fix-restore-from-backup-using-6-digit-pin

 Conflicts:
	lib/store/settings_store.dart
This commit is contained in:
OmarHatem
2022-12-09 20:29:50 +02:00
38 changed files with 353 additions and 115 deletions
@@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/settings/switcher_list_item.dart';
import 'package:cw_core/wallet_type.dart';
@@ -11,15 +12,13 @@ class AdvancedPrivacySettingsViewModel = AdvancedPrivacySettingsViewModelBase
abstract class AdvancedPrivacySettingsViewModelBase with Store {
AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore)
: _disableFiat = false,
_addCustomNode = false {
: _addCustomNode = false {
settings = [
// TODO: uncomment when Disable Fiat PR is merged
// SwitcherListItem(
// title: S.current.disable_fiat,
// value: () => _disableFiat,
// onValueChange: (_, bool value) => _disableFiat = value,
// ),
SwitcherListItem(
title: S.current.disable_fiat,
value: () => _settingsStore.fiatApiMode == FiatApiMode.disabled,
onValueChange: (_, bool value) => setFiatMode(value),
),
SwitcherListItem(
title: S.current.disable_exchange,
value: () => _settingsStore.disableExchange,
@@ -37,9 +36,6 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
late List<SwitcherListItem> settings;
@observable
bool _disableFiat = false;
@observable
bool _addCustomNode = false;
@@ -48,4 +44,13 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
@computed
bool get addCustomNode => _addCustomNode;
@action
void setFiatMode(bool value) {
if (value) {
_settingsStore.fiatApiMode = FiatApiMode.disabled;
return;
}
_settingsStore.fiatApiMode = FiatApiMode.enabled;
}
}
@@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/wallet_base.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/settings_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:flutter/cupertino.dart';
import 'package:mobx/mobx.dart';
part 'balance_view_model.g.dart';
@@ -71,6 +71,9 @@ abstract class BalanceViewModelBase with Store {
@computed
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
@computed
bool get isFiatDisabled => settingsStore.fiatApiMode == FiatApiMode.disabled;
@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: isFiatDisabled ? '' : '---',
fiatAvailableBalance: isFiatDisabled ? '' : '---',
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 = isFiatDisabled ? '' : (fiatCurrency.toString()
+ ' '
+ _getFiatBalance(
price: price,
cryptoAmount: value.formattedAdditionalBalance);
cryptoAmount: value.formattedAdditionalBalance));
final availableFiatBalance = fiatCurrency.toString()
+ ' '
final availableFiatBalance = isFiatDisabled ? '' : (fiatCurrency.toString()
+ ' '
+ _getFiatBalance(
price: price,
cryptoAmount: value.formattedAvailableBalance);
cryptoAmount: value.formattedAvailableBalance));
return MapEntry(key, BalanceRecord(
availableBalance: value.formattedAvailableBalance,
@@ -72,6 +72,18 @@ abstract class ExchangeTradeViewModelBase with Store {
? '\n\n' + S.current.xrp_extra_info
: '';
@computed
String get pendingTransactionFiatAmountValueFormatted =>
sendViewModel.isFiatDisabled
? '' : sendViewModel.pendingTransactionFiatAmount
+ ' ' + sendViewModel.fiat.title;
@computed
String get pendingTransactionFeeFiatAmountFormatted =>
sendViewModel.isFiatDisabled
? '' : sendViewModel.pendingTransactionFeeFiatAmount
+ ' ' + sendViewModel.fiat.title;
@observable
ObservableList<ExchangeTradeItem> items;
+13
View File
@@ -142,6 +142,19 @@ abstract class SendViewModelBase with Store {
@computed
String get balance => balanceViewModel.availableBalance;
@computed
bool get isFiatDisabled => balanceViewModel.isFiatDisabled;
@computed
String get pendingTransactionFiatAmountFormatted =>
isFiatDisabled ? '' : pendingTransactionFiatAmount +
' ' + fiat.title;
@computed
String get pendingTransactionFeeFiatAmountFormatted =>
isFiatDisabled ? '' : pendingTransactionFeeFiatAmount +
' ' + fiat.title;
@computed
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
@@ -3,6 +3,7 @@ import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
part 'display_settings_view_model.g.dart';
@@ -30,6 +31,9 @@ abstract class DisplaySettingsViewModelBase with Store {
@computed
ThemeBase get theme => _settingsStore.currentTheme;
@computed
bool get disabledFiatApiMode => _settingsStore.fiatApiMode == FiatApiMode.disabled;
@action
void setBalanceDisplayMode(BalanceDisplayMode value) => _settingsStore.balanceDisplayMode = value;
@@ -1,5 +1,6 @@
import 'package:cake_wallet/store/settings_store.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
part 'privacy_settings_view_model.g.dart';
@@ -16,9 +17,22 @@ abstract class PrivacySettingsViewModelBase with Store {
@computed
bool get shouldSaveRecipientAddress => _settingsStore.shouldSaveRecipientAddress;
@computed
bool get isFiatDisabled => _settingsStore.fiatApiMode == FiatApiMode.disabled;
@action
void setShouldSaveRecipientAddress(bool value) => _settingsStore.shouldSaveRecipientAddress = value;
@action
void setEnableExchange(bool value) => _settingsStore.disableExchange = value;
@action
void setFiatMode(bool value) {
if (value) {
_settingsStore.fiatApiMode = FiatApiMode.disabled;
return;
}
_settingsStore.fiatApiMode = FiatApiMode.enabled;
}
}