This commit is contained in:
M
2020-06-01 21:56:21 +03:00
298 changed files with 9437 additions and 5461 deletions
@@ -16,6 +16,7 @@ abstract class AcountListStoreBase with Store {
AcountListStoreBase({@required WalletService walletService}) {
accounts = [];
isAccountCreating = false;
isDisabledStatus = true;
if (walletService.currentWallet != null) {
_onWalletChanged(walletService.currentWallet);
@@ -37,10 +38,18 @@ abstract class AcountListStoreBase with Store {
@observable
bool isAccountCreating;
@observable
bool isDisabledStatus;
AccountList _accountList;
StreamSubscription<Wallet> _onWalletChangeSubscription;
StreamSubscription<List<Account>> _onAccountsChangeSubscription;
@action
void setDisabledStatus(bool isDisabled) {
isDisabledStatus = isDisabled;
}
// @override
// void dispose() {
// _onWalletChangeSubscription.cancel();
@@ -12,11 +12,15 @@ class AddressBookStore = AddressBookStoreBase with _$AddressBookStore;
abstract class AddressBookStoreBase with Store {
AddressBookStoreBase({@required this.contacts}) {
updateContactList();
isDisabledStatus = true;
}
@observable
List<Contact> contactList;
@observable
bool isDisabledStatus;
@observable
bool isValid;
@@ -37,6 +41,11 @@ abstract class AddressBookStoreBase with Store {
@action
Future delete({Contact contact}) async => await contact.delete();
@action
void setDisabledStatus(bool isDisabled) {
isDisabledStatus = isDisabled;
}
void validateContactName(String value) {
const pattern = '''^[^`,'"]{1,32}\$''';
final regExp = RegExp(pattern);
+29 -8
View File
@@ -33,6 +33,14 @@ abstract class ExchangeStoreBase with Store {
provider = initialProvider;
depositCurrency = initialDepositCurrency;
receiveCurrency = initialReceiveCurrency;
/*isDepositAddressEnabled = !(depositCurrency == walletStore.type);
isReceiveAddressEnabled = !(receiveCurrency == walletStore.type);*/
isDepositAddressEnabled = true;
isReceiveAddressEnabled = true;
depositAmount = '';
receiveAmount = '';
depositAddress = '';
receiveAddress = '';
limitsState = LimitsInitialState();
tradeState = ExchangeTradeStateInitial();
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12;
@@ -63,6 +71,18 @@ abstract class ExchangeStoreBase with Store {
@observable
String receiveAmount;
@observable
String depositAddress;
@observable
String receiveAddress;
@observable
bool isDepositAddressEnabled;
@observable
bool isReceiveAddressEnabled;
@observable
bool isValid;
@@ -71,10 +91,6 @@ abstract class ExchangeStoreBase with Store {
Box<Trade> trades;
String depositAddress;
String receiveAddress;
WalletStore walletStore;
Limits limits;
@@ -93,12 +109,16 @@ abstract class ExchangeStoreBase with Store {
void changeDepositCurrency({CryptoCurrency currency}) {
depositCurrency = currency;
_onPairChange();
/*isDepositAddressEnabled = !(depositCurrency == walletStore.type);
isReceiveAddressEnabled = !(receiveCurrency == walletStore.type);*/
}
@action
void changeReceiveCurrency({CryptoCurrency currency}) {
receiveCurrency = currency;
_onPairChange();
/*isDepositAddressEnabled = !(depositCurrency == walletStore.type);
isReceiveAddressEnabled = !(receiveCurrency == walletStore.type);*/
}
@action
@@ -218,12 +238,13 @@ abstract class ExchangeStoreBase with Store {
void reset() {
depositAmount = '';
receiveAmount = '';
depositAddress = '';
receiveAddress = '';
provider = XMRTOExchangeProvider();
depositCurrency = CryptoCurrency.xmr;
receiveCurrency = CryptoCurrency.btc;
loadLimits();
depositAddress = depositCurrency == walletStore.type ? walletStore.address : '';
receiveAddress = receiveCurrency == walletStore.type ? walletStore.address : '';
/*isDepositAddressEnabled = !(depositCurrency == walletStore.type);
isReceiveAddressEnabled = !(receiveCurrency == walletStore.type);*/
_onPairChange();
}
List<ExchangeProvider> providersForCurrentPair() {
@@ -0,0 +1,40 @@
import 'dart:async';
import 'package:mobx/mobx.dart';
import 'package:hive/hive.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_template.dart';
part 'exchange_template_store.g.dart';
class ExchangeTemplateStore = ExchangeTemplateBase with _$ExchangeTemplateStore;
abstract class ExchangeTemplateBase with Store {
ExchangeTemplateBase({this.templateSource}) {
templates = ObservableList<ExchangeTemplate>();
update();
}
@observable
ObservableList<ExchangeTemplate> templates;
Box<ExchangeTemplate> templateSource;
@action
void update() =>
templates.replaceRange(0, templates.length, templateSource.values.toList());
@action
Future addTemplate({String amount, String depositCurrency, String receiveCurrency,
String provider, String depositAddress, String receiveAddress}) async {
final template = ExchangeTemplate(
amount: amount,
depositCurrency: depositCurrency,
receiveCurrency: receiveCurrency,
provider: provider,
depositAddress: depositAddress,
receiveAddress: receiveAddress);
await templateSource.add(template);
}
@action
Future remove({ExchangeTemplate template}) async => await template.delete();
}
@@ -12,6 +12,7 @@ class NodeListStore = NodeListBase with _$NodeListStore;
abstract class NodeListBase with Store {
NodeListBase({this.nodesSource}) {
nodes = ObservableList<Node>();
disabledState = true;
_onNodesChangeSubscription = nodesSource.watch().listen((e) => update());
update();
}
@@ -25,6 +26,9 @@ abstract class NodeListBase with Store {
@observable
String errorMessage;
@observable
bool disabledState;
Box<Node> nodesSource;
StreamSubscription<BoxEvent> _onNodesChangeSubscription;
@@ -61,6 +65,11 @@ abstract class NodeListBase with Store {
@action
Future reset() async => await resetToDefault(nodesSource);
@action
void setDisabledState(bool isDisable) {
disabledState = isDisable;
}
Future<bool> isNodeOnline(Node node) async {
try {
return await node.requestNode(node.uri,
+15
View File
@@ -45,6 +45,9 @@ abstract class SendStoreBase with Store {
@observable
String cryptoAmount;
@observable
String address;
@observable
bool isValid;
@@ -157,6 +160,18 @@ abstract class SendStoreBase with Store {
}
}
@action
void changeAddress(String address) {
this.address = address;
}
@action
void clear() {
address = '';
cryptoAmount = '';
fiatAmount = '';
}
Future<bool> isOpenaliasRecord(String name) async {
final _openaliasRecord = await OpenaliasRecord
.fetchAddressAndName(OpenaliasRecord.formatDomainName(name));
@@ -0,0 +1,48 @@
import 'dart:async';
import 'package:mobx/mobx.dart';
import 'package:hive/hive.dart';
import 'package:cake_wallet/src/domain/common/template.dart';
import 'package:cake_wallet/generated/i18n.dart';
part 'send_template_store.g.dart';
class SendTemplateStore = SendTemplateBase with _$SendTemplateStore;
abstract class SendTemplateBase with Store {
SendTemplateBase({this.templateSource}) {
templates = ObservableList<Template>();
update();
}
@observable
ObservableList<Template> templates;
@observable
bool isValid;
@observable
String errorMessage;
Box<Template> templateSource;
@action
void update() =>
templates.replaceRange(0, templates.length, templateSource.values.toList());
@action
Future addTemplate({String name, String address, String cryptoCurrency, String amount}) async {
final template = Template(name: name, address: address,
cryptoCurrency: cryptoCurrency, amount: amount);
await templateSource.add(template);
}
@action
Future remove({Template template}) async => await template.delete();
void validateTemplate(String value) {
const pattern = '''^[^`,'"]{1,106}\$''';
final regExp = RegExp(pattern);
isValid = regExp.hasMatch(value);
errorMessage = isValid ? null : S.current.error_text_template;
}
}
@@ -17,6 +17,7 @@ class SubadrressCreationStore = SubadrressCreationStoreBase
abstract class SubadrressCreationStoreBase with Store {
SubadrressCreationStoreBase({@required WalletService walletService}) {
state = SubaddressCreationStateInitial();
isDisabledStatus = true;
if (walletService.currentWallet != null) {
_onWalletChanged(walletService.currentWallet);
@@ -26,6 +27,7 @@ abstract class SubadrressCreationStoreBase with Store {
walletService.onWalletChange.listen(_onWalletChanged);
}
@observable
SubaddressCreationState state;
@observable
@@ -34,11 +36,19 @@ abstract class SubadrressCreationStoreBase with Store {
@observable
String errorMessage;
@observable
bool isDisabledStatus;
SubaddressList _subaddressList;
StreamSubscription<Wallet> _onWalletChangeSubscription;
StreamSubscription<Account> _onAccountChangeSubscription;
Account _account;
@action
void setDisabledStatus(bool isDisabled) {
isDisabledStatus = isDisabled;
}
// @override
// void dispose() {
// _onWalletChangeSubscription.cancel();
@@ -61,6 +71,20 @@ abstract class SubadrressCreationStoreBase with Store {
}
}
Future<void> setLabel({int addressIndex, String label}) async {
try {
state = SubaddressIsCreating();
await _subaddressList.setLabelSubaddress(
accountIndex: _account.id,
addressIndex: addressIndex,
label: label
);
state = SubaddressCreatedSuccessfully();
} catch (e) {
state = SubaddressCreationFailure(error: e.toString());
}
}
Future<void> _onWalletChanged(Wallet wallet) async {
if (wallet is MoneroWallet) {
_account = wallet.account;
@@ -16,6 +16,7 @@ abstract class WalletCreationStoreBase with Store {
@required this.walletListService,
@required this.sharedPreferences}) {
state = WalletCreationStateInitial();
isDisabledStatus = true;
}
final AuthenticationStore authStore;
@@ -31,6 +32,9 @@ abstract class WalletCreationStoreBase with Store {
@observable
bool isValid;
@observable
bool isDisabledStatus;
@action
Future create({String name, String language}) async {
state = WalletCreationStateInitial();
@@ -45,6 +49,11 @@ abstract class WalletCreationStoreBase with Store {
}
}
@action
void setDisabledStatus(bool isDisabled) {
isDisabledStatus = isDisabled;
}
void validateWalletName(String value) {
const pattern = '^[a-zA-Z0-9_]{1,15}\$';
final regExp = RegExp(pattern);
@@ -20,6 +20,7 @@ abstract class WalleRestorationStoreBase with Store {
@required this.walletListService,
@required this.sharedPreferences}) {
state = WalletRestorationStateInitial();
disabledState = true;
}
final AuthenticationStore authStore;
@@ -38,6 +39,9 @@ abstract class WalleRestorationStoreBase with Store {
@observable
List<MnemoticItem> seed;
@observable
bool disabledState;
@action
Future restoreFromSeed({String name, String seed, int restoreHeight}) async {
state = WalletRestorationStateInitial();
@@ -109,6 +113,11 @@ abstract class WalleRestorationStoreBase with Store {
return seed.fold('', (acc, item) => acc + ' ' + item.toString());
}
@action
void setDisabledState(bool isDisable) {
disabledState = isDisable;
}
void validateWalletName(String value) {
const pattern = '^[a-zA-Z0-9_]{1,15}\$';
final regExp = RegExp(pattern);