diff --git a/src/status_im2/common/standard_authentication/password_input/style.cljs b/src/status_im2/common/standard_authentication/password_input/style.cljs index b15a6ed2224..f60de494658 100644 --- a/src/status_im2/common/standard_authentication/password_input/style.cljs +++ b/src/status_im2/common/standard_authentication/password_input/style.cljs @@ -4,3 +4,11 @@ {:margin-top 8 :flex-direction :row :align-items :center}) + +(def input-container + {:flex-direction :row + :align-items :flex-end}) + +(def input + {:flex 1 + :margin-right 12}) diff --git a/src/status_im2/common/standard_authentication/password_input/view.cljs b/src/status_im2/common/standard_authentication/password_input/view.cljs index 5f0760eefa8..e919cfb2078 100644 --- a/src/status_im2/common/standard_authentication/password_input/view.cljs +++ b/src/status_im2/common/standard_authentication/password_input/view.cljs @@ -5,6 +5,7 @@ [quo.foundations.colors :as colors] [quo.theme :as quo.theme] [react-native.core :as rn] + [status-im2.common.keychain.events :as keychain] [status-im2.common.standard-authentication.forgot-password-doc.view :as forgot-password-doc] [status-im2.common.standard-authentication.password-input.style :as style] [utils.i18n :as i18n] @@ -29,19 +30,30 @@ (defn- view-internal [{:keys [default-password theme shell?]}] (let [{:keys [error processing]} (rf/sub [:profile/login]) + auth-method (rf/sub [:auth-method]) error-message (get-error-message error) error? (boolean (seq error-message))] [:<> - [quo/input - {:type :password - :blur? true - :disabled? processing - :placeholder (i18n/label :t/type-your-password) - :auto-focus true - :error? error? - :label (i18n/label :t/profile-password) - :on-change-text on-change-password - :default-value (security/safe-unmask-data default-password)}] + [rn/view {:style style/input-container} + [quo/input + {:type :password + :blur? true + :container-style style/input + :disabled? processing + :placeholder (i18n/label :t/type-your-password) + :auto-focus true + :error? error? + :label (i18n/label :t/profile-password) + :on-change-text on-change-password + :default-value (security/safe-unmask-data default-password)}] + (when (= auth-method keychain/auth-method-biometric) + [quo/button + {:type :outline + :icon-only? true + :on-press #(rf/dispatch [:profile.login/biometric-auth]) + :background :blur + :size 40} + :i/face-id])] (when error? [rn/view {:style style/error-message} [quo/info-message diff --git a/src/status_im2/contexts/profile/events.cljs b/src/status_im2/contexts/profile/events.cljs index 2e9a7802723..6d057f900d9 100644 --- a/src/status_im2/contexts/profile/events.cljs +++ b/src/status_im2/contexts/profile/events.cljs @@ -15,12 +15,11 @@ (rf/defn profile-selected {:events [:profile/profile-selected]} [{:keys [db]} key-uid] - {:db (update db - :profile/login - #(-> % - (assoc :key-uid key-uid) - (dissoc :error :password))) - :dispatch [:profile.login/login-with-biometric-if-available key-uid]}) + {:db (update db + :profile/login + #(-> % + (assoc :key-uid key-uid) + (dissoc :error :password)))}) (rf/defn init-profiles-overview [{:keys [db] :as cofx} profiles key-uid] @@ -28,6 +27,13 @@ {:db (assoc db :profile/profiles-overview profiles)} (profile-selected key-uid))) +(rf/reg-event-fx + :profile/switch-profile + (fn [{:keys [db]} [key-uid]] + {:db db + :fx [[:dispatch [:profile/profile-selected key-uid]] + [:dispatch [:profile.login/login-with-biometric-if-available key-uid]]]})) + (defn reduce-profiles [profiles] (reduce diff --git a/src/status_im2/contexts/profile/login/events.cljs b/src/status_im2/contexts/profile/login/events.cljs index 173e97baa73..583030d1aef 100644 --- a/src/status_im2/contexts/profile/login/events.cljs +++ b/src/status_im2/contexts/profile/login/events.cljs @@ -180,6 +180,14 @@ {:keychain/get-auth-method [key-uid #(rf/dispatch [:profile.login/get-auth-method-success % key-uid])]}) +(rf/reg-event-fx + :profile.login/biometric-auth + (fn [] + {:dispatch [:biometric/authenticate + {:on-success #(rf/dispatch [:profile.login/biometric-success]) + :on-fail #(rf/dispatch + [:profile.login/biometric-auth-fail %])}]})) + (rf/defn get-auth-method-success {:events [:profile.login/get-auth-method-success]} [{:keys [db]} auth-method key-uid] @@ -187,11 +195,7 @@ (when (= auth-method keychain/auth-method-biometric) {:keychain/password-hash-migration {:key-uid key-uid - :callback (fn [] - (rf/dispatch [:biometric/authenticate - {:on-success #(rf/dispatch [:profile.login/biometric-success]) - :on-fail #(rf/dispatch - [:profile.login/biometric-auth-fail %])}]))}}))) + :callback #(rf/dispatch [:profile.login/biometric-auth])}}))) ;; result of :keychain/get-auth-method above (rf/defn get-user-password-success @@ -218,8 +222,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 "NOT_ENROLLED") [:biometric/supress-not-enrolled-error [key-uid [:biometric/show-message code]]] diff --git a/src/status_im2/contexts/profile/profiles/view.cljs b/src/status_im2/contexts/profile/profiles/view.cljs index 8022d8a8992..868a99e6ebd 100644 --- a/src/status_im2/contexts/profile/profiles/view.cljs +++ b/src/status_im2/contexts/profile/profiles/view.cljs @@ -123,7 +123,7 @@ :profile-picture profile-picture}) :on-card-press (fn [] (rf/dispatch - [:profile/profile-selected key-uid]) + [:profile/switch-profile key-uid]) (when-not keycard-pairing (set-hide-profiles)))}])) (defn- f-profiles-section