2022-12-05 19:14:46 +00:00
|
|
|
import 'package:cake_wallet/core/auth_service.dart';
|
2022-11-23 17:06:41 +00:00
|
|
|
import 'package:cake_wallet/entities/biometric_auth.dart';
|
2022-12-05 19:14:46 +00:00
|
|
|
import 'package:cake_wallet/entities/pin_code_required_duration.dart';
|
2022-11-23 17:06:41 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
|
|
|
|
part 'security_settings_view_model.g.dart';
|
|
|
|
|
2022-12-01 19:21:51 +00:00
|
|
|
class SecuritySettingsViewModel = SecuritySettingsViewModelBase with _$SecuritySettingsViewModel;
|
2022-11-23 17:06:41 +00:00
|
|
|
|
|
|
|
abstract class SecuritySettingsViewModelBase with Store {
|
2022-12-05 19:14:46 +00:00
|
|
|
SecuritySettingsViewModelBase(
|
|
|
|
this._settingsStore,
|
|
|
|
this._authService,
|
|
|
|
) : _biometricAuth = BiometricAuth();
|
2022-11-23 17:06:41 +00:00
|
|
|
|
|
|
|
final BiometricAuth _biometricAuth;
|
|
|
|
final SettingsStore _settingsStore;
|
2022-12-05 19:14:46 +00:00
|
|
|
final AuthService _authService;
|
2022-12-01 19:21:51 +00:00
|
|
|
|
2022-11-23 17:06:41 +00:00
|
|
|
@computed
|
2022-12-01 19:21:51 +00:00
|
|
|
bool get allowBiometricalAuthentication => _settingsStore.allowBiometricalAuthentication;
|
2022-11-23 17:06:41 +00:00
|
|
|
|
2022-12-05 19:14:46 +00:00
|
|
|
@computed
|
|
|
|
PinCodeRequiredDuration get pinCodeRequiredDuration => _settingsStore.pinTimeOutDuration;
|
|
|
|
|
2022-11-23 17:06:41 +00:00
|
|
|
@action
|
2022-12-01 19:21:51 +00:00
|
|
|
Future<bool> biometricAuthenticated() async {
|
|
|
|
return await _biometricAuth.canCheckBiometrics() && await _biometricAuth.isAuthenticated();
|
2022-11-23 17:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2022-12-05 19:14:46 +00:00
|
|
|
void setAllowBiometricalAuthentication(bool value) =>
|
|
|
|
_settingsStore.allowBiometricalAuthentication = value;
|
|
|
|
|
|
|
|
@action
|
|
|
|
setPinCodeRequiredDuration(PinCodeRequiredDuration duration) =>
|
|
|
|
_settingsStore.pinTimeOutDuration = duration;
|
|
|
|
|
|
|
|
bool checkPinCodeRiquired() => _authService.requireAuth();
|
2022-12-01 19:21:51 +00:00
|
|
|
}
|