From 59c2b79df2c4c127669397afbe30311013c9b31c Mon Sep 17 00:00:00 2001 From: Parvesh Monu Date: Wed, 25 Sep 2024 19:40:26 +0530 Subject: [PATCH] fix Lost the syncing state in fallback recovery, when first enter the seed phrase for the wrong account (#21298) --- .../create_or_sync_profile/view.cljs | 2 ++ src/status_im/contexts/onboarding/events.cljs | 23 ++++++++++------- .../onboarding/syncing/progress/view.cljs | 1 + .../contexts/profile/login/events.cljs | 2 +- src/status_im/contexts/syncing/events.cljs | 25 +++++++++++-------- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/status_im/contexts/onboarding/create_or_sync_profile/view.cljs b/src/status_im/contexts/onboarding/create_or_sync_profile/view.cljs index 932057c5e5..98432e790c 100644 --- a/src/status_im/contexts/onboarding/create_or_sync_profile/view.cljs +++ b/src/status_im/contexts/onboarding/create_or_sync_profile/view.cljs @@ -23,6 +23,7 @@ (defn- navigate-to-sign-in-by-syncing [] + (rf/dispatch [:syncing/clear-syncing-fallback-flow]) (debounce/throttle-and-dispatch [:onboarding/navigate-to-sign-in-by-syncing] 1000)) @@ -37,6 +38,7 @@ (defn- navigate-to-sign-in-by-seed-phrase [create-profile?] + (rf/dispatch [:syncing/clear-syncing-fallback-flow]) (rf/dispatch [:onboarding/navigate-to-sign-in-by-seed-phrase (if create-profile? :screen/onboarding.new-to-status diff --git a/src/status_im/contexts/onboarding/events.cljs b/src/status_im/contexts/onboarding/events.cljs index e5dcd8511c..c3073b1cb4 100644 --- a/src/status_im/contexts/onboarding/events.cljs +++ b/src/status_im/contexts/onboarding/events.cljs @@ -72,15 +72,21 @@ [{:keys [db] :as cofx}] (let [{:keys [display-name seed-phrase password image-path color] :as profile} (:onboarding/profile db) - loading-screen (if (seq (:syncing/key-uid db)) + syncing-account-recovered? (and (seq (:syncing/key-uid db)) + (= (:syncing/key-uid db) + (get-in db [:onboarding/profile :key-uid]))) + loading-screen (if syncing-account-recovered? :screen/onboarding.preparing-status :screen/onboarding.generating-keys)] (rf/merge cofx - {:dispatch [:navigate-to-within-stack - [loading-screen - (get db - :onboarding/navigated-to-enter-seed-phrase-from-screen - :screen/onboarding.new-to-status)]] + {:fx [[:dispatch + [:navigate-to-within-stack + [loading-screen + (get db + :onboarding/navigated-to-enter-seed-phrase-from-screen + :screen/onboarding.new-to-status)]]] + (when-not syncing-account-recovered? + [:dispatch [:syncing/clear-syncing-installation-id]])] :dispatch-later [{:ms constants/onboarding-generating-keys-animation-duration-ms :dispatch [:navigate-to-within-stack [:screen/onboarding.enable-notifications @@ -154,15 +160,14 @@ :on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}} {:db (-> db (assoc-in [:onboarding/profile :seed-phrase] seed-phrase) + (assoc-in [:onboarding/profile :key-uid] key-uid) (assoc-in [:onboarding/profile :color] constants/profile-default-color)) :fx [[:dispatch [:navigate-to-within-stack [next-screen (get db :onboarding/navigated-to-enter-seed-phrase-from-screen - :screen/onboarding.new-to-status)]]] - (when-not syncing-account-recovered? - [:dispatch [:syncing/clear-syncing-data]])]}))) + :screen/onboarding.new-to-status)]]]]}))) (rf/defn navigate-to-create-profile {:events [:onboarding/navigate-to-create-profile]} diff --git a/src/status_im/contexts/onboarding/syncing/progress/view.cljs b/src/status_im/contexts/onboarding/syncing/progress/view.cljs index 57966faa2f..08aa1256a0 100644 --- a/src/status_im/contexts/onboarding/syncing/progress/view.cljs +++ b/src/status_im/contexts/onboarding/syncing/progress/view.cljs @@ -28,6 +28,7 @@ (defn- navigate-to-enter-seed-phrase [] + (rf/dispatch [:syncing/set-syncing-fallback-flow]) (debounce/debounce-and-dispatch [:onboarding/navigate-to-sign-in-by-seed-phrase :screen/onboarding.sync-or-recover-profile] 500)) diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index 7347774053..7b1da9d318 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -142,7 +142,7 @@ (rf/dispatch [:chats-list/load-success result]) (rf/dispatch [:communities/get-user-requests-to-join]) (rf/dispatch [:profile.login/get-chats-callback]))}] - (when (:syncing/installation-id db) + (when (and (:syncing/fallback-flow? db) (:syncing/installation-id db)) [:dispatch [:pairing/finish-seed-phrase-fallback-syncing]]) (when-not new-account? [:dispatch [:universal-links/process-stored-event]])]}))) diff --git a/src/status_im/contexts/syncing/events.cljs b/src/status_im/contexts/syncing/events.cljs index c1c3dae817..10d5f74a3f 100644 --- a/src/status_im/contexts/syncing/events.cljs +++ b/src/status_im/contexts/syncing/events.cljs @@ -39,11 +39,6 @@ {:type :negative :text error}])))) -(rf/defn initiate-pairing-process - {:events [:syncing/initiate-pairing-process]} - [{:keys [db]}] - {:db (assoc db :syncing/pairing-process-initiated? true)}) - (rf/defn set-syncing-installation-id {:events [:syncing/set-syncing-installation-id]} [{:keys [db]} installation-id key-uid] @@ -51,15 +46,26 @@ :syncing/key-uid key-uid :syncing/installation-id installation-id)}) -(defn clear-syncing-data +(defn clear-syncing-installation-id [{:keys [db]}] {:db (dissoc db :syncing/key-uid - :syncing/installation-id - :syncing/pairing-process-initiated?)}) + :syncing/installation-id)}) -(re-frame/reg-event-fx :syncing/clear-syncing-data clear-syncing-data) +(re-frame/reg-event-fx :syncing/clear-syncing-installation-id clear-syncing-installation-id) + +(defn set-syncing-fallback-flow + [{:keys [db]}] + {:db (assoc db :syncing/fallback-flow? true)}) + +(re-frame/reg-event-fx :syncing/set-syncing-fallback-flow set-syncing-fallback-flow) + +(defn clear-syncing-fallback-flow + [{:keys [db]}] + {:db (dissoc db :syncing/fallback-flow?)}) + +(re-frame/reg-event-fx :syncing/clear-syncing-fallback-flow clear-syncing-fallback-flow) (rf/defn preflight-outbound-check-for-local-pairing {:events [:syncing/preflight-outbound-check]} @@ -95,7 +101,6 @@ (when (sync-utils/valid-connection-string? response) (on-valid-connection-string response) (rf/dispatch [:syncing/update-role constants/local-pairing-role-sender]) - (rf/dispatch [:syncing/initiate-pairing-process]) (rf/dispatch [:hide-bottom-sheet])))] (when-not (and error (string/blank? error)) (let [key-uid (get-in db [:profile/profile :key-uid])