Fix formatting

Godwin Asuquo committed Dec 9, 2022 at 20:18 UTC 6836ac6d1ac2374b4586b7ac3bd643909ed14fbe
2 files changed +15 -20
lib/core/auth_service.dart
+5 -9
@@ -21,8 +21,7 @@ class AuthService with Store {
21
22 Future<bool> canAuthenticate() async {
23 final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
24 - final walletName =
25 - sharedPreferences.getString(PreferencesKey.currentWalletName) ?? '';
24 + final walletName = sharedPreferences.getString(PreferencesKey.currentWalletName) ?? '';
25 var password = '';
26
27 try {
@@ -43,26 +42,23 @@ class AuthService with Store {
42 }
43
44 void saveLastAuthTime() {
46 -
45 int timestamp = DateTime.now().millisecondsSinceEpoch;
46 sharedPreferences.setInt(PreferencesKey.lastAuthTimeMilliseconds, timestamp);
47 }
48
51 - bool requireAuth() {
52 -
49 + bool requireAuth() {
50 final timestamp = sharedPreferences.getInt(PreferencesKey.lastAuthTimeMilliseconds);
54 - final duration = _durationToRequireAuth(timestamp ?? 0);
51 + final duration = _durationToRequireAuth(timestamp ?? 0);
52 final requiredPinInterval = getIt.get<SettingsStore>().pinTimeOutDuration;
56 -
53 +
54 return duration >= requiredPinInterval.value;
55 }
56
57 int _durationToRequireAuth(int timestamp) {
61 -
58 DateTime before = DateTime.fromMillisecondsSinceEpoch(timestamp);
59 DateTime now = DateTime.now();
60 Duration timeDifference = now.difference(before);
61
66 - return timeDifference.inMinutes;
62 + return timeDifference.inMinutes;
63 }
64 }
lib/view_model/auth_view_model.dart
+10 -11
@@ -14,12 +14,12 @@ part 'auth_view_model.g.dart';
14 class AuthViewModel = AuthViewModelBase with _$AuthViewModel;
15
16 abstract class AuthViewModelBase with Store {
17 - AuthViewModelBase(this._authService, this._sharedPreferences,
18 - this._settingsStore, this._biometricAuth)
17 + AuthViewModelBase(
18 + this._authService, this._sharedPreferences, this._settingsStore, this._biometricAuth)
19 : _failureCounter = 0,
20 - state = InitialExecutionState(){
21 - reaction((_) => state, _saveLastAuthTime);
22 - }
20 + state = InitialExecutionState() {
21 + reaction((_) => state, _saveLastAuthTime);
22 + }
23
24 static const maxFailedLogins = 3;
25 static const banTimeout = 180; // 3 minutes
@@ -30,8 +30,7 @@ abstract class AuthViewModelBase with Store {
30
31 int get pinLength => _settingsStore.pinCodeLength;
32
33 - bool get isBiometricalAuthenticationAllowed =>
34 - _settingsStore.allowBiometricalAuthentication;
33 + bool get isBiometricalAuthenticationAllowed => _settingsStore.allowBiometricalAuthentication;
34
35 @observable
36 int _failureCounter;
@@ -59,7 +58,7 @@ abstract class AuthViewModelBase with Store {
58
59 if (isSuccessfulAuthenticated) {
60 WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
62 - state = ExecutedSuccessfullyState();
61 + state = ExecutedSuccessfullyState();
62 _failureCounter = 0;
63 });
64 } else {
@@ -116,14 +115,14 @@ abstract class AuthViewModelBase with Store {
115 state = ExecutedSuccessfullyState();
116 }
117 }
119 - } catch(e) {
118 + } catch (e) {
119 state = FailureState(e.toString());
120 }
121 }
122
123 void _saveLastAuthTime(ExecutionState state) {
125 - if(state is ExecutedSuccessfullyState) {
126 - _authService.saveLastAuthTime();
124 + if (state is ExecutedSuccessfullyState) {
125 + _authService.saveLastAuthTime();
126 }
127 }
128 }