From d0e624afd7301e60a44a495347c532a353a12aa5 Mon Sep 17 00:00:00 2001 From: Lungu Cristian Date: Wed, 20 Dec 2023 17:15:51 +0200 Subject: [PATCH] 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 --- src/status_im/common/biometric/events.cljs | 9 +++++++-- .../password_input/view.cljs | 5 +++-- src/status_im/constants.cljs | 5 +++++ src/status_im/contexts/profile/login/events.cljs | 4 ++-- .../contexts/profile/profiles/view.cljs | 16 ++++++++++++++-- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/status_im/common/biometric/events.cljs b/src/status_im/common/biometric/events.cljs index 0c95eabcb9..feedcc843b 100644 --- a/src/status_im/common/biometric/events.cljs +++ b/src/status_im/common/biometric/events.cljs @@ -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? diff --git a/src/status_im/common/standard_authentication/password_input/view.cljs b/src/status_im/common/standard_authentication/password_input/view.cljs index e3e1834e5d..50eb424b44 100644 --- a/src/status_im/common/standard_authentication/password_input/view.cljs +++ b/src/status_im/common/standard_authentication/password_input/view.cljs @@ -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? diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index ff6a3a6414..881c554d8b 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -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) diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index 6d6fd51ee8..560584628b 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -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]]] diff --git a/src/status_im/contexts/profile/profiles/view.cljs b/src/status_im/contexts/profile/profiles/view.cljs index 7b52392de9..d5682b8f6a 100644 --- a/src/status_im/contexts/profile/profiles/view.cljs +++ b/src/status_im/contexts/profile/profiles/view.cljs @@ -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