mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-25 08:39:06 +00:00
Fix formatting
This commit is contained in:
parent
f6c5f96929
commit
6836ac6d1a
2 changed files with 15 additions and 20 deletions
|
@ -21,8 +21,7 @@ class AuthService with Store {
|
||||||
|
|
||||||
Future<bool> canAuthenticate() async {
|
Future<bool> canAuthenticate() async {
|
||||||
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
|
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
|
||||||
final walletName =
|
final walletName = sharedPreferences.getString(PreferencesKey.currentWalletName) ?? '';
|
||||||
sharedPreferences.getString(PreferencesKey.currentWalletName) ?? '';
|
|
||||||
var password = '';
|
var password = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -43,26 +42,23 @@ class AuthService with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveLastAuthTime() {
|
void saveLastAuthTime() {
|
||||||
|
|
||||||
int timestamp = DateTime.now().millisecondsSinceEpoch;
|
int timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||||
sharedPreferences.setInt(PreferencesKey.lastAuthTimeMilliseconds, timestamp);
|
sharedPreferences.setInt(PreferencesKey.lastAuthTimeMilliseconds, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool requireAuth() {
|
bool requireAuth() {
|
||||||
|
|
||||||
final timestamp = sharedPreferences.getInt(PreferencesKey.lastAuthTimeMilliseconds);
|
final timestamp = sharedPreferences.getInt(PreferencesKey.lastAuthTimeMilliseconds);
|
||||||
final duration = _durationToRequireAuth(timestamp ?? 0);
|
final duration = _durationToRequireAuth(timestamp ?? 0);
|
||||||
final requiredPinInterval = getIt.get<SettingsStore>().pinTimeOutDuration;
|
final requiredPinInterval = getIt.get<SettingsStore>().pinTimeOutDuration;
|
||||||
|
|
||||||
return duration >= requiredPinInterval.value;
|
return duration >= requiredPinInterval.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _durationToRequireAuth(int timestamp) {
|
int _durationToRequireAuth(int timestamp) {
|
||||||
|
|
||||||
DateTime before = DateTime.fromMillisecondsSinceEpoch(timestamp);
|
DateTime before = DateTime.fromMillisecondsSinceEpoch(timestamp);
|
||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
Duration timeDifference = now.difference(before);
|
Duration timeDifference = now.difference(before);
|
||||||
|
|
||||||
return timeDifference.inMinutes;
|
return timeDifference.inMinutes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,12 @@ part 'auth_view_model.g.dart';
|
||||||
class AuthViewModel = AuthViewModelBase with _$AuthViewModel;
|
class AuthViewModel = AuthViewModelBase with _$AuthViewModel;
|
||||||
|
|
||||||
abstract class AuthViewModelBase with Store {
|
abstract class AuthViewModelBase with Store {
|
||||||
AuthViewModelBase(this._authService, this._sharedPreferences,
|
AuthViewModelBase(
|
||||||
this._settingsStore, this._biometricAuth)
|
this._authService, this._sharedPreferences, this._settingsStore, this._biometricAuth)
|
||||||
: _failureCounter = 0,
|
: _failureCounter = 0,
|
||||||
state = InitialExecutionState(){
|
state = InitialExecutionState() {
|
||||||
reaction((_) => state, _saveLastAuthTime);
|
reaction((_) => state, _saveLastAuthTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const maxFailedLogins = 3;
|
static const maxFailedLogins = 3;
|
||||||
static const banTimeout = 180; // 3 minutes
|
static const banTimeout = 180; // 3 minutes
|
||||||
|
@ -30,8 +30,7 @@ abstract class AuthViewModelBase with Store {
|
||||||
|
|
||||||
int get pinLength => _settingsStore.pinCodeLength;
|
int get pinLength => _settingsStore.pinCodeLength;
|
||||||
|
|
||||||
bool get isBiometricalAuthenticationAllowed =>
|
bool get isBiometricalAuthenticationAllowed => _settingsStore.allowBiometricalAuthentication;
|
||||||
_settingsStore.allowBiometricalAuthentication;
|
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
int _failureCounter;
|
int _failureCounter;
|
||||||
|
@ -59,7 +58,7 @@ abstract class AuthViewModelBase with Store {
|
||||||
|
|
||||||
if (isSuccessfulAuthenticated) {
|
if (isSuccessfulAuthenticated) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||||
state = ExecutedSuccessfullyState();
|
state = ExecutedSuccessfullyState();
|
||||||
_failureCounter = 0;
|
_failureCounter = 0;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,14 +115,14 @@ abstract class AuthViewModelBase with Store {
|
||||||
state = ExecutedSuccessfullyState();
|
state = ExecutedSuccessfullyState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
state = FailureState(e.toString());
|
state = FailureState(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _saveLastAuthTime(ExecutionState state) {
|
void _saveLastAuthTime(ExecutionState state) {
|
||||||
if(state is ExecutedSuccessfullyState) {
|
if (state is ExecutedSuccessfullyState) {
|
||||||
_authService.saveLastAuthTime();
|
_authService.saveLastAuthTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue