| 1 | import 'package:cake_wallet/core/auth_service.dart'; |
| 2 | import 'package:cake_wallet/entities/biometric_auth.dart'; |
| 3 | import 'package:cake_wallet/entities/pin_code_required_duration.dart'; |
| 4 | import 'package:cake_wallet/store/settings_store.dart'; |
| 5 | import 'package:mobx/mobx.dart'; |
| 6 | |
| 7 | part 'security_settings_view_model.g.dart'; |
| 8 | |
| 9 | class SecuritySettingsViewModel = SecuritySettingsViewModelBase with _$SecuritySettingsViewModel; |
| 10 | |
| 11 | abstract class SecuritySettingsViewModelBase with Store { |
| 12 | SecuritySettingsViewModelBase(this._settingsStore, this._authService) |
| 13 | : _biometricAuth = BiometricAuth(); |
| 14 | |
| 15 | final BiometricAuth _biometricAuth; |
| 16 | final SettingsStore _settingsStore; |
| 17 | final AuthService _authService; |
| 18 | |
| 19 | @computed |
| 20 | bool get isAppSecure => _settingsStore.isAppSecure; |
| 21 | |
| 22 | @computed |
| 23 | bool get allowBiometricalAuthentication => _settingsStore.allowBiometricalAuthentication; |
| 24 | |
| 25 | @computed |
| 26 | bool get enableDuressPin => _settingsStore.enableDuressPin; |
| 27 | |
| 28 | @computed |
| 29 | bool get useTotp2FA => _settingsStore.useTOTP2FA; |
| 30 | |
| 31 | @computed |
| 32 | bool get shouldRequireTOTP2FAForAllSecurityAndBackupSettings => |
| 33 | _settingsStore.shouldRequireTOTP2FAForAllSecurityAndBackupSettings; |
| 34 | |
| 35 | @computed |
| 36 | PinCodeRequiredDuration get pinCodeRequiredDuration => _settingsStore.pinTimeOutDuration; |
| 37 | |
| 38 | @action |
| 39 | Future<bool> biometricAuthenticated() async { |
| 40 | return await _biometricAuth.canCheckBiometrics() && await _biometricAuth.isAuthenticated(); |
| 41 | } |
| 42 | |
| 43 | @action |
| 44 | void setIsAppSecure(bool value) => _settingsStore.isAppSecure = value; |
| 45 | |
| 46 | @action |
| 47 | void setAllowBiometricalAuthentication(bool value) => |
| 48 | _settingsStore.allowBiometricalAuthentication = value; |
| 49 | |
| 50 | @action |
| 51 | void setPinCodeRequiredDuration(PinCodeRequiredDuration duration) => |
| 52 | _settingsStore.pinTimeOutDuration = duration; |
| 53 | |
| 54 | @action |
| 55 | void setEnableDuressPin(bool value) => _settingsStore.enableDuressPin = value; |
| 56 | |
| 57 | Future<void> clearDuressPin() async => await _authService.clearDuressPin(); |
| 58 | } |