diff --git a/lib/core/auth_service.dart b/lib/core/auth_service.dart index c493cddcb..569db5700 100644 --- a/lib/core/auth_service.dart +++ b/lib/core/auth_service.dart @@ -21,8 +21,7 @@ class AuthService with Store { Future canAuthenticate() async { final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword); - final walletName = - sharedPreferences.getString(PreferencesKey.currentWalletName) ?? ''; + final walletName = sharedPreferences.getString(PreferencesKey.currentWalletName) ?? ''; var password = ''; try { @@ -43,26 +42,23 @@ class AuthService with Store { } void saveLastAuthTime() { - int timestamp = DateTime.now().millisecondsSinceEpoch; sharedPreferences.setInt(PreferencesKey.lastAuthTimeMilliseconds, timestamp); } - bool requireAuth() { - + bool requireAuth() { final timestamp = sharedPreferences.getInt(PreferencesKey.lastAuthTimeMilliseconds); - final duration = _durationToRequireAuth(timestamp ?? 0); + final duration = _durationToRequireAuth(timestamp ?? 0); final requiredPinInterval = getIt.get().pinTimeOutDuration; - + return duration >= requiredPinInterval.value; } int _durationToRequireAuth(int timestamp) { - DateTime before = DateTime.fromMillisecondsSinceEpoch(timestamp); DateTime now = DateTime.now(); Duration timeDifference = now.difference(before); - return timeDifference.inMinutes; + return timeDifference.inMinutes; } } diff --git a/lib/view_model/auth_view_model.dart b/lib/view_model/auth_view_model.dart index d45873230..e50f4db0c 100644 --- a/lib/view_model/auth_view_model.dart +++ b/lib/view_model/auth_view_model.dart @@ -14,12 +14,12 @@ part 'auth_view_model.g.dart'; class AuthViewModel = AuthViewModelBase with _$AuthViewModel; abstract class AuthViewModelBase with Store { - AuthViewModelBase(this._authService, this._sharedPreferences, - this._settingsStore, this._biometricAuth) + AuthViewModelBase( + this._authService, this._sharedPreferences, this._settingsStore, this._biometricAuth) : _failureCounter = 0, - state = InitialExecutionState(){ - reaction((_) => state, _saveLastAuthTime); - } + state = InitialExecutionState() { + reaction((_) => state, _saveLastAuthTime); + } static const maxFailedLogins = 3; static const banTimeout = 180; // 3 minutes @@ -30,8 +30,7 @@ abstract class AuthViewModelBase with Store { int get pinLength => _settingsStore.pinCodeLength; - bool get isBiometricalAuthenticationAllowed => - _settingsStore.allowBiometricalAuthentication; + bool get isBiometricalAuthenticationAllowed => _settingsStore.allowBiometricalAuthentication; @observable int _failureCounter; @@ -59,7 +58,7 @@ abstract class AuthViewModelBase with Store { if (isSuccessfulAuthenticated) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - state = ExecutedSuccessfullyState(); + state = ExecutedSuccessfullyState(); _failureCounter = 0; }); } else { @@ -116,14 +115,14 @@ abstract class AuthViewModelBase with Store { state = ExecutedSuccessfullyState(); } } - } catch(e) { + } catch (e) { state = FailureState(e.toString()); } } void _saveLastAuthTime(ExecutionState state) { - if(state is ExecutedSuccessfullyState) { - _authService.saveLastAuthTime(); + if (state is ExecutedSuccessfullyState) { + _authService.saveLastAuthTime(); } } }