2023-03-30 22:33:59 +00:00
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cw_core/wallet_type.dart';
|
|
|
|
import 'package:cake_wallet/core/execution_state.dart';
|
|
|
|
import 'package:cake_wallet/view_model/wallet_unlock_view_model.dart';
|
|
|
|
|
|
|
|
part 'wallet_unlock_verifiable_view_model.g.dart';
|
|
|
|
|
2023-07-14 20:28:01 +00:00
|
|
|
class WalletUnlockVerifiableViewModel = WalletUnlockVerifiableViewModelBase
|
|
|
|
with _$WalletUnlockVerifiableViewModel;
|
2023-03-30 22:33:59 +00:00
|
|
|
|
2023-07-14 20:28:01 +00:00
|
|
|
abstract class WalletUnlockVerifiableViewModelBase extends WalletUnlockViewModel
|
|
|
|
with Store {
|
|
|
|
WalletUnlockVerifiableViewModelBase(this.appStore,
|
|
|
|
{required this.walletName, required this.walletType})
|
|
|
|
: password = '',
|
|
|
|
state = InitialExecutionState();
|
2023-03-30 22:33:59 +00:00
|
|
|
|
|
|
|
final String walletName;
|
|
|
|
|
|
|
|
final WalletType walletType;
|
|
|
|
|
|
|
|
final AppStore appStore;
|
|
|
|
|
|
|
|
@override
|
|
|
|
@observable
|
|
|
|
String password;
|
|
|
|
|
|
|
|
@override
|
|
|
|
@observable
|
|
|
|
ExecutionState state;
|
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
void setPassword(String password) => this.password = password;
|
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
Future<void> unlock() async {
|
2023-07-14 20:28:01 +00:00
|
|
|
try {
|
|
|
|
state = appStore.wallet!.password == password
|
|
|
|
? ExecutedSuccessfullyState()
|
|
|
|
: FailureState(S.current.invalid_password);
|
|
|
|
} catch (e) {
|
|
|
|
failure('${S.current.invalid_password}\n${e.toString()}');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
void success() {
|
|
|
|
state = ExecutedSuccessfullyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
void failure(e) {
|
|
|
|
state = FailureState(e.toString());
|
2023-03-30 22:33:59 +00:00
|
|
|
}
|
|
|
|
}
|