From 50f6c1ef1bed55b88b897dfea8ee61ea3cb98e87 Mon Sep 17 00:00:00 2001 From: yqrashawn Date: Tue, 20 Feb 2024 10:11:22 +0800 Subject: [PATCH] fix: password input triggers re-render of whole login view (#18728) --- .../password_input/view.cljs | 8 +++-- .../contexts/profile/login/events.cljs | 5 +++ .../contexts/profile/profiles/view.cljs | 33 +++++++++++-------- src/status_im/subs/profile.cljs | 12 +++++++ 4 files changed, 41 insertions(+), 17 deletions(-) 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 50eb424b44..bba900585c 100644 --- a/src/status_im/common/standard_authentication/password_input/view.cljs +++ b/src/status_im/common/standard_authentication/password_input/view.cljs @@ -7,6 +7,7 @@ [react-native.core :as rn] [status-im.common.standard-authentication.forgot-password-doc.view :as forgot-password-doc] [status-im.common.standard-authentication.password-input.style :as style] + [utils.debounce :as debounce] [utils.i18n :as i18n] [utils.re-frame :as rf] [utils.security.core :as security])) @@ -22,9 +23,10 @@ (defn- on-change-password [entered-password] - (rf/dispatch [:set-in [:profile/login :password] - (security/mask-data entered-password)]) - (rf/dispatch [:set-in [:profile/login :error] ""])) + (debounce/debounce-and-dispatch [:profile/on-password-input-changed + {:password (security/mask-data entered-password) + :error ""}] + 100)) (defn- view-internal [{:keys [default-password theme shell? on-press-biometrics blur?]}] diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index aad293b407..56d365974a 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -247,3 +247,8 @@ #(-> % (dissoc :processing) (assoc :error "Invalid password")))})) + +(re-frame/reg-event-fx + :profile/on-password-input-changed + (fn [{:keys [db]} [{:keys [password error]}]] + {:db (update db :profile/login assoc :password password :error error)})) diff --git a/src/status_im/contexts/profile/profiles/view.cljs b/src/status_im/contexts/profile/profiles/view.cljs index e833f87955..b6aa3a39fb 100644 --- a/src/status_im/contexts/profile/profiles/view.cljs +++ b/src/status_im/contexts/profile/profiles/view.cljs @@ -172,13 +172,29 @@ [props] [:f> f-profiles-section props]) +(defn password-input + [] + (let [password (rf/sub [:profile/login-password]) + auth-method (rf/sub [:auth-method])] + [standard-authentication/password-input + {: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}])) + (defn login-section [{:keys [set-show-profiles]}] - (let [{:keys [processing password]} (rf/sub [:profile/login]) + (let [processing (rf/sub [:profile/login-processing]) {: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 @@ -213,18 +229,7 @@ :customization-color (or customization-color :primary) :profile-picture profile-picture :card-style style/login-profile-card}] - [standard-authentication/password-input - {: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}]] + [password-input]] [quo/button {:size 40 :type :primary diff --git a/src/status_im/subs/profile.cljs b/src/status_im/subs/profile.cljs index 195dbeb180..581c22ba7c 100644 --- a/src/status_im/subs/profile.cljs +++ b/src/status_im/subs/profile.cljs @@ -338,6 +338,18 @@ (fn [[{:keys [key-uid]} profiles]] (get profiles key-uid))) +(re-frame/reg-sub + :profile/login-processing + :<- [:profile/login] + (fn [{:keys [processing]}] + processing)) + +(re-frame/reg-sub + :profile/login-password + :<- [:profile/login] + (fn [{:keys [password]}] + password)) + ;; LINK PREVIEW ;; ========================================================================================================