mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-19 05:58:50 +02:00
CWA-164 | added biometric authentication
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
class BiometricAuth {
|
||||
|
||||
Future<bool> isAuthenticated() async {
|
||||
final LocalAuthentication _localAuth = LocalAuthentication();
|
||||
|
||||
try {
|
||||
return await _localAuth.authenticateWithBiometrics(
|
||||
localizedReason: S.current.biometric_auth_reason,
|
||||
useErrorDialogs: true,
|
||||
stickyAuth: false
|
||||
);
|
||||
} on PlatformException
|
||||
catch(e) {
|
||||
print(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/stores/auth/auth_state.dart';
|
||||
import 'package:cake_wallet/src/stores/auth/auth_store.dart';
|
||||
import 'package:cake_wallet/src/screens/pin_code/pin_code.dart';
|
||||
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
|
||||
import 'package:cake_wallet/src/domain/common/biometric_auth.dart';
|
||||
|
||||
typedef OnAuthenticationFinished = void Function(bool, AuthPageState);
|
||||
|
||||
@@ -33,6 +35,26 @@ class AuthPageState extends State<AuthPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authStore = Provider.of<AuthStore>(context);
|
||||
final settingsStore = Provider.of<SettingsStore>(context);
|
||||
|
||||
if (settingsStore.allowBiometricalAuthentication) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final biometricAuth = BiometricAuth();
|
||||
biometricAuth.isAuthenticated().then(
|
||||
(isAuth) {
|
||||
if (isAuth) {
|
||||
authStore.biometricAuth();
|
||||
_key.currentState.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(S.of(context).authenticated),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
reaction((_) => authStore.state, (AuthState state) {
|
||||
if (state is AuthenticatedSuccessfully) {
|
||||
|
||||
@@ -91,4 +91,9 @@ abstract class AuthStoreBase with Store {
|
||||
|
||||
return Duration(milliseconds: timeout);
|
||||
}
|
||||
|
||||
@action
|
||||
void biometricAuth() {
|
||||
state = AuthenticatedSuccessfully();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user