CWA-164 | added biometric authentication

This commit is contained in:
Oleksandr Sobol
2020-01-21 19:51:37 +02:00
parent 59492a6634
commit 71bdfb3e5b
19 changed files with 116 additions and 13 deletions
+21
View File
@@ -38,6 +38,7 @@ class S implements WidgetsLocalizations {
String get authenticated => "Authenticated";
String get authentication => "Authentication";
String get available_balance => "Available Balance";
String get biometric_auth_reason => "Scan your fingerprint to authenticate";
String get cancel => "Cancel";
String get change => "Change";
String get change_currency => "Change Currency";
@@ -315,6 +316,8 @@ class $de extends S {
@override
String get hidden_balance => "Verstecktes Gleichgewicht";
@override
String get biometric_auth_reason => "Scannen Sie Ihren Fingerabdruck zur Authentifizierung";
@override
String get transaction_sent => "Transaktion gesendet!";
@override
String get password => "Passwort";
@@ -861,6 +864,8 @@ class $hi extends S {
@override
String get hidden_balance => "छिपा हुआ संतुलन";
@override
String get biometric_auth_reason => "प्रमाणित करने के लिए अपने फ़िंगरप्रिंट को स्कैन करें";
@override
String get transaction_sent => "भेजा गया लेन-देन";
@override
String get password => "पारण शब्द";
@@ -1407,6 +1412,8 @@ class $ru extends S {
@override
String get hidden_balance => "Скрытый баланс";
@override
String get biometric_auth_reason => "Отсканируйте свой отпечаток пальца для аутентификации";
@override
String get transaction_sent => "Tранзакция отправлена!";
@override
String get password => "Password";
@@ -1953,6 +1960,8 @@ class $ko extends S {
@override
String get hidden_balance => "숨겨진 균형";
@override
String get biometric_auth_reason => "지문을 스캔하여 인증";
@override
String get transaction_sent => "거래가 전송되었습니다!";
@override
String get password => "암호";
@@ -2499,6 +2508,8 @@ class $pt extends S {
@override
String get hidden_balance => "Saldo escondido";
@override
String get biometric_auth_reason => "Digitalize sua impressão digital para autenticar";
@override
String get transaction_sent => "Transação enviada!";
@override
String get password => "Senha";
@@ -3045,6 +3056,8 @@ class $ja extends S {
@override
String get hidden_balance => "隠れたバランス";
@override
String get biometric_auth_reason => "प指紋をスキャンして認証する";
@override
String get transaction_sent => "トランザクションが送信されました!";
@override
String get password => "パスワード";
@@ -3595,6 +3608,8 @@ class $pl extends S {
@override
String get hidden_balance => "Ukryta równowaga";
@override
String get biometric_auth_reason => "Zeskanuj swój odcisk palca, aby go uwierzytelnić";
@override
String get transaction_sent => "Transakcja wysłana!";
@override
String get password => "Hasło";
@@ -4141,6 +4156,8 @@ class $es extends S {
@override
String get hidden_balance => "Balance oculto";
@override
String get biometric_auth_reason => "Escanee su huella digital para autenticar";
@override
String get transaction_sent => "Transacción enviada!";
@override
String get password => "Contraseña";
@@ -4687,6 +4704,8 @@ class $nl extends S {
@override
String get hidden_balance => "Verborgen balans";
@override
String get biometric_auth_reason => "Scan uw vingerafdruk om te verifiëren";
@override
String get transaction_sent => "Transactie verzonden!";
@override
String get password => "Wachtwoord";
@@ -5233,6 +5252,8 @@ class $zh extends S {
@override
String get hidden_balance => "隐藏余额";
@override
String get biometric_auth_reason => "掃描指紋以進行身份驗證";
@override
String get transaction_sent => "交易已发送";
@override
String get password => "密码";
+24
View File
@@ -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;
}
}
+22
View File
@@ -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) {
+5
View File
@@ -91,4 +91,9 @@ abstract class AuthStoreBase with Store {
return Duration(milliseconds: timeout);
}
@action
void biometricAuth() {
state = AuthenticatedSuccessfully();
}
}