Biometrics button on login screen (#18106)

* feat: login with biometry when switching accounts

* feat: biometry button on login screen

* fix: addressed review comments

* fix: biometry button background

* ref: moved biometrics constants to main constants file

* fix: hide biometric button when not enabled

* feat: standard_auth blur prop

* fix: leftover rename
This commit is contained in:
Lungu Cristian 2023-12-20 17:15:51 +02:00 committed by GitHub
parent bf55a2a974
commit d0e624afd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 8 deletions

View File

@ -6,6 +6,7 @@
[react-native.platform :as platform]
[react-native.touch-id :as touch-id]
[status-im.common.keychain.events :as keychain]
[status-im.constants :as constants]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
@ -46,8 +47,12 @@
{:events [:biometric/show-message]}
[_ code]
(let [handle-error? (and code
(not (contains? #{"USER_CANCELED" "USER_FALLBACK"} code)))
content (if (#{"NOT_AVAILABLE" "NOT_ENROLLED"} code)
(not (contains? #{constants/biometric-error-user-canceled
constants/biometric-error-user-fallback}
code)))
content (if (#{constants/biometric-error-not-available
constants/biometric-error-not-enrolled}
code)
(i18n/label :t/grant-face-id-permissions)
(i18n/label :t/biometric-auth-error {:code code}))]
(when handle-error?

View File

@ -27,7 +27,7 @@
(rf/dispatch [:set-in [:profile/login :error] ""]))
(defn- view-internal
[{:keys [default-password theme shell? on-press-biometrics]}]
[{:keys [default-password theme shell? on-press-biometrics blur?]}]
(let [{:keys [error processing]} (rf/sub [:profile/login])
error-message (get-error-message error)
error? (boolean (seq error-message))]
@ -36,7 +36,7 @@
[quo/input
{:container-style {:flex 1}
:type :password
:blur? true
:blur? blur?
:disabled? processing
:placeholder (i18n/label :t/type-your-password)
:auto-focus true
@ -49,6 +49,7 @@
{:container-style style/auth-button
:on-press on-press-biometrics
:icon-only? true
:background (when blur? :blur)
:type :outline}
:i/face-id])]
(when error?

View File

@ -375,6 +375,11 @@
(def ^:const auth-method-biometric-prepare "biometric-prepare")
(def ^:const auth-method-none "none")
(def ^:const biometric-error-user-canceled "USER_CANCELED")
(def ^:const biometric-error-user-fallback "USER_USER_FALLBACK")
(def ^:const biometric-error-not-available "NOT_AVAILABLE")
(def ^:const biometric-error-not-enrolled "NOT_ENROLLED")
(def ^:const onboarding-generating-keys-animation-duration-ms 7000)
(def ^:const onboarding-generating-keys-navigation-retry-ms 3000)

View File

@ -16,6 +16,7 @@
[status-im.common.log :as logging]
[status-im.common.universal-links :as universal-links]
[status-im.config :as config]
[status-im.constants :as constants]
[status-im.contexts.chat.messages.link-preview.events :as link-preview]
[status-im.contexts.contacts.events :as contacts]
[status-im.contexts.profile.config :as profile.config]
@ -220,8 +221,7 @@
(fn [{:keys [db]} [code]]
(let [key-uid (get-in db [:profile/login :key-uid])]
{:db db
:fx [[:dispatch [:init-root :profiles]]
(if (= code "NOT_ENROLLED")
:fx [(if (= code constants/biometric-error-not-enrolled)
[:biometric/supress-not-enrolled-error
[key-uid
[:biometric/show-message code]]]

View File

@ -124,6 +124,8 @@
:on-card-press (fn []
(rf/dispatch
[:profile/profile-selected key-uid])
(rf/dispatch
[:profile.login/login-with-biometric-if-available key-uid])
(when-not keycard-pairing (set-hide-profiles)))}]))
(defn- f-profiles-section
@ -171,6 +173,7 @@
{:keys [key-uid name customization-color]} (rf/sub [:profile/login-profile])
sign-in-enabled? (rf/sub [:sign-in-enabled?])
profile-picture (rf/sub [:profile/login-profiles-picture key-uid])
auth-method (rf/sub [:auth-method])
login-multiaccount #(rf/dispatch [:profile.login/login])]
[rn/keyboard-avoiding-view
{:style style/login-container
@ -206,8 +209,17 @@
:profile-picture profile-picture
:card-style style/login-profile-card}]
[standard-authentication/password-input
{:shell? true
:default-password password}]]
{:shell? true
:blur? true
:on-press-biometrics (when (= auth-method constants/auth-method-biometric)
(fn []
(rf/dispatch [:biometric/authenticate
{:on-success #(rf/dispatch
[:profile.login/biometric-success])
:on-fail #(rf/dispatch
[:profile.login/biometric-auth-fail
%])}])))
:default-password password}]]
[quo/button
{:size 40
:type :primary