From 35a19053965b2e7dd0207c7674e29d055b295c35 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 3 Jul 2024 15:27:27 +0200 Subject: [PATCH] Fix auth slider resetting when wallet connect signing is finished (#20589) * Fix auth slider resetting when wallet connect signing is finished * Lint fix * Fixes * Fixes --- .../components/buttons/slide_button/view.cljs | 8 ++-- .../standard_authentication/events.cljs | 32 ++++++++++--- .../standard_auth/slide_button/view.cljs | 3 +- .../preview/quo/buttons/slide_button.cljs | 46 ++++++++----------- 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/quo/components/buttons/slide_button/view.cljs b/src/quo/components/buttons/slide_button/view.cljs index 9a8d9bbbb1..3ca145299c 100644 --- a/src/quo/components/buttons/slide_button/view.cljs +++ b/src/quo/components/buttons/slide_button/view.cljs @@ -26,7 +26,8 @@ (reanimated/set-shared-value x-pos clamped-x) (when (and reached-end? (not sliding-complete?)) (set-sliding-complete true) - (when on-complete (on-complete reset-fn)))))) + (when on-complete + (on-complete reset-fn)))))) (gesture/on-end (fn [event] (let [x-translation (oops/oget event "translationX") reached-end? (>= x-translation track-width)] @@ -54,9 +55,10 @@ on-track-layout (rn/use-callback #(set-track-width (oops/oget % "nativeEvent.layout.width"))) reset-fn (rn/use-callback - (fn [] + (fn [keep-at-end-after-slide?] (set-sliding-complete false) - (animations/reset-track-position x-pos))) + (when-not keep-at-end-after-slide? + (animations/reset-track-position x-pos)))) dimensions (rn/use-callback (partial utils/get-dimensions (or track-width constants/default-width) diff --git a/src/status_im/common/standard_authentication/events.cljs b/src/status_im/common/standard_authentication/events.cljs index 400eee1970..7c2580a931 100644 --- a/src/status_im/common/standard_authentication/events.cljs +++ b/src/status_im/common/standard_authentication/events.cljs @@ -32,9 +32,8 @@ :on-cancel #(rf/dispatch [:standard-auth/authorize-with-password args-with-biometric-btn]) :on-success (fn [] - (when (fn? on-close) - (on-close)) - (rf/dispatch [:standard-auth/on-biometric-success on-auth-success])) + (rf/dispatch [:standard-auth/on-biometric-success on-auth-success]) + (rf/dispatch [:standard-auth/close on-close])) :on-fail (fn [err] (rf/dispatch [:standard-auth/authorize-with-password args-with-biometric-btn]) @@ -48,6 +47,7 @@ [{:keys [db]} [on-auth-success]] (let [key-uid (get-in db [:profile/profile :key-uid])] {:fx [[:keychain/get-user-password [key-uid on-auth-success]] + [:dispatch [:standard-auth/set-success true]] [:dispatch [:standard-auth/reset-login-password]]]})) (schema/=> on-biometric-success events-schema/?on-biometric-success) @@ -74,6 +74,7 @@ (fn [password] (let [sha3-pwd (security/hash-masked-password password) on-auth-success-callback #(on-auth-success sha3-pwd)] + (rf/dispatch [:standard-auth/set-success true]) (rf/dispatch [:standard-auth/reset-login-password]) (if has-partially-operable-accounts? (rf/dispatch [:wallet/make-partially-operable-accounts-fully-operable @@ -92,10 +93,7 @@ {:fx [[:dispatch [:standard-auth/reset-login-password]] [:dispatch [:show-bottom-sheet - {:on-close (fn [] - (rf/dispatch [:standard-auth/reset-login-password]) - (when on-close - (on-close))) + {:on-close #(rf/dispatch [:standard-auth/close on-close]) :theme theme :shell? blur? :content #(bottom-sheet-password-view args)}]]]}) @@ -107,3 +105,23 @@ :standard-auth/reset-login-password (fn [{:keys [db]}] {:db (update db :profile/login dissoc :password :error)})) + +(rf/reg-fx + :standard-auth/on-close + (fn [{:keys [on-close success?]}] + (when on-close + (on-close success?)))) + +(rf/reg-event-fx + :standard-auth/close + (fn [{:keys [db]} [on-close]] + {:db (assoc-in db [:profile/login :success?] false) + :fx [[:dispatch [:standard-auth/reset-login-password]] + [:standard-auth/on-close + {:on-close on-close + :success? (get-in db [:profile/login :success?])}]]})) + +(rf/reg-event-fx + :standard-auth/set-success + (fn [{:keys [db]} [success?]] + {:db (assoc-in db [:profile/login :success?] success?)})) diff --git a/src/status_im/common/standard_authentication/standard_auth/slide_button/view.cljs b/src/status_im/common/standard_authentication/standard_auth/slide_button/view.cljs index dd5cb2aa7c..c96eedf17a 100644 --- a/src/status_im/common/standard_authentication/standard_auth/slide_button/view.cljs +++ b/src/status_im/common/standard_authentication/standard_auth/slide_button/view.cljs @@ -16,7 +16,8 @@ on-complete (rn/use-callback (fn [reset] (rf/dispatch [:standard-auth/authorize - {:on-close #(js/setTimeout reset 200) + {:on-close (fn [success?] + (js/setTimeout #(reset success?) 200)) :auth-button-icon-left auth-button-icon-left :theme theme :blur? blur? diff --git a/src/status_im/contexts/preview/quo/buttons/slide_button.cljs b/src/status_im/contexts/preview/quo/buttons/slide_button.cljs index 59629250c0..c21009ce17 100644 --- a/src/status_im/contexts/preview/quo/buttons/slide_button.cljs +++ b/src/status_im/contexts/preview/quo/buttons/slide_button.cljs @@ -1,7 +1,6 @@ (ns status-im.contexts.preview.quo.buttons.slide-button (:require [quo.core :as quo] - [react-native.core :as rn] [reagent.core :as reagent] [status-im.contexts.preview.quo.preview :as preview])) @@ -18,41 +17,36 @@ :type :boolean} {:key :blur? :type :boolean} + {:key :keep-at-end-after-slide? + :type :boolean} (preview/customization-color-option {:key :color})]) (defn f-view [] - (let [state (reagent/atom {:disabled? false - :color :blue - :size :size-48}) - color (reagent/cursor state [:color]) - blur? (reagent/cursor state [:blur?]) - complete? (reagent/atom false)] + (let [state (reagent/atom {:disabled? false + :color :blue + :size :size-48 + :keep-at-end-after-slide? false}) + color (reagent/cursor state [:color]) + blur? (reagent/cursor state [:blur?]) + keep-at-end-after-slide? (reagent/cursor state [:keep-at-end-after-slide?])] (fn [] - (rn/use-effect (fn [] - (reset! complete? true) - (js/setTimeout #(reset! complete? false) 50)) - [(:size @state)]) [preview/preview-container {:state state :descriptor descriptor :component-container-style (when-not @blur? (:align-items :center)) :blur? @blur? :show-blur-background? true} - (if (not @complete?) - [quo/slide-button - {:track-text "We gotta slide" - :track-icon :face-id - :customization-color @color - :size (:size @state) - :disabled? (:disabled? @state) - :blur? @blur? - :type (:type @state) - :on-complete (fn [_] - (js/setTimeout (fn [] (reset! complete? true)) - 1000) - (js/alert "I don't wanna slide anymore"))}] - [quo/button {:on-press (fn [] (reset! complete? false))} - "Try again"])]))) + [quo/slide-button + {:track-text "We gotta slide" + :track-icon :face-id + :customization-color @color + :size (:size @state) + :disabled? (:disabled? @state) + :blur? @blur? + :type (:type @state) + :on-complete (fn [reset-fn] + (js/alert "Slide complete") + (reset-fn @keep-at-end-after-slide?))}]]))) (defn view [] [:f> f-view])