General changes. CAKE-1.

This commit is contained in:
M
2020-07-06 23:09:03 +03:00
160 changed files with 5492 additions and 4033 deletions
+18 -1
View File
@@ -1,16 +1,33 @@
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/store/wallet_list_store.dart';
import 'package:cake_wallet/store/authentication_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/store/node_list_store.dart';
import 'package:cake_wallet/store/contact_list_store.dart';
part 'app_store.g.dart';
class AppStore = AppStoreBase with _$AppStore;
abstract class AppStoreBase with Store {
AppStoreBase({this.authenticationStore});
AppStoreBase(
{this.authenticationStore,
this.walletList,
this.settingsStore,
this.contactListStore,
this.nodeListStore});
AuthenticationStore authenticationStore;
@observable
WalletBase wallet;
WalletListStore walletList;
SettingsStore settingsStore;
ContactListStore contactListStore;
NodeListStore nodeListStore;
}
+12
View File
@@ -0,0 +1,12 @@
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/src/domain/common/contact.dart';
part 'contact_list_store.g.dart';
class ContactListStore = ContactListStoreBase with _$ContactListStore;
abstract class ContactListStoreBase with Store {
ContactListStoreBase() : contacts = ObservableList<Contact>();
final ObservableList<Contact> contacts;
}
+17
View File
@@ -0,0 +1,17 @@
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/src/domain/common/node.dart';
part 'node_list_store.g.dart';
class NodeListStore = NodeListStoreBase with _$NodeListStore;
abstract class NodeListStoreBase with Store {
NodeListStoreBase() : nodes = ObservableList<Node>();
final ObservableList<Node> nodes;
void replaceValues(Iterable<Node> newNodes) {
nodes.clear();
nodes.addAll(newNodes);
}
}
+154
View File
@@ -0,0 +1,154 @@
import 'package:cake_wallet/di.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:devicelocale/devicelocale.dart';
import 'package:package_info/package_info.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/src/domain/common/language.dart';
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
import 'package:cake_wallet/src/domain/common/node.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
import 'package:cake_wallet/src/stores/action_list/action_list_display_mode.dart';
part 'settings_store.g.dart';
class SettingsStore = SettingsStoreBase with _$SettingsStore;
abstract class SettingsStoreBase with Store {
SettingsStoreBase(
{@required SharedPreferences sharedPreferences,
@required Box<Node> nodeSource,
@required FiatCurrency initialFiatCurrency,
@required TransactionPriority initialTransactionPriority,
@required BalanceDisplayMode initialBalanceDisplayMode,
@required bool initialSaveRecipientAddress,
@required bool initialAllowBiometricalAuthentication,
@required bool initialDarkTheme,
@required int initialPinLength,
@required String initialLanguageCode,
@required String initialCurrentLocale,
@required this.node,
@required this.appVersion,
this.actionlistDisplayMode}) {
fiatCurrency = initialFiatCurrency;
transactionPriority = initialTransactionPriority;
balanceDisplayMode = initialBalanceDisplayMode;
shouldSaveRecipientAddress = initialSaveRecipientAddress;
allowBiometricalAuthentication = initialAllowBiometricalAuthentication;
isDarkTheme = initialDarkTheme;
defaultPinLength = initialPinLength;
languageCode = initialLanguageCode;
currentLocale = initialCurrentLocale;
itemHeaders = {};
// actionlistDisplayMode.observe(
// (dynamic _) => _sharedPreferences.setInt(displayActionListModeKey,
// serializeActionlistDisplayModes(actionlistDisplayMode)),
// fireImmediately: false);
_sharedPreferences = sharedPreferences;
_nodeSource = nodeSource;
}
static const currentNodeIdKey = 'current_node_id';
static const currentFiatCurrencyKey = 'current_fiat_currency';
static const currentTransactionPriorityKey = 'current_fee_priority';
static const currentBalanceDisplayModeKey = 'current_balance_display_mode';
static const shouldSaveRecipientAddressKey = 'save_recipient_address';
static const allowBiometricalAuthenticationKey =
'allow_biometrical_authentication';
static const currentDarkTheme = 'dark_theme';
static const displayActionListModeKey = 'display_list_mode';
static const currentPinLength = 'current_pin_length';
static const currentLanguageCode = 'language_code';
@observable
Node node;
@observable
FiatCurrency fiatCurrency;
@observable
ObservableList<ActionListDisplayMode> actionlistDisplayMode;
@observable
TransactionPriority transactionPriority;
@observable
BalanceDisplayMode balanceDisplayMode;
@observable
bool shouldSaveRecipientAddress;
@observable
bool allowBiometricalAuthentication;
@observable
bool isDarkTheme;
@observable
int defaultPinLength;
@observable
Map<String, String> itemHeaders;
String languageCode;
String currentLocale;
String appVersion;
SharedPreferences _sharedPreferences;
Box<Node> _nodeSource;
static Future<SettingsStore> load(
{@required Box<Node> nodeSource,
FiatCurrency initialFiatCurrency = FiatCurrency.usd,
TransactionPriority initialTransactionPriority = TransactionPriority.slow,
BalanceDisplayMode initialBalanceDisplayMode =
BalanceDisplayMode.availableBalance}) async {
final sharedPreferences = await getIt.getAsync<SharedPreferences>();
final currentFiatCurrency = FiatCurrency(
symbol: sharedPreferences.getString(currentFiatCurrencyKey));
final currentTransactionPriority = TransactionPriority.deserialize(
raw: sharedPreferences.getInt(currentTransactionPriorityKey));
final currentBalanceDisplayMode = BalanceDisplayMode.deserialize(
raw: sharedPreferences.getInt(currentBalanceDisplayModeKey));
final shouldSaveRecipientAddress =
sharedPreferences.getBool(shouldSaveRecipientAddressKey);
final allowBiometricalAuthentication =
sharedPreferences.getBool(allowBiometricalAuthenticationKey) ?? false;
final savedDarkTheme = sharedPreferences.getBool(currentDarkTheme) ?? false;
final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
sharedPreferences.getInt(displayActionListModeKey) ??
11)); // FIXME: Unnamed constant.
final defaultPinLength = sharedPreferences.getInt(currentPinLength) ??
4; // FIXME: Unnamed constant.
final savedLanguageCode =
sharedPreferences.getString(currentLanguageCode) ??
await Language.localeDetection();
final initialCurrentLocale = await Devicelocale.currentLocale;
final nodeId = sharedPreferences.getInt(currentNodeIdKey);
final node = nodeSource.get(nodeId);
final packageInfo = await PackageInfo.fromPlatform();
return SettingsStore(
sharedPreferences: sharedPreferences,
node: node,
nodeSource: nodeSource,
appVersion: packageInfo.version,
initialFiatCurrency: currentFiatCurrency,
initialTransactionPriority: currentTransactionPriority,
initialBalanceDisplayMode: currentBalanceDisplayMode,
initialSaveRecipientAddress: shouldSaveRecipientAddress,
initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
initialDarkTheme: savedDarkTheme,
actionlistDisplayMode: actionListDisplayMode,
initialPinLength: defaultPinLength,
initialLanguageCode: savedLanguageCode,
initialCurrentLocale: initialCurrentLocale);
}
}
+4 -1
View File
@@ -1,10 +1,13 @@
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/src/domain/common/wallet_description.dart';
part 'wallet_list_store.g.dart';
class WalletListStore = WalletListStoreBase with _$WalletListStore;
abstract class WalletListStoreBase with Store {
WalletListStoreBase() : wallets = ObservableList<WalletDescription>();
@observable
Object state;
ObservableList<WalletDescription> wallets;
}