2023-05-17 14:43:23 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
2023-03-01 21:44:15 +00:00
|
|
|
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
2022-11-22 20:52:28 +00:00
|
|
|
import 'package:cake_wallet/entities/pin_code_required_duration.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/preferences_key.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/transaction_priority.dart';
|
2020-12-15 19:43:50 +00:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
|
|
|
import 'package:cake_wallet/themes/theme_list.dart';
|
2023-05-17 14:43:23 +00:00
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
2020-09-28 15:47:43 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:package_info/package_info.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2020-09-28 15:47:43 +00:00
|
|
|
import 'package:cake_wallet/entities/language_service.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
|
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/node.dart';
|
|
|
|
import 'package:cake_wallet/monero/monero.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/action_list_display_mode.dart';
|
2022-12-06 23:38:36 +00:00
|
|
|
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
2023-04-20 09:59:59 +00:00
|
|
|
import 'package:cw_core/set_app_secure_native.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
part 'settings_store.g.dart';
|
|
|
|
|
|
|
|
class SettingsStore = SettingsStoreBase with _$SettingsStore;
|
|
|
|
|
|
|
|
abstract class SettingsStoreBase with Store {
|
|
|
|
SettingsStoreBase(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required SharedPreferences sharedPreferences,
|
2023-04-16 13:45:35 +00:00
|
|
|
required bool initialShouldShowMarketPlaceInDashboard,
|
2022-10-12 17:09:57 +00:00
|
|
|
required FiatCurrency initialFiatCurrency,
|
|
|
|
required BalanceDisplayMode initialBalanceDisplayMode,
|
|
|
|
required bool initialSaveRecipientAddress,
|
2023-04-20 09:59:59 +00:00
|
|
|
required bool initialAppSecure,
|
2023-05-15 12:26:56 +00:00
|
|
|
required bool initialDisableBuy,
|
|
|
|
required bool initialDisableSell,
|
2022-12-06 23:38:36 +00:00
|
|
|
required FiatApiMode initialFiatMode,
|
2022-10-12 17:09:57 +00:00
|
|
|
required bool initialAllowBiometricalAuthentication,
|
2023-05-17 14:43:23 +00:00
|
|
|
required String initialTotpSecretKey,
|
|
|
|
required bool initialUseTOTP2FA,
|
|
|
|
required int initialFailedTokenTrial,
|
2023-03-01 21:44:15 +00:00
|
|
|
required ExchangeApiMode initialExchangeStatus,
|
2022-10-12 17:09:57 +00:00
|
|
|
required ThemeBase initialTheme,
|
|
|
|
required int initialPinLength,
|
|
|
|
required String initialLanguageCode,
|
|
|
|
// required String initialCurrentLocale,
|
|
|
|
required this.appVersion,
|
2023-05-17 14:43:23 +00:00
|
|
|
required this.deviceName,
|
2022-10-12 17:09:57 +00:00
|
|
|
required Map<WalletType, Node> nodes,
|
|
|
|
required this.shouldShowYatPopup,
|
|
|
|
required this.isBitcoinBuyEnabled,
|
|
|
|
required this.actionlistDisplayMode,
|
2022-11-22 20:52:28 +00:00
|
|
|
required this.pinTimeOutDuration,
|
2022-10-12 17:09:57 +00:00
|
|
|
TransactionPriority? initialBitcoinTransactionPriority,
|
2022-12-08 15:23:17 +00:00
|
|
|
TransactionPriority? initialMoneroTransactionPriority,
|
|
|
|
TransactionPriority? initialHavenTransactionPriority,
|
|
|
|
TransactionPriority? initialLitecoinTransactionPriority})
|
2023-05-17 14:43:23 +00:00
|
|
|
: nodes = ObservableMap<WalletType, Node>.of(nodes),
|
|
|
|
_sharedPreferences = sharedPreferences,
|
|
|
|
fiatCurrency = initialFiatCurrency,
|
|
|
|
balanceDisplayMode = initialBalanceDisplayMode,
|
|
|
|
shouldSaveRecipientAddress = initialSaveRecipientAddress,
|
|
|
|
fiatApiMode = initialFiatMode,
|
|
|
|
allowBiometricalAuthentication = initialAllowBiometricalAuthentication,
|
|
|
|
totpSecretKey = initialTotpSecretKey,
|
|
|
|
useTOTP2FA = initialUseTOTP2FA,
|
|
|
|
numberOfFailedTokenTrials = initialFailedTokenTrial,
|
2023-04-20 09:59:59 +00:00
|
|
|
isAppSecure = initialAppSecure,
|
2023-05-17 14:43:23 +00:00
|
|
|
disableBuy = initialDisableBuy,
|
|
|
|
disableSell = initialDisableSell,
|
2023-04-16 13:45:35 +00:00
|
|
|
shouldShowMarketPlaceInDashboard = initialShouldShowMarketPlaceInDashboard,
|
2023-05-17 14:43:23 +00:00
|
|
|
exchangeStatus = initialExchangeStatus,
|
|
|
|
currentTheme = initialTheme,
|
|
|
|
pinCodeLength = initialPinLength,
|
|
|
|
languageCode = initialLanguageCode,
|
|
|
|
priority = ObservableMap<WalletType, TransactionPriority>() {
|
2022-10-12 17:09:57 +00:00
|
|
|
//this.nodes = ObservableMap<WalletType, Node>.of(nodes);
|
|
|
|
|
|
|
|
if (initialMoneroTransactionPriority != null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
priority[WalletType.monero] = initialMoneroTransactionPriority;
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (initialBitcoinTransactionPriority != null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
priority[WalletType.bitcoin] = initialBitcoinTransactionPriority;
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
2020-09-10 14:51:59 +00:00
|
|
|
|
2022-12-08 15:23:17 +00:00
|
|
|
if (initialHavenTransactionPriority != null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
priority[WalletType.haven] = initialHavenTransactionPriority;
|
2022-12-08 15:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (initialLitecoinTransactionPriority != null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
priority[WalletType.litecoin] = initialLitecoinTransactionPriority;
|
2022-12-08 15:23:17 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 19:02:30 +00:00
|
|
|
reaction(
|
|
|
|
(_) => fiatCurrency,
|
|
|
|
(FiatCurrency fiatCurrency) => sharedPreferences.setString(
|
|
|
|
PreferencesKey.currentFiatCurrencyKey, fiatCurrency.serialize()));
|
|
|
|
|
2021-10-04 13:03:35 +00:00
|
|
|
reaction(
|
|
|
|
(_) => shouldShowYatPopup,
|
2023-05-17 14:43:23 +00:00
|
|
|
(bool shouldShowYatPopup) =>
|
|
|
|
sharedPreferences.setBool(PreferencesKey.shouldShowYatPopup, shouldShowYatPopup));
|
2021-10-04 13:03:35 +00:00
|
|
|
|
2021-01-27 13:51:51 +00:00
|
|
|
priority.observe((change) {
|
2022-12-08 15:23:17 +00:00
|
|
|
final String? key;
|
|
|
|
switch (change.key) {
|
|
|
|
case WalletType.monero:
|
|
|
|
key = PreferencesKey.moneroTransactionPriority;
|
|
|
|
break;
|
|
|
|
case WalletType.bitcoin:
|
|
|
|
key = PreferencesKey.bitcoinTransactionPriority;
|
|
|
|
break;
|
|
|
|
case WalletType.litecoin:
|
|
|
|
key = PreferencesKey.litecoinTransactionPriority;
|
|
|
|
break;
|
|
|
|
case WalletType.haven:
|
|
|
|
key = PreferencesKey.havenTransactionPriority;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
key = null;
|
|
|
|
}
|
2021-01-27 13:51:51 +00:00
|
|
|
|
2022-12-08 15:23:17 +00:00
|
|
|
if (change.newValue != null && key != null) {
|
2022-10-12 17:09:57 +00:00
|
|
|
sharedPreferences.setInt(key, change.newValue!.serialize());
|
|
|
|
}
|
2021-01-27 13:51:51 +00:00
|
|
|
});
|
2020-09-28 19:02:30 +00:00
|
|
|
|
|
|
|
reaction(
|
|
|
|
(_) => shouldSaveRecipientAddress,
|
|
|
|
(bool shouldSaveRecipientAddress) => sharedPreferences.setBool(
|
2023-05-17 14:43:23 +00:00
|
|
|
PreferencesKey.shouldSaveRecipientAddressKey, shouldSaveRecipientAddress));
|
2020-09-28 19:02:30 +00:00
|
|
|
|
2023-05-17 15:34:41 +00:00
|
|
|
setIsAppSecureNative(isAppSecure);
|
|
|
|
|
2023-04-20 09:59:59 +00:00
|
|
|
reaction((_) => isAppSecure, (bool isAppSecure) {
|
|
|
|
sharedPreferences.setBool(PreferencesKey.isAppSecureKey, isAppSecure);
|
|
|
|
setIsAppSecureNative(isAppSecure);
|
|
|
|
});
|
|
|
|
|
2023-05-15 12:26:56 +00:00
|
|
|
reaction(
|
|
|
|
(_) => disableBuy,
|
|
|
|
(bool disableBuy) => sharedPreferences.setBool(
|
|
|
|
PreferencesKey.disableBuyKey, disableBuy));
|
|
|
|
|
|
|
|
reaction(
|
|
|
|
(_) => disableSell,
|
|
|
|
(bool disableSell) => sharedPreferences.setBool(
|
|
|
|
PreferencesKey.disableSellKey, disableSell));
|
|
|
|
|
2022-11-04 11:58:04 +00:00
|
|
|
reaction(
|
2023-05-17 14:43:23 +00:00
|
|
|
(_) => fiatApiMode,
|
|
|
|
(FiatApiMode mode) =>
|
|
|
|
sharedPreferences.setInt(PreferencesKey.currentFiatApiModeKey, mode.serialize()));
|
2022-11-04 11:58:04 +00:00
|
|
|
|
2023-05-17 14:43:23 +00:00
|
|
|
reaction((_) => currentTheme,
|
|
|
|
(ThemeBase theme) => sharedPreferences.setInt(PreferencesKey.currentTheme, theme.raw));
|
2020-09-28 19:02:30 +00:00
|
|
|
|
2020-09-10 14:51:59 +00:00
|
|
|
reaction(
|
|
|
|
(_) => allowBiometricalAuthentication,
|
|
|
|
(bool biometricalAuthentication) => sharedPreferences.setBool(
|
2023-05-17 14:43:23 +00:00
|
|
|
PreferencesKey.allowBiometricalAuthenticationKey, biometricalAuthentication));
|
|
|
|
|
|
|
|
reaction(
|
|
|
|
(_) => useTOTP2FA, (bool use) => sharedPreferences.setBool(PreferencesKey.useTOTP2FA, use));
|
|
|
|
|
|
|
|
reaction(
|
|
|
|
(_) => numberOfFailedTokenTrials,
|
|
|
|
(int failedTokenTrail) =>
|
|
|
|
sharedPreferences.setInt(PreferencesKey.failedTotpTokenTrials, failedTokenTrail));
|
|
|
|
|
|
|
|
reaction((_) => totpSecretKey,
|
|
|
|
(String totpKey) => sharedPreferences.setString(PreferencesKey.totpSecretKey, totpKey));
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2023-04-16 13:45:35 +00:00
|
|
|
reaction(
|
|
|
|
(_) => shouldShowMarketPlaceInDashboard,
|
|
|
|
(bool value) =>
|
|
|
|
sharedPreferences.setBool(PreferencesKey.shouldShowMarketPlaceInDashboard, value));
|
|
|
|
|
2023-05-17 14:43:23 +00:00
|
|
|
reaction((_) => pinCodeLength,
|
|
|
|
(int pinLength) => sharedPreferences.setInt(PreferencesKey.currentPinLength, pinLength));
|
2020-09-26 19:17:31 +00:00
|
|
|
|
2020-09-28 19:02:30 +00:00
|
|
|
reaction(
|
|
|
|
(_) => languageCode,
|
2023-05-17 14:43:23 +00:00
|
|
|
(String languageCode) =>
|
|
|
|
sharedPreferences.setString(PreferencesKey.currentLanguageCode, languageCode));
|
2020-12-15 16:29:10 +00:00
|
|
|
|
2022-11-22 20:52:28 +00:00
|
|
|
reaction(
|
|
|
|
(_) => pinTimeOutDuration,
|
2023-05-17 14:43:23 +00:00
|
|
|
(PinCodeRequiredDuration pinCodeInterval) =>
|
|
|
|
sharedPreferences.setInt(PreferencesKey.pinTimeOutDuration, pinCodeInterval.value));
|
2022-11-22 20:52:28 +00:00
|
|
|
|
2021-01-15 17:41:30 +00:00
|
|
|
reaction(
|
|
|
|
(_) => balanceDisplayMode,
|
|
|
|
(BalanceDisplayMode mode) => sharedPreferences.setInt(
|
|
|
|
PreferencesKey.currentBalanceDisplayModeKey, mode.serialize()));
|
2020-12-18 19:42:00 +00:00
|
|
|
|
2022-12-08 19:14:42 +00:00
|
|
|
reaction(
|
2023-05-17 14:43:23 +00:00
|
|
|
(_) => exchangeStatus,
|
|
|
|
(ExchangeApiMode mode) =>
|
|
|
|
sharedPreferences.setInt(PreferencesKey.exchangeStatusKey, mode.serialize()));
|
|
|
|
|
|
|
|
this.nodes.observe((change) {
|
|
|
|
if (change.newValue != null && change.key != null) {
|
|
|
|
_saveCurrentNode(change.newValue!, change.key!);
|
|
|
|
}
|
|
|
|
});
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 11:50:26 +00:00
|
|
|
static const defaultPinLength = 4;
|
|
|
|
static const defaultActionsMode = 11;
|
2022-12-13 15:19:31 +00:00
|
|
|
static const defaultPinCodeTimeOutDuration = PinCodeRequiredDuration.tenminutes;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
@observable
|
|
|
|
FiatCurrency fiatCurrency;
|
|
|
|
|
2021-10-04 13:03:35 +00:00
|
|
|
@observable
|
|
|
|
bool shouldShowYatPopup;
|
|
|
|
|
2023-04-16 13:45:35 +00:00
|
|
|
@observable
|
|
|
|
bool shouldShowMarketPlaceInDashboard;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
@observable
|
|
|
|
ObservableList<ActionListDisplayMode> actionlistDisplayMode;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
BalanceDisplayMode balanceDisplayMode;
|
|
|
|
|
|
|
|
@observable
|
2022-12-06 23:38:36 +00:00
|
|
|
FiatApiMode fiatApiMode;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
@observable
|
|
|
|
bool shouldSaveRecipientAddress;
|
|
|
|
|
2023-04-20 09:59:59 +00:00
|
|
|
@observable
|
|
|
|
bool isAppSecure;
|
|
|
|
|
2023-05-15 12:26:56 +00:00
|
|
|
@observable
|
|
|
|
bool disableBuy;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
bool disableSell;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
@observable
|
|
|
|
bool allowBiometricalAuthentication;
|
|
|
|
|
2023-05-17 14:43:23 +00:00
|
|
|
@observable
|
|
|
|
String totpSecretKey;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
String get totpVersionOneLink {
|
|
|
|
return 'otpauth://totp/Cake%20Wallet:$deviceName?secret=$totpSecretKey&issuer=Cake%20Wallet&algorithm=SHA512&digits=8&period=30';
|
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
|
|
|
bool useTOTP2FA;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
int numberOfFailedTokenTrials;
|
|
|
|
|
2022-11-22 02:18:18 +00:00
|
|
|
@observable
|
2023-03-01 21:44:15 +00:00
|
|
|
ExchangeApiMode exchangeStatus;
|
2022-11-22 02:18:18 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
@observable
|
2020-12-15 19:30:16 +00:00
|
|
|
ThemeBase currentTheme;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
@observable
|
2020-09-21 11:50:26 +00:00
|
|
|
int pinCodeLength;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2022-11-22 20:52:28 +00:00
|
|
|
@observable
|
|
|
|
PinCodeRequiredDuration pinTimeOutDuration;
|
|
|
|
|
2020-09-28 15:47:43 +00:00
|
|
|
@computed
|
2020-12-10 17:53:40 +00:00
|
|
|
ThemeData get theme => currentTheme.themeData;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2020-09-28 15:47:43 +00:00
|
|
|
@observable
|
|
|
|
String languageCode;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2021-01-27 13:51:51 +00:00
|
|
|
@observable
|
|
|
|
ObservableMap<WalletType, TransactionPriority> priority;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
String appVersion;
|
|
|
|
|
2023-05-17 14:43:23 +00:00
|
|
|
String deviceName;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
SharedPreferences _sharedPreferences;
|
|
|
|
|
2020-09-07 15:13:39 +00:00
|
|
|
ObservableMap<WalletType, Node> nodes;
|
2020-08-27 16:54:34 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Node getCurrentNode(WalletType walletType) {
|
|
|
|
final node = nodes[walletType];
|
|
|
|
|
|
|
|
if (node == null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
throw Exception('No node found for wallet type: ${walletType.toString()}');
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
2020-08-27 16:54:34 +00:00
|
|
|
|
2021-03-16 13:20:46 +00:00
|
|
|
bool isBitcoinBuyEnabled;
|
|
|
|
|
2021-06-04 10:30:59 +00:00
|
|
|
bool get shouldShowReceiveWarning =>
|
2023-05-17 14:43:23 +00:00
|
|
|
_sharedPreferences.getBool(PreferencesKey.shouldShowReceiveWarning) ?? true;
|
2021-06-04 10:30:59 +00:00
|
|
|
|
|
|
|
Future<void> setShouldShowReceiveWarning(bool value) async =>
|
2023-05-17 14:43:23 +00:00
|
|
|
_sharedPreferences.setBool(PreferencesKey.shouldShowReceiveWarning, value);
|
2021-06-04 10:30:59 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
static Future<SettingsStore> load(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required Box<Node> nodeSource,
|
|
|
|
required bool isBitcoinBuyEnabled,
|
2020-07-06 20:09:03 +00:00
|
|
|
FiatCurrency initialFiatCurrency = FiatCurrency.usd,
|
2023-04-14 04:39:08 +00:00
|
|
|
BalanceDisplayMode initialBalanceDisplayMode = BalanceDisplayMode.availableBalance,
|
|
|
|
ThemeBase? initialTheme}) async {
|
2020-07-06 20:09:03 +00:00
|
|
|
final sharedPreferences = await getIt.getAsync<SharedPreferences>();
|
2023-05-17 14:43:23 +00:00
|
|
|
final currentFiatCurrency = FiatCurrency.deserialize(
|
|
|
|
raw: sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey)!);
|
2022-12-08 15:23:17 +00:00
|
|
|
|
2023-05-17 14:43:23 +00:00
|
|
|
TransactionPriority? moneroTransactionPriority = monero?.deserializeMoneroTransactionPriority(
|
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!);
|
2022-12-08 15:23:17 +00:00
|
|
|
TransactionPriority? bitcoinTransactionPriority =
|
2023-05-17 14:43:23 +00:00
|
|
|
bitcoin?.deserializeBitcoinTransactionPriority(
|
|
|
|
sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!);
|
2022-12-08 15:23:17 +00:00
|
|
|
|
|
|
|
TransactionPriority? havenTransactionPriority;
|
|
|
|
TransactionPriority? litecoinTransactionPriority;
|
|
|
|
|
|
|
|
if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
|
|
|
|
havenTransactionPriority = monero?.deserializeMoneroTransactionPriority(
|
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!);
|
|
|
|
}
|
|
|
|
if (sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority) != null) {
|
|
|
|
litecoinTransactionPriority = bitcoin?.deserializeLitecoinTransactionPriority(
|
|
|
|
sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!);
|
|
|
|
}
|
|
|
|
|
|
|
|
moneroTransactionPriority ??= monero?.getDefaultTransactionPriority();
|
|
|
|
bitcoinTransactionPriority ??= bitcoin?.getMediumTransactionPriority();
|
|
|
|
havenTransactionPriority ??= monero?.getDefaultTransactionPriority();
|
|
|
|
litecoinTransactionPriority ??= bitcoin?.getLitecoinTransactionPriorityMedium();
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
final currentBalanceDisplayMode = BalanceDisplayMode.deserialize(
|
2023-05-17 14:43:23 +00:00
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
|
2022-10-12 17:09:57 +00:00
|
|
|
// FIX-ME: Check for which default value we should have here
|
2020-07-06 20:09:03 +00:00
|
|
|
final shouldSaveRecipientAddress =
|
2022-10-12 17:09:57 +00:00
|
|
|
sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? false;
|
2023-04-20 09:59:59 +00:00
|
|
|
final isAppSecure =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.isAppSecureKey) ?? false;
|
2023-05-15 12:26:56 +00:00
|
|
|
final disableBuy =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.disableBuyKey) ?? false;
|
|
|
|
final disableSell =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.disableSellKey) ?? false;
|
2022-12-06 23:38:36 +00:00
|
|
|
final currentFiatApiMode = FiatApiMode.deserialize(
|
2023-05-17 14:43:23 +00:00
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.currentFiatApiModeKey) ??
|
|
|
|
FiatApiMode.enabled.raw);
|
|
|
|
final allowBiometricalAuthentication =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ?? false;
|
|
|
|
final totpSecretKey = sharedPreferences.getString(PreferencesKey.totpSecretKey) ?? '';
|
|
|
|
final useTOTP2FA = sharedPreferences.getBool(PreferencesKey.useTOTP2FA) ?? false;
|
|
|
|
final tokenTrialNumber = sharedPreferences.getInt(PreferencesKey.failedTotpTokenTrials) ?? 0;
|
2023-04-16 13:45:35 +00:00
|
|
|
final shouldShowMarketPlaceInDashboard =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.shouldShowMarketPlaceInDashboard) ?? true;
|
2023-03-01 21:44:15 +00:00
|
|
|
final exchangeStatus = ExchangeApiMode.deserialize(
|
2023-05-17 14:43:23 +00:00
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.exchangeStatusKey) ??
|
|
|
|
ExchangeApiMode.enabled.raw);
|
|
|
|
final legacyTheme = (sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy) ?? false)
|
|
|
|
? ThemeType.dark.index
|
|
|
|
: ThemeType.bright.index;
|
|
|
|
final savedTheme = initialTheme ??
|
|
|
|
ThemeList.deserialize(
|
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.currentTheme) ?? legacyTheme);
|
2020-07-06 20:09:03 +00:00
|
|
|
final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
|
|
|
|
actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
|
2023-05-17 14:43:23 +00:00
|
|
|
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ?? defaultActionsMode));
|
2020-11-09 23:14:47 +00:00
|
|
|
var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
|
2023-05-17 14:43:23 +00:00
|
|
|
final timeOutDuration = sharedPreferences.getInt(PreferencesKey.pinTimeOutDuration);
|
2022-12-13 15:19:31 +00:00
|
|
|
final pinCodeTimeOutDuration = timeOutDuration != null
|
|
|
|
? PinCodeRequiredDuration.deserialize(raw: timeOutDuration)
|
|
|
|
: defaultPinCodeTimeOutDuration;
|
2023-04-20 09:59:59 +00:00
|
|
|
|
2020-11-09 23:14:47 +00:00
|
|
|
// If no value
|
|
|
|
if (pinLength == null || pinLength == 0) {
|
|
|
|
pinLength = defaultPinLength;
|
|
|
|
}
|
|
|
|
|
2023-05-17 14:43:23 +00:00
|
|
|
final savedLanguageCode = sharedPreferences.getString(PreferencesKey.currentLanguageCode) ??
|
|
|
|
await LanguageService.localeDetection();
|
2020-09-21 11:50:26 +00:00
|
|
|
final nodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
|
2023-05-17 14:43:23 +00:00
|
|
|
final bitcoinElectrumServerId =
|
|
|
|
sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
|
|
|
|
final litecoinElectrumServerId =
|
|
|
|
sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
|
|
|
|
final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey);
|
2020-08-27 16:54:34 +00:00
|
|
|
final moneroNode = nodeSource.get(nodeId);
|
|
|
|
final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId);
|
2021-05-07 07:36:38 +00:00
|
|
|
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
|
2022-03-30 15:57:04 +00:00
|
|
|
final havenNode = nodeSource.get(havenNodeId);
|
2020-07-06 20:09:03 +00:00
|
|
|
final packageInfo = await PackageInfo.fromPlatform();
|
2023-05-17 14:43:23 +00:00
|
|
|
final deviceName = await _getDeviceName() ?? '';
|
|
|
|
final shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
final nodes = <WalletType, Node>{};
|
|
|
|
|
|
|
|
if (moneroNode != null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
nodes[WalletType.monero] = moneroNode;
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bitcoinElectrumServer != null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
nodes[WalletType.bitcoin] = bitcoinElectrumServer;
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (litecoinElectrumServer != null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
nodes[WalletType.litecoin] = litecoinElectrumServer;
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (havenNode != null) {
|
2023-05-17 14:43:23 +00:00
|
|
|
nodes[WalletType.haven] = havenNode;
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
2022-12-08 15:23:17 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
return SettingsStore(
|
|
|
|
sharedPreferences: sharedPreferences,
|
2023-04-16 13:45:35 +00:00
|
|
|
initialShouldShowMarketPlaceInDashboard: shouldShowMarketPlaceInDashboard,
|
2022-10-12 17:09:57 +00:00
|
|
|
nodes: nodes,
|
2020-07-06 20:09:03 +00:00
|
|
|
appVersion: packageInfo.version,
|
2023-05-17 14:43:23 +00:00
|
|
|
deviceName: deviceName,
|
2021-03-16 13:20:46 +00:00
|
|
|
isBitcoinBuyEnabled: isBitcoinBuyEnabled,
|
2020-07-06 20:09:03 +00:00
|
|
|
initialFiatCurrency: currentFiatCurrency,
|
|
|
|
initialBalanceDisplayMode: currentBalanceDisplayMode,
|
|
|
|
initialSaveRecipientAddress: shouldSaveRecipientAddress,
|
2023-04-20 09:59:59 +00:00
|
|
|
initialAppSecure: isAppSecure,
|
2023-05-15 12:26:56 +00:00
|
|
|
initialDisableBuy: disableBuy,
|
|
|
|
initialDisableSell: disableSell,
|
2022-12-06 23:38:36 +00:00
|
|
|
initialFiatMode: currentFiatApiMode,
|
2020-07-06 20:09:03 +00:00
|
|
|
initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
|
2023-05-17 14:43:23 +00:00
|
|
|
initialTotpSecretKey: totpSecretKey,
|
|
|
|
initialUseTOTP2FA: useTOTP2FA,
|
|
|
|
initialFailedTokenTrial: tokenTrialNumber,
|
2023-02-06 19:20:43 +00:00
|
|
|
initialExchangeStatus: exchangeStatus,
|
2020-12-10 17:53:40 +00:00
|
|
|
initialTheme: savedTheme,
|
2020-07-06 20:09:03 +00:00
|
|
|
actionlistDisplayMode: actionListDisplayMode,
|
2020-09-21 11:50:26 +00:00
|
|
|
initialPinLength: pinLength,
|
2022-11-22 20:52:28 +00:00
|
|
|
pinTimeOutDuration: pinCodeTimeOutDuration,
|
2021-01-27 13:51:51 +00:00
|
|
|
initialLanguageCode: savedLanguageCode,
|
|
|
|
initialMoneroTransactionPriority: moneroTransactionPriority,
|
2021-10-04 13:03:35 +00:00
|
|
|
initialBitcoinTransactionPriority: bitcoinTransactionPriority,
|
2022-12-08 15:23:17 +00:00
|
|
|
initialHavenTransactionPriority: havenTransactionPriority,
|
|
|
|
initialLitecoinTransactionPriority: litecoinTransactionPriority,
|
2021-10-04 13:03:35 +00:00
|
|
|
shouldShowYatPopup: shouldShowYatPopup);
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2022-12-09 13:57:45 +00:00
|
|
|
Future<void> reload({required Box<Node> nodeSource}) async {
|
|
|
|
final sharedPreferences = await getIt.getAsync<SharedPreferences>();
|
|
|
|
|
|
|
|
fiatCurrency = FiatCurrency.deserialize(
|
|
|
|
raw: sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey)!);
|
|
|
|
|
|
|
|
priority[WalletType.monero] = monero?.deserializeMoneroTransactionPriority(
|
2023-05-17 14:43:23 +00:00
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
|
2022-12-09 13:57:45 +00:00
|
|
|
priority[WalletType.monero]!;
|
|
|
|
priority[WalletType.bitcoin] = bitcoin?.deserializeBitcoinTransactionPriority(
|
2023-05-17 14:43:23 +00:00
|
|
|
sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
|
2022-12-09 13:57:45 +00:00
|
|
|
priority[WalletType.bitcoin]!;
|
2022-12-09 18:36:51 +00:00
|
|
|
|
|
|
|
if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
|
|
|
|
priority[WalletType.haven] = monero?.deserializeMoneroTransactionPriority(
|
2023-05-17 14:43:23 +00:00
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!) ??
|
2022-12-09 18:36:51 +00:00
|
|
|
priority[WalletType.haven]!;
|
|
|
|
}
|
|
|
|
if (sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority) != null) {
|
|
|
|
priority[WalletType.litecoin] = bitcoin?.deserializeLitecoinTransactionPriority(
|
2023-05-17 14:43:23 +00:00
|
|
|
sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!) ??
|
2022-12-09 18:36:51 +00:00
|
|
|
priority[WalletType.litecoin]!;
|
|
|
|
}
|
2022-12-09 13:57:45 +00:00
|
|
|
|
|
|
|
balanceDisplayMode = BalanceDisplayMode.deserialize(
|
2023-05-17 14:43:23 +00:00
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
|
2022-12-09 13:57:45 +00:00
|
|
|
shouldSaveRecipientAddress =
|
2023-05-17 14:43:23 +00:00
|
|
|
sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ??
|
|
|
|
shouldSaveRecipientAddress;
|
|
|
|
totpSecretKey = sharedPreferences.getString(PreferencesKey.totpSecretKey) ?? totpSecretKey;
|
|
|
|
useTOTP2FA = sharedPreferences.getBool(PreferencesKey.useTOTP2FA) ?? useTOTP2FA;
|
|
|
|
numberOfFailedTokenTrials =
|
|
|
|
sharedPreferences.getInt(PreferencesKey.failedTotpTokenTrials) ?? numberOfFailedTokenTrials;
|
2022-12-09 13:57:45 +00:00
|
|
|
sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? shouldSaveRecipientAddress;
|
2023-04-20 09:59:59 +00:00
|
|
|
isAppSecure =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.isAppSecureKey) ?? isAppSecure;
|
2023-05-15 12:26:56 +00:00
|
|
|
disableBuy =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.disableBuyKey) ?? disableBuy;
|
|
|
|
disableSell =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.disableSellKey) ?? disableSell;
|
2022-12-09 13:57:45 +00:00
|
|
|
allowBiometricalAuthentication = sharedPreferences
|
|
|
|
.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
|
|
|
|
allowBiometricalAuthentication;
|
2023-04-16 13:45:35 +00:00
|
|
|
shouldShowMarketPlaceInDashboard =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.shouldShowMarketPlaceInDashboard) ??
|
|
|
|
shouldShowMarketPlaceInDashboard;
|
2023-03-01 21:44:15 +00:00
|
|
|
exchangeStatus = ExchangeApiMode.deserialize(
|
2023-05-17 14:43:23 +00:00
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.exchangeStatusKey) ??
|
|
|
|
ExchangeApiMode.enabled.raw);
|
|
|
|
final legacyTheme = (sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy) ?? false)
|
|
|
|
? ThemeType.dark.index
|
|
|
|
: ThemeType.bright.index;
|
2022-12-09 13:57:45 +00:00
|
|
|
currentTheme = ThemeList.deserialize(
|
2023-05-17 14:43:23 +00:00
|
|
|
raw: sharedPreferences.getInt(PreferencesKey.currentTheme) ?? legacyTheme);
|
2022-12-09 13:57:45 +00:00
|
|
|
actionlistDisplayMode = ObservableList<ActionListDisplayMode>();
|
|
|
|
actionlistDisplayMode.addAll(deserializeActionlistDisplayModes(
|
2023-05-17 14:43:23 +00:00
|
|
|
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ?? defaultActionsMode));
|
2022-12-09 13:57:45 +00:00
|
|
|
var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
|
|
|
|
// If no value
|
|
|
|
if (pinLength == null || pinLength == 0) {
|
|
|
|
pinLength = pinCodeLength;
|
2022-12-07 14:41:04 +00:00
|
|
|
}
|
2022-12-09 13:57:45 +00:00
|
|
|
pinCodeLength = pinLength;
|
2022-12-07 14:41:04 +00:00
|
|
|
|
2022-12-09 13:57:45 +00:00
|
|
|
languageCode = sharedPreferences.getString(PreferencesKey.currentLanguageCode) ?? languageCode;
|
2023-05-17 14:43:23 +00:00
|
|
|
shouldShowYatPopup =
|
|
|
|
sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? shouldShowYatPopup;
|
2022-12-09 13:57:45 +00:00
|
|
|
|
|
|
|
final nodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
|
2023-05-17 14:43:23 +00:00
|
|
|
final bitcoinElectrumServerId =
|
|
|
|
sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
|
|
|
|
final litecoinElectrumServerId =
|
|
|
|
sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
|
|
|
|
final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey);
|
2022-12-09 13:57:45 +00:00
|
|
|
final moneroNode = nodeSource.get(nodeId);
|
|
|
|
final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId);
|
|
|
|
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
|
|
|
|
final havenNode = nodeSource.get(havenNodeId);
|
|
|
|
|
|
|
|
if (moneroNode != null) {
|
|
|
|
nodes[WalletType.monero] = moneroNode;
|
2022-12-07 14:41:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-09 13:57:45 +00:00
|
|
|
if (bitcoinElectrumServer != null) {
|
|
|
|
nodes[WalletType.bitcoin] = bitcoinElectrumServer;
|
|
|
|
}
|
2022-12-07 14:41:04 +00:00
|
|
|
|
2022-12-09 13:57:45 +00:00
|
|
|
if (litecoinElectrumServer != null) {
|
|
|
|
nodes[WalletType.litecoin] = litecoinElectrumServer;
|
|
|
|
}
|
2022-12-07 14:41:04 +00:00
|
|
|
|
2022-12-09 13:57:45 +00:00
|
|
|
if (havenNode != null) {
|
|
|
|
nodes[WalletType.haven] = havenNode;
|
|
|
|
}
|
2022-12-07 14:41:04 +00:00
|
|
|
}
|
2021-01-15 17:41:30 +00:00
|
|
|
|
2020-09-26 19:17:31 +00:00
|
|
|
Future<void> _saveCurrentNode(Node node, WalletType walletType) async {
|
2020-09-21 11:50:26 +00:00
|
|
|
switch (walletType) {
|
|
|
|
case WalletType.bitcoin:
|
|
|
|
await _sharedPreferences.setInt(
|
|
|
|
PreferencesKey.currentBitcoinElectrumSererIdKey, node.key as int);
|
|
|
|
break;
|
2021-05-07 07:36:38 +00:00
|
|
|
case WalletType.litecoin:
|
|
|
|
await _sharedPreferences.setInt(
|
|
|
|
PreferencesKey.currentLitecoinElectrumSererIdKey, node.key as int);
|
|
|
|
break;
|
2020-09-21 11:50:26 +00:00
|
|
|
case WalletType.monero:
|
2023-05-17 14:43:23 +00:00
|
|
|
await _sharedPreferences.setInt(PreferencesKey.currentNodeIdKey, node.key as int);
|
2020-09-21 11:50:26 +00:00
|
|
|
break;
|
2022-06-20 14:18:25 +00:00
|
|
|
case WalletType.haven:
|
2023-05-17 14:43:23 +00:00
|
|
|
await _sharedPreferences.setInt(PreferencesKey.currentHavenNodeIdKey, node.key as int);
|
2022-06-20 14:18:25 +00:00
|
|
|
break;
|
2020-09-21 11:50:26 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes[walletType] = node;
|
|
|
|
}
|
2023-05-17 14:43:23 +00:00
|
|
|
|
|
|
|
static Future<String?> _getDeviceName() async {
|
|
|
|
String? deviceName = '';
|
|
|
|
final deviceInfoPlugin = DeviceInfoPlugin();
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
final androidInfo = await deviceInfoPlugin.androidInfo;
|
|
|
|
deviceName = '${androidInfo.brand}%20${androidInfo.manufacturer}%20${androidInfo.model}';
|
|
|
|
print(deviceName);
|
|
|
|
} else if (Platform.isIOS) {
|
|
|
|
final iosInfo = await deviceInfoPlugin.iosInfo;
|
|
|
|
deviceName = iosInfo.model;
|
|
|
|
} else if (Platform.isLinux) {
|
|
|
|
final linuxInfo = await deviceInfoPlugin.linuxInfo;
|
|
|
|
deviceName = linuxInfo.prettyName;
|
|
|
|
} else if (Platform.isMacOS) {
|
|
|
|
final macInfo = await deviceInfoPlugin.macOsInfo;
|
|
|
|
deviceName = macInfo.computerName;
|
|
|
|
} else if (Platform.isWindows) {
|
|
|
|
final windowsInfo = await deviceInfoPlugin.windowsInfo;
|
|
|
|
deviceName = windowsInfo.productName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceName;
|
|
|
|
}
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|