mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-22 10:34:17 +01:00
Part 1
This commit is contained in:
@@ -1,18 +1,6 @@
|
||||
abstract class AuthState {}
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
|
||||
class AuthenticationStateInitial extends AuthState {}
|
||||
|
||||
class AuthenticationInProgress extends AuthState {}
|
||||
|
||||
class AuthenticatedSuccessfully extends AuthState {}
|
||||
|
||||
class AuthenticationFailure extends AuthState {
|
||||
AuthenticationFailure({this.error});
|
||||
|
||||
final String error;
|
||||
}
|
||||
|
||||
class AuthenticationBanned extends AuthState {
|
||||
class AuthenticationBanned extends ExecutionState {
|
||||
AuthenticationBanned({this.error});
|
||||
|
||||
final String error;
|
||||
|
||||
@@ -1,38 +1,47 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/view_model/auth_state.dart';
|
||||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/entities/biometric_auth.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
|
||||
part 'auth_view_model.g.dart';
|
||||
|
||||
class AuthViewModel = AuthViewModelBase with _$AuthViewModel;
|
||||
|
||||
abstract class AuthViewModelBase with Store {
|
||||
AuthViewModelBase(
|
||||
{@required this.authService, @required this.sharedPreferences}) {
|
||||
state = AuthenticationStateInitial();
|
||||
AuthViewModelBase(this._authService, this._sharedPreferences,
|
||||
this._settingsStore, this._biometricAuth) {
|
||||
state = InitialExecutionState();
|
||||
_failureCounter = 0;
|
||||
}
|
||||
|
||||
static const maxFailedLogins = 3;
|
||||
static const banTimeout = 180; // 3 mins
|
||||
static const banTimeout = 180; // 3 minutes
|
||||
final banTimeoutKey = S.current.auth_store_ban_timeout;
|
||||
|
||||
final AuthService authService;
|
||||
final SharedPreferences sharedPreferences;
|
||||
|
||||
@observable
|
||||
AuthState state;
|
||||
ExecutionState state;
|
||||
|
||||
int get pinLength => _settingsStore.pinCodeLength;
|
||||
|
||||
bool get isBiometricalAuthenticationAllowed =>
|
||||
_settingsStore.allowBiometricalAuthentication;
|
||||
|
||||
@observable
|
||||
int _failureCounter;
|
||||
|
||||
final AuthService _authService;
|
||||
final BiometricAuth _biometricAuth;
|
||||
final SharedPreferences _sharedPreferences;
|
||||
final SettingsStore _settingsStore;
|
||||
|
||||
@action
|
||||
Future<void> auth({String password}) async {
|
||||
state = AuthenticationStateInitial();
|
||||
state = InitialExecutionState();
|
||||
final _banDuration = banDuration();
|
||||
|
||||
if (_banDuration != null) {
|
||||
@@ -43,11 +52,11 @@ abstract class AuthViewModelBase with Store {
|
||||
return;
|
||||
}
|
||||
|
||||
state = AuthenticationInProgress();
|
||||
final isAuth = await authService.authenticate(password);
|
||||
state = IsExecutingState();
|
||||
final isSuccessfulAuthenticated = await _authService.authenticate(password);
|
||||
|
||||
if (isAuth) {
|
||||
state = AuthenticatedSuccessfully();
|
||||
if (isSuccessfulAuthenticated) {
|
||||
state = ExecutedSuccessfullyState();
|
||||
_failureCounter = 0;
|
||||
} else {
|
||||
_failureCounter += 1;
|
||||
@@ -61,13 +70,12 @@ abstract class AuthViewModelBase with Store {
|
||||
return;
|
||||
}
|
||||
|
||||
state =
|
||||
AuthenticationFailure(error: S.current.auth_store_incorrect_password);
|
||||
state = FailureState(S.current.auth_store_incorrect_password);
|
||||
}
|
||||
}
|
||||
|
||||
Duration banDuration() {
|
||||
final unbanTimestamp = sharedPreferences.getInt(banTimeoutKey);
|
||||
final unbanTimestamp = _sharedPreferences.getInt(banTimeoutKey);
|
||||
|
||||
if (unbanTimestamp == null) {
|
||||
return null;
|
||||
@@ -87,11 +95,25 @@ abstract class AuthViewModelBase with Store {
|
||||
final multiplier = _failureCounter - maxFailedLogins + 1;
|
||||
final timeout = (multiplier * banTimeout) * 1000;
|
||||
final unbanTimestamp = DateTime.now().millisecondsSinceEpoch + timeout;
|
||||
await sharedPreferences.setInt(banTimeoutKey, unbanTimestamp);
|
||||
await _sharedPreferences.setInt(banTimeoutKey, unbanTimestamp);
|
||||
|
||||
return Duration(milliseconds: timeout);
|
||||
}
|
||||
|
||||
@action
|
||||
void biometricAuth() => state = AuthenticatedSuccessfully();
|
||||
Future<void> biometricAuth() async {
|
||||
try {
|
||||
final canBiometricAuth = await _biometricAuth.canCheckBiometrics();
|
||||
|
||||
if (canBiometricAuth) {
|
||||
final isAuthenticated = await _biometricAuth.isAuthenticated();
|
||||
|
||||
if (isAuthenticated) {
|
||||
state = ExecutedSuccessfullyState();
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/contact_service.dart';
|
||||
import 'package:cake_wallet/store/contact_list_store.dart';
|
||||
import 'package:cake_wallet/src/domain/common/contact.dart';
|
||||
import 'package:cake_wallet/entities/contact.dart';
|
||||
import 'package:cake_wallet/utils/mobx.dart';
|
||||
|
||||
part 'contact_list_view_model.g.dart';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/contact_service.dart';
|
||||
import 'package:cake_wallet/src/domain/common/contact.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/view_model/contact_list/contact_view_model_state.dart';
|
||||
import 'package:cake_wallet/entities/contact.dart';
|
||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||
|
||||
part 'contact_view_model.g.dart';
|
||||
|
||||
@@ -12,7 +12,7 @@ class ContactViewModel = ContactViewModelBase with _$ContactViewModel;
|
||||
|
||||
abstract class ContactViewModelBase with Store {
|
||||
ContactViewModelBase(this._contacts, this._wallet, {Contact contact})
|
||||
: state = InitialContactViewModelState(),
|
||||
: state = InitialExecutionState(),
|
||||
currencies = CryptoCurrency.all,
|
||||
_contact = contact {
|
||||
name = _contact?.name;
|
||||
@@ -21,7 +21,7 @@ abstract class ContactViewModelBase with Store {
|
||||
}
|
||||
|
||||
@observable
|
||||
ContactViewModelState state;
|
||||
ExecutionState state;
|
||||
|
||||
@observable
|
||||
String name;
|
||||
@@ -39,7 +39,6 @@ abstract class ContactViewModelBase with Store {
|
||||
(address?.isNotEmpty ?? false);
|
||||
|
||||
final List<CryptoCurrency> currencies;
|
||||
// final ContactService _contactService;
|
||||
final WalletBase _wallet;
|
||||
final Box<Contact> _contacts;
|
||||
final Contact _contact;
|
||||
@@ -48,30 +47,26 @@ abstract class ContactViewModelBase with Store {
|
||||
void reset() {
|
||||
address = '';
|
||||
name = '';
|
||||
//currency = _wallet.currency;
|
||||
currency = null;
|
||||
}
|
||||
|
||||
Future save() async {
|
||||
try {
|
||||
state = ContactIsCreating();
|
||||
state = IsExecutingState();
|
||||
|
||||
if (_contact != null) {
|
||||
_contact.name = name;
|
||||
_contact.address = address;
|
||||
_contact.updateCryptoCurrency(currency: currency);
|
||||
await _contacts.put(_contact.key, _contact);
|
||||
// await _contactService.update(_contact);
|
||||
} else {
|
||||
await _contacts
|
||||
.add(Contact(name: name, address: address, type: currency));
|
||||
// await _contactService
|
||||
// .add(Contact(name: name, address: address, type: currency));
|
||||
}
|
||||
|
||||
state = ContactSavingSuccessfully();
|
||||
state = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
state = ContactCreationFailure(e.toString());
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
abstract class ContactViewModelState {}
|
||||
|
||||
class InitialContactViewModelState extends ContactViewModelState {}
|
||||
|
||||
class ContactIsCreating extends ContactViewModelState {}
|
||||
|
||||
class ContactSavingSuccessfully extends ContactViewModelState {}
|
||||
|
||||
class ContactCreationFailure extends ContactViewModelState {
|
||||
ContactCreationFailure(this.error);
|
||||
|
||||
final String error;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/src/domain/common/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/wallet_balance.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
@@ -22,7 +22,7 @@ abstract class BalanceViewModelBase with Store {
|
||||
|
||||
final WalletBase wallet;
|
||||
final SettingsStore settingsStore;
|
||||
final FiatConvertationStore fiatConvertationStore;
|
||||
final FiatConversionStore fiatConvertationStore;
|
||||
|
||||
WalletBalance _getWalletBalance() {
|
||||
final _wallet = wallet;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/transaction_direction.dart';
|
||||
import 'package:cake_wallet/src/domain/common/transaction_info.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade.dart';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||
import 'package:cake_wallet/entities/transaction_direction.dart';
|
||||
import 'package:cake_wallet/entities/transaction_info.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/filter_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
|
||||
@@ -15,8 +15,8 @@ import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/action_list_display_mode.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/common/sync_status.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/sync_status.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:cake_wallet/src/domain/exchange/trade.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
||||
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
|
||||
class TradeListItem extends ActionListItem {
|
||||
TradeListItem({this.trade, this.displayMode});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
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/transaction_info.dart';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/entities/transaction_info.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
|
||||
import 'package:cake_wallet/src/domain/monero/monero_transaction_info.dart';
|
||||
import 'package:cake_wallet/src/domain/monero/monero_amount_format.dart';
|
||||
import 'package:cake_wallet/monero/monero_transaction_info.dart';
|
||||
import 'package:cake_wallet/monero/monero_amount_format.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
|
||||
import 'package:cake_wallet/src/domain/common/calculate_fiat_amount_raw.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
||||
|
||||
class TransactionListItem extends ActionListItem {
|
||||
TransactionListItem({
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/changenow/changenow_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/changenow/changenow_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/exchange/morphtoken/morphtoken_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/exchange/xmrto/xmrto_exchange_provider.dart';
|
||||
import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/limits.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade.dart';
|
||||
import 'package:cake_wallet/src/stores/exchange/limits_state.dart';
|
||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/limits.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/exchange/limits_state.dart';
|
||||
import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:cake_wallet/src/stores/exchange/exchange_trade_state.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/changenow/changenow_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/changenow/changenow_request.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_trade_request.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_exchange_provider.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_request.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_trade_state.dart';
|
||||
import 'package:cake_wallet/exchange/changenow/changenow_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/changenow/changenow_request.dart';
|
||||
import 'package:cake_wallet/exchange/trade_request.dart';
|
||||
import 'package:cake_wallet/exchange/xmrto/xmrto_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/xmrto/xmrto_trade_request.dart';
|
||||
import 'package:cake_wallet/exchange/morphtoken/morphtoken_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/morphtoken/morphtoken_request.dart';
|
||||
import 'package:cake_wallet/store/templates/exchange_template_store.dart';
|
||||
import 'package:cake_wallet/src/domain/exchange/exchange_template.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_template.dart';
|
||||
|
||||
part 'exchange_view_model.g.dart';
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
abstract class MoneroAccountEditOrCreateState {}
|
||||
|
||||
class InitialAccountCreationState extends MoneroAccountEditOrCreateState {}
|
||||
|
||||
class AccountIsCreating extends MoneroAccountEditOrCreateState {}
|
||||
|
||||
class AccountCreatedSuccessfully extends MoneroAccountEditOrCreateState {}
|
||||
|
||||
class AccountCreationFailure extends MoneroAccountEditOrCreateState {
|
||||
AccountCreationFailure({@required this.error});
|
||||
|
||||
final String error;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/monero/monero_account_list.dart';
|
||||
import 'package:cake_wallet/view_model/monero_account_list/account_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/monero_account_list/monero_account_edit_or_create_state.dart';
|
||||
|
||||
part 'monero_account_edit_or_create_view_model.g.dart';
|
||||
|
||||
@@ -11,14 +11,14 @@ class MoneroAccountEditOrCreateViewModel = MoneroAccountEditOrCreateViewModelBas
|
||||
abstract class MoneroAccountEditOrCreateViewModelBase with Store {
|
||||
MoneroAccountEditOrCreateViewModelBase(this._moneroAccountList,
|
||||
{AccountListItem accountListItem})
|
||||
: state = InitialAccountCreationState(),
|
||||
: state = InitialExecutionState(),
|
||||
isEdit = accountListItem != null,
|
||||
_accountListItem = accountListItem;
|
||||
|
||||
final bool isEdit;
|
||||
|
||||
@observable
|
||||
MoneroAccountEditOrCreateState state;
|
||||
ExecutionState state;
|
||||
|
||||
@observable
|
||||
String label;
|
||||
@@ -28,7 +28,7 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
|
||||
|
||||
Future<void> save() async {
|
||||
try {
|
||||
state = AccountIsCreating();
|
||||
state = IsExecutingState();
|
||||
|
||||
if (_accountListItem != null) {
|
||||
await _moneroAccountList.setLabelAccount(
|
||||
@@ -37,9 +37,9 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
|
||||
await _moneroAccountList.addAccount(label: label);
|
||||
}
|
||||
|
||||
state = AccountCreatedSuccessfully();
|
||||
state = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
state = AccountCreationFailure(error: e.toString());
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/src/domain/monero/account.dart';
|
||||
import 'package:cake_wallet/monero/account.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/view_model/monero_account_list/account_list_item.dart';
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/common/node.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model_state.dart';
|
||||
import 'package:cake_wallet/entities/node.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
|
||||
part 'node_create_or_edit_view_model.g.dart';
|
||||
|
||||
@@ -12,10 +12,10 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
|
||||
|
||||
abstract class NodeCreateOrEditViewModelBase with Store {
|
||||
NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet)
|
||||
: state = InitialNodeCreateOrEditViewModelState();
|
||||
: state = InitialExecutionState();
|
||||
|
||||
@observable
|
||||
NodeCreateOrEditViewModelState state;
|
||||
ExecutionState state;
|
||||
|
||||
@observable
|
||||
String address;
|
||||
@@ -59,13 +59,13 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||
@action
|
||||
Future<void> save() async {
|
||||
try {
|
||||
state = NodeIsCreating();
|
||||
state = IsExecutingState();
|
||||
final node =
|
||||
Node(uri: uri, type: _wallet.type, login: login, password: password);
|
||||
await _nodeSource.add(node);
|
||||
state = NodeCreatedSuccessfully();
|
||||
state = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
state = NodeCreateOrEditViewModelFailure(e.toString());
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
abstract class NodeCreateOrEditViewModelState {}
|
||||
|
||||
class InitialNodeCreateOrEditViewModelState
|
||||
extends NodeCreateOrEditViewModelState {}
|
||||
|
||||
class NodeIsCreating extends NodeCreateOrEditViewModelState {}
|
||||
|
||||
class NodeCreatedSuccessfully extends NodeCreateOrEditViewModelState {}
|
||||
|
||||
class NodeCreateOrEditViewModelFailure extends NodeCreateOrEditViewModelState {
|
||||
NodeCreateOrEditViewModelFailure(this.error);
|
||||
|
||||
final String error;
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/common/node.dart';
|
||||
import 'package:cake_wallet/src/domain/common/node_list.dart';
|
||||
import 'package:cake_wallet/entities/node.dart';
|
||||
import 'package:cake_wallet/entities/node_list.dart';
|
||||
import 'package:cake_wallet/store/node_list_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/src/domain/common/default_settings_migration.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/default_settings_migration.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/utils/mobx.dart';
|
||||
import 'package:cake_wallet/utils/item_cell.dart';
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'rescan_view_model.g.dart';
|
||||
|
||||
class RescanViewModel = RescanViewModelBase with _$RescanViewModel;
|
||||
|
||||
enum RescanWalletState { rescaning, none }
|
||||
|
||||
abstract class RescanViewModelBase with Store {
|
||||
RescanViewModelBase(this._wallet) {
|
||||
state = RescanWalletState.none;
|
||||
}
|
||||
|
||||
@observable
|
||||
RescanWalletState state;
|
||||
final WalletBase _wallet;
|
||||
|
||||
@action
|
||||
Future<void> rescanCurrentWallet({int restoreHeight}) async {
|
||||
state = RescanWalletState.rescaning;
|
||||
await _wallet.rescan(height: restoreHeight);
|
||||
state = RescanWalletState.none;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,26 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/template_validator.dart';
|
||||
import 'package:cake_wallet/src/domain/common/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
|
||||
import 'package:cake_wallet/core/address_validator.dart';
|
||||
import 'package:cake_wallet/core/amount_validator.dart';
|
||||
import 'package:cake_wallet/core/pending_transaction.dart';
|
||||
import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/src/domain/common/sync_status.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
|
||||
import 'package:cake_wallet/monero/monero_transaction_creation_credentials.dart';
|
||||
import 'package:cake_wallet/entities/sync_status.dart';
|
||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
part 'send_view_model.g.dart';
|
||||
|
||||
@@ -26,13 +29,14 @@ class SendViewModel = SendViewModelBase with _$SendViewModel;
|
||||
abstract class SendViewModelBase with Store {
|
||||
SendViewModelBase(
|
||||
this._wallet, this._settingsStore, this._fiatConversationStore)
|
||||
: state = InitialSendViewModelState(),
|
||||
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12,
|
||||
// FIXME: need to be based on wallet type.
|
||||
sendAll = false;
|
||||
: state = InitialExecutionState(),
|
||||
_cryptoNumberFormat = NumberFormat(),
|
||||
sendAll = false {
|
||||
_setCryptoNumMaximumFractionDigits();
|
||||
}
|
||||
|
||||
@observable
|
||||
SendViewModelState state;
|
||||
ExecutionState state;
|
||||
|
||||
@observable
|
||||
String fiatAmount;
|
||||
@@ -82,7 +86,7 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
final WalletBase _wallet;
|
||||
final SettingsStore _settingsStore;
|
||||
final FiatConvertationStore _fiatConversationStore;
|
||||
final FiatConversionStore _fiatConversationStore;
|
||||
final NumberFormat _cryptoNumberFormat;
|
||||
|
||||
@action
|
||||
@@ -98,11 +102,11 @@ abstract class SendViewModelBase with Store {
|
||||
@action
|
||||
Future<void> createTransaction() async {
|
||||
try {
|
||||
state = TransactionIsCreating();
|
||||
state = IsExecutingState();
|
||||
pendingTransaction = await _wallet.createTransaction(_credentials());
|
||||
state = TransactionCreatedSuccessfully();
|
||||
state = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
state = SendingFailed(error: e.toString());
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,14 +117,13 @@ abstract class SendViewModelBase with Store {
|
||||
await pendingTransaction.commit();
|
||||
state = TransactionCommitted();
|
||||
} catch (e) {
|
||||
state = SendingFailed(error: e.toString());
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void setCryptoAmount(String amount) {
|
||||
// FIXME: hardcoded value.
|
||||
if (amount.toUpperCase() != 'ALL') {
|
||||
if (amount.toUpperCase() != S.current.all) {
|
||||
sendAll = false;
|
||||
}
|
||||
|
||||
@@ -164,19 +167,41 @@ abstract class SendViewModelBase with Store {
|
||||
}
|
||||
|
||||
Object _credentials() {
|
||||
final amount =
|
||||
!sendAll ? double.parse(cryptoAmount.replaceAll(',', '.')) : null;
|
||||
final _amount = cryptoAmount.replaceAll(',', '.');
|
||||
|
||||
switch (_wallet.type) {
|
||||
case WalletType.bitcoin:
|
||||
final amount = !sendAll ? double.parse(_amount) : null;
|
||||
|
||||
return BitcoinTransactionCredentials(
|
||||
address, amount, _settingsStore.transactionPriority);
|
||||
case WalletType.monero:
|
||||
// FIXME: Wrong credentials
|
||||
return BitcoinTransactionCredentials(
|
||||
address, amount, _settingsStore.transactionPriority);
|
||||
final amount = !sendAll ? _amount : null;
|
||||
|
||||
return MoneroTransactionCreationCredentials(
|
||||
address: address,
|
||||
paymentId: '',
|
||||
priority: _settingsStore.transactionPriority,
|
||||
amount: amount);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void _setCryptoNumMaximumFractionDigits() {
|
||||
var maximumFractionDigits = 0;
|
||||
|
||||
switch (_wallet.type) {
|
||||
case WalletType.monero:
|
||||
maximumFractionDigits = 12;
|
||||
break;
|
||||
case WalletType.bitcoin:
|
||||
maximumFractionDigits = 8;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_cryptoNumberFormat.maximumFractionDigits = maximumFractionDigits;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
|
||||
abstract class SendViewModelState {}
|
||||
|
||||
class InitialSendViewModelState extends SendViewModelState {}
|
||||
|
||||
class TransactionIsCreating extends SendViewModelState {}
|
||||
class TransactionCreatedSuccessfully extends SendViewModelState {}
|
||||
|
||||
class TransactionCommitting extends SendViewModelState {}
|
||||
|
||||
class TransactionCommitted extends SendViewModelState {}
|
||||
|
||||
class SendingFailed extends SendViewModelState {
|
||||
SendingFailed({@required this.error});
|
||||
|
||||
String error;
|
||||
}
|
||||
class TransactionCommitting extends ExecutionState {}
|
||||
class TransactionCommitted extends ExecutionState {}
|
||||
|
||||
@@ -1,216 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/address_validator.dart';
|
||||
import 'package:cake_wallet/core/amount_validator.dart';
|
||||
import 'package:cake_wallet/core/template_validator.dart';
|
||||
import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/src/domain/common/calculate_estimated_fee.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/sync_status.dart';
|
||||
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/store/templates/send_template_store.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/domain/common/openalias_record.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
|
||||
import 'package:cake_wallet/src/domain/common/template.dart';
|
||||
|
||||
part 'send_view_model.g.dart';
|
||||
|
||||
abstract class SendViewModelState {}
|
||||
|
||||
class InitialSendViewModelState extends SendViewModelState {}
|
||||
|
||||
class TransactionIsCreating extends SendViewModelState {}
|
||||
|
||||
class TransactionCreatedSuccessfully extends SendViewModelState {}
|
||||
|
||||
class TransactionCommitting extends SendViewModelState {}
|
||||
|
||||
class TransactionCommitted extends SendViewModelState {}
|
||||
|
||||
class SendingFailed extends SendViewModelState {
|
||||
SendingFailed({@required this.error});
|
||||
|
||||
String error;
|
||||
}
|
||||
|
||||
class SendViewModel = SendViewModelBase with _$SendViewModel;
|
||||
|
||||
abstract class SendViewModelBase with Store {
|
||||
SendViewModelBase(this._wallet, this._settingsStore,
|
||||
this._fiatConvertationStore, this.sendTemplateStore) {
|
||||
state = InitialSendViewModelState();
|
||||
|
||||
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12;
|
||||
_fiatNumberFormat = NumberFormat()..maximumFractionDigits = 2;
|
||||
}
|
||||
|
||||
NumberFormat _cryptoNumberFormat;
|
||||
NumberFormat _fiatNumberFormat;
|
||||
|
||||
@observable
|
||||
SendViewModelState state;
|
||||
|
||||
@observable
|
||||
String fiatAmount;
|
||||
|
||||
@observable
|
||||
String cryptoAmount;
|
||||
|
||||
@observable
|
||||
String address;
|
||||
|
||||
String get cryptoCurrencyTitle {
|
||||
var _currencyTitle = '';
|
||||
|
||||
if (_wallet is MoneroWallet) {
|
||||
_currencyTitle = 'Monero';
|
||||
}
|
||||
|
||||
if (_wallet is BitcoinWallet) {
|
||||
_currencyTitle = 'Bitcoin';
|
||||
}
|
||||
|
||||
return _currencyTitle;
|
||||
}
|
||||
|
||||
String get pageTitle => S.current.send_title + ' ' + cryptoCurrencyTitle;
|
||||
|
||||
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
||||
|
||||
TransactionPriority get transactionPriority =>
|
||||
_settingsStore.transactionPriority;
|
||||
|
||||
double get estimatedFee =>
|
||||
calculateEstimatedFee(priority: transactionPriority);
|
||||
|
||||
String get name => _wallet.name;
|
||||
|
||||
CryptoCurrency get currency => _wallet.currency;
|
||||
|
||||
Validator get amountValidator => AmountValidator(type: _wallet.type);
|
||||
|
||||
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
||||
|
||||
Validator get templateValidator => TemplateValidator();
|
||||
|
||||
@computed
|
||||
double get price => _fiatConvertationStore.price;
|
||||
|
||||
@computed
|
||||
ObservableList<Template> get templates =>
|
||||
ObservableList.of(sendTemplateStore.templates
|
||||
.where((item) => item.cryptoCurrency == _wallet.currency.title)
|
||||
.toList());
|
||||
|
||||
@computed
|
||||
String get balance {
|
||||
var _balance = '0.0';
|
||||
|
||||
if (_wallet is MoneroWallet) {
|
||||
_balance = _wallet.balance.formattedUnlockedBalance.toString();
|
||||
}
|
||||
|
||||
if (_wallet is BitcoinWallet) {
|
||||
_balance = _wallet.balance.confirmedFormatted.toString();
|
||||
}
|
||||
|
||||
return _settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance
|
||||
? '---'
|
||||
: _balance;
|
||||
}
|
||||
|
||||
@computed
|
||||
SyncStatus get status => _wallet.syncStatus;
|
||||
|
||||
@action
|
||||
void changeCryptoAmount(String amount) {
|
||||
cryptoAmount = amount;
|
||||
|
||||
if (cryptoAmount != null && cryptoAmount.isNotEmpty) {
|
||||
_calculateFiatAmount();
|
||||
} else {
|
||||
fiatAmount = '';
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void changeFiatAmount(String amount) {
|
||||
fiatAmount = amount;
|
||||
|
||||
if (fiatAmount != null && fiatAmount.isNotEmpty) {
|
||||
_calculateCryptoAmount();
|
||||
} else {
|
||||
cryptoAmount = '';
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future _calculateFiatAmount() async {
|
||||
try {
|
||||
final amount = double.parse(cryptoAmount) * price;
|
||||
fiatAmount = _fiatNumberFormat.format(amount);
|
||||
} catch (e) {
|
||||
fiatAmount = '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future _calculateCryptoAmount() async {
|
||||
try {
|
||||
final amount = double.parse(fiatAmount) / price;
|
||||
cryptoAmount = _cryptoNumberFormat.format(amount);
|
||||
} catch (e) {
|
||||
cryptoAmount = '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void changeAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@action
|
||||
void setSendAll() {
|
||||
cryptoAmount = 'ALL';
|
||||
fiatAmount = '';
|
||||
}
|
||||
|
||||
@action
|
||||
void setTransactionPriority(TransactionPriority transactionPriority) {
|
||||
_settingsStore.transactionPriority = transactionPriority;
|
||||
}
|
||||
|
||||
final WalletBase _wallet;
|
||||
|
||||
final SettingsStore _settingsStore;
|
||||
|
||||
final FiatConvertationStore _fiatConvertationStore;
|
||||
|
||||
final SendTemplateStore sendTemplateStore;
|
||||
|
||||
String recordName;
|
||||
|
||||
String recordAddress;
|
||||
|
||||
Future<bool> isOpenaliasRecord(String name) async {
|
||||
final _openaliasRecord = await OpenaliasRecord.fetchAddressAndName(
|
||||
OpenaliasRecord.formatDomainName(name));
|
||||
|
||||
recordAddress = _openaliasRecord.address;
|
||||
recordName = _openaliasRecord.name;
|
||||
|
||||
return recordAddress != name;
|
||||
}
|
||||
|
||||
Future<void> createTransaction() async {}
|
||||
|
||||
Future<void> commitTransaction() async {}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/common/biometric_auth.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/biometric_auth.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:cake_wallet/store/theme_changer_store.dart';
|
||||
import 'package:cake_wallet/themes.dart';
|
||||
@@ -10,11 +10,11 @@ import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/store/settings_store.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';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/entities/node.dart';
|
||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||
import 'package:cake_wallet/entities/action_list_display_mode.dart';
|
||||
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||
import 'package:cake_wallet/view_model/settings/link_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/settings/picker_list_item.dart';
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
|
||||
class SetupPinCodeViewModel {
|
||||
SetupPinCodeViewModel(this._authService, this._settingsStore)
|
||||
: _pinCodeLength = _settingsStore.pinCodeLength;
|
||||
|
||||
String originalPinCode = '';
|
||||
|
||||
String repeatedPinCode = '';
|
||||
|
||||
set pinCode(String pinCode) {
|
||||
if (!isOriginalPinCodeFull) {
|
||||
setOriginalPinCode(pinCode);
|
||||
return;
|
||||
}
|
||||
|
||||
repeatedPinCode = pinCode;
|
||||
}
|
||||
|
||||
int get pinCodeLength => _pinCodeLength;
|
||||
|
||||
set pinCodeLength(int length) {
|
||||
_pinCodeLength = length;
|
||||
reset();
|
||||
}
|
||||
|
||||
bool get isOriginalPinCodeFull => originalPinCode.length == pinCodeLength;
|
||||
|
||||
bool get isRepeatedPinCodeFull => repeatedPinCode.length == pinCodeLength;
|
||||
|
||||
bool get isPinCodeCorrect =>
|
||||
originalPinCode.length == pinCodeLength &&
|
||||
repeatedPinCode.length == pinCodeLength &&
|
||||
originalPinCode == repeatedPinCode;
|
||||
|
||||
final SettingsStore _settingsStore;
|
||||
final AuthService _authService;
|
||||
int _pinCodeLength;
|
||||
|
||||
void setOriginalPinCode(String pinCode) {
|
||||
if (isOriginalPinCodeFull) {
|
||||
return;
|
||||
}
|
||||
|
||||
originalPinCode = pinCode;
|
||||
}
|
||||
|
||||
void setRepeatedPinCode(String pinCode) {
|
||||
if (isRepeatedPinCodeFull) {
|
||||
return;
|
||||
}
|
||||
|
||||
repeatedPinCode = pinCode;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
originalPinCode = '';
|
||||
repeatedPinCode = '';
|
||||
}
|
||||
|
||||
Future<void> setupPinCode() async {
|
||||
if (!isPinCodeCorrect) {
|
||||
return;
|
||||
}
|
||||
|
||||
await _authService.setPassword(repeatedPinCode);
|
||||
_settingsStore.pinCodeLength = pinCodeLength;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import 'package:cake_wallet/utils/list_item.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_address_list/wallet_account_list_header.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_header.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_item.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
|
||||
part 'wallet_address_list_view_model.g.dart';
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
abstract class WalletCreationState {}
|
||||
|
||||
class InitialWalletCreationState extends WalletCreationState {}
|
||||
|
||||
class WalletCreating extends WalletCreationState {}
|
||||
|
||||
class WalletCreatedSuccessfully extends WalletCreationState {}
|
||||
|
||||
class WalletCreationFailure extends WalletCreationState {
|
||||
WalletCreationFailure({@required this.error});
|
||||
|
||||
final String error;
|
||||
}
|
||||
@@ -1,20 +1,22 @@
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/wallet_credentials.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_creation_state.dart';
|
||||
import 'package:cake_wallet/entities/pathForWallet.dart';
|
||||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
|
||||
part 'wallet_creation_vm.g.dart';
|
||||
|
||||
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
|
||||
|
||||
abstract class WalletCreationVMBase with Store {
|
||||
WalletCreationVMBase(this._walletInfoSource,
|
||||
WalletCreationVMBase(this._appStore, this._walletInfoSource,
|
||||
{@required this.type, @required this.isRecovery}) {
|
||||
state = InitialWalletCreationState();
|
||||
state = InitialExecutionState();
|
||||
name = '';
|
||||
}
|
||||
|
||||
@@ -22,17 +24,18 @@ abstract class WalletCreationVMBase with Store {
|
||||
String name;
|
||||
|
||||
@observable
|
||||
WalletCreationState state;
|
||||
ExecutionState state;
|
||||
|
||||
final WalletType type;
|
||||
|
||||
final bool isRecovery;
|
||||
|
||||
final Box<WalletInfo> _walletInfoSource;
|
||||
final AppStore _appStore;
|
||||
|
||||
Future<void> create({dynamic options}) async {
|
||||
try {
|
||||
state = WalletCreating();
|
||||
state = IsExecutingState();
|
||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
||||
final path = await pathForWallet(name: name, type: type);
|
||||
final credentials = getCredentials(options);
|
||||
final walletInfo = WalletInfo.external(
|
||||
id: WalletBase.idFor(name, type),
|
||||
@@ -40,19 +43,23 @@ abstract class WalletCreationVMBase with Store {
|
||||
type: type,
|
||||
isRecovery: isRecovery,
|
||||
restoreHeight: credentials.height ?? 0,
|
||||
date: DateTime.now());
|
||||
date: DateTime.now(),
|
||||
path: path,
|
||||
dirPath: dirPath);
|
||||
credentials.walletInfo = walletInfo;
|
||||
await process(credentials);
|
||||
final wallet = await process(credentials);
|
||||
await _walletInfoSource.add(walletInfo);
|
||||
state = WalletCreatedSuccessfully();
|
||||
_appStore.wallet = wallet;
|
||||
_appStore.authenticationStore.allowed();
|
||||
state = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
state = WalletCreationFailure(error: e.toString());
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
WalletCredentials getCredentials(dynamic options) =>
|
||||
throw UnimplementedError();
|
||||
|
||||
Future<void> process(WalletCredentials credentials) =>
|
||||
Future<WalletBase> process(WalletCredentials credentials) =>
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
|
||||
class WalletListItem {
|
||||
const WalletListItem(
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/core/key_service.dart';
|
||||
import 'package:cake_wallet/core/wallet_service.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
|
||||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
|
||||
part 'wallet_list_view_model.g.dart';
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@ import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet_service.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet_creation_credentials.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
||||
import 'package:cake_wallet/core/wallet_credentials.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
|
||||
|
||||
part 'wallet_new_vm.g.dart';
|
||||
@@ -14,9 +16,11 @@ part 'wallet_new_vm.g.dart';
|
||||
class WalletNewVM = WalletNewVMBase with _$WalletNewVM;
|
||||
|
||||
abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
||||
WalletNewVMBase(this._walletCreationService, Box<WalletInfo> walletInfoSource, {@required WalletType type})
|
||||
WalletNewVMBase(AppStore appStore, this._walletCreationService,
|
||||
Box<WalletInfo> walletInfoSource,
|
||||
{@required WalletType type})
|
||||
: selectedMnemonicLanguage = '',
|
||||
super(walletInfoSource, type: type, isRecovery: false);
|
||||
super(appStore, walletInfoSource, type: type, isRecovery: false);
|
||||
|
||||
@observable
|
||||
String selectedMnemonicLanguage;
|
||||
@@ -39,6 +43,6 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> process(WalletCredentials credentials) async =>
|
||||
Future<WalletBase> process(WalletCredentials credentials) async =>
|
||||
_walletCreationService.create(credentials);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@ import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet_service.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet_creation_credentials.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/generate_wallet_password.dart';
|
||||
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
||||
import 'package:cake_wallet/core/wallet_credentials.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
|
||||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
|
||||
part 'wallet_restoration_from_keys_vm.g.dart';
|
||||
|
||||
@@ -17,9 +19,10 @@ class WalletRestorationFromKeysVM = WalletRestorationFromKeysVMBase
|
||||
|
||||
abstract class WalletRestorationFromKeysVMBase extends WalletCreationVM
|
||||
with Store {
|
||||
WalletRestorationFromKeysVMBase(this._walletCreationService, Box<WalletInfo> walletInfoSource,
|
||||
WalletRestorationFromKeysVMBase(AppStore appStore,
|
||||
this._walletCreationService, Box<WalletInfo> walletInfoSource,
|
||||
{@required WalletType type, @required this.language})
|
||||
: super(walletInfoSource, type: type, isRecovery: true);
|
||||
: super(appStore, walletInfoSource, type: type, isRecovery: true);
|
||||
|
||||
@observable
|
||||
int height;
|
||||
@@ -48,17 +51,22 @@ abstract class WalletRestorationFromKeysVMBase extends WalletCreationVM
|
||||
switch (type) {
|
||||
case WalletType.monero:
|
||||
return MoneroRestoreWalletFromKeysCredentials(
|
||||
name: name, password: password, language: language, address: address,
|
||||
viewKey: viewKey, spendKey: spendKey, height: height);
|
||||
name: name,
|
||||
password: password,
|
||||
language: language,
|
||||
address: address,
|
||||
viewKey: viewKey,
|
||||
spendKey: spendKey,
|
||||
height: height);
|
||||
case WalletType.bitcoin:
|
||||
return BitcoinRestoreWalletFromWIFCredentials(
|
||||
name: name, password: password, wif: wif);
|
||||
name: name, password: password, wif: wif);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> process(WalletCredentials credentials) async =>
|
||||
Future<WalletBase> process(WalletCredentials credentials) async =>
|
||||
_walletCreationService.restoreFromKeys(credentials);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet_service.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet_creation_credentials.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/generate_wallet_password.dart';
|
||||
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
||||
import 'package:cake_wallet/core/wallet_credentials.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
|
||||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
|
||||
part 'wallet_restoration_from_seed_vm.g.dart';
|
||||
|
||||
@@ -17,9 +19,10 @@ class WalletRestorationFromSeedVM = WalletRestorationFromSeedVMBase
|
||||
|
||||
abstract class WalletRestorationFromSeedVMBase extends WalletCreationVM
|
||||
with Store {
|
||||
WalletRestorationFromSeedVMBase(this._walletCreationService, Box<WalletInfo> walletInfoSource,
|
||||
WalletRestorationFromSeedVMBase(AppStore appStore,
|
||||
this._walletCreationService, Box<WalletInfo> walletInfoSource,
|
||||
{@required WalletType type, @required this.language, this.seed})
|
||||
: super(walletInfoSource, type: type, isRecovery: true);
|
||||
: super(appStore, walletInfoSource, type: type, isRecovery: true);
|
||||
|
||||
@observable
|
||||
String seed;
|
||||
@@ -49,6 +52,6 @@ abstract class WalletRestorationFromSeedVMBase extends WalletCreationVM
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> process(WalletCredentials credentials) async =>
|
||||
Future<WalletBase> process(WalletCredentials credentials) async =>
|
||||
_walletCreationService.restoreFromSeed(credentials);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user