From 6099262c984eb194157a9a974a570fb259517766 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 28 Dec 2020 12:30:50 +0100 Subject: [PATCH] [Fixes: #11579] Add only certain fields to multiaccount on login `multiaccounts` has some fields that should not be overriden (`save-password`), so we expliciltly `assoc` only certain fields. Signed-off-by: Andrea Maria Piana --- src/status_im/events.cljs | 8 ++++++-- src/status_im/init/core.cljs | 7 ++++++- src/status_im/multiaccounts/login/core.cljs | 17 ++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index c42c08a265..d8c553f084 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -139,13 +139,17 @@ (handlers/register-handler-fx :multiaccounts.login.ui/multiaccount-selected (fn [{:keys [db] :as cofx} [_ key-uid]] - (let [multiaccount (get-in db [:multiaccounts/multiaccounts key-uid])] + ;; We specifically pass a bunch of fields instead of the whole multiaccount + ;; as we want store some fields in multiaccount that are not here + (let [multiaccount + (get-in db [:multiaccounts/multiaccounts key-uid])] (fx/merge cofx {:db (-> db (dissoc :intro-wizard) (update :keycard dissoc :application-info))} - (multiaccounts.login/open-login multiaccount))))) + (multiaccounts.login/open-login + (select-keys multiaccount [:key-uid :name :public-key :identicon :images])))))) (handlers/register-handler-fx :login/filters-initialized diff --git a/src/status_im/init/core.cljs b/src/status_im/init/core.cljs index 5a67136aa3..46d6aa119e 100644 --- a/src/status_im/init/core.cljs +++ b/src/status_im/init/core.cljs @@ -27,8 +27,13 @@ [cofx {:keys [logout?]}] (let [{{:multiaccounts/keys [multiaccounts]} :db} cofx] (when (and (seq multiaccounts) (not logout?)) + ;; We specifically pass a bunch of fields instead of the whole multiaccount + ;; as we want store some fields in multiaccount that are not here (let [multiaccount (first (sort-by :timestamp > (vals multiaccounts)))] - (multiaccounts.login/open-login cofx multiaccount))))) + (multiaccounts.login/open-login cofx + (select-keys + multiaccount + [:key-uid :name :public-key :identicon :images])))))) (fx/defn initialize-multiaccounts {:events [::initialize-multiaccounts]} diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index d0b545a4c2..a8cc1e94ec 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -342,11 +342,22 @@ ;; FIXME(Ferossgp): We should not copy keys as we denormalize the database, ;; this create desync between actual accounts and the one on login causing broken state +;; UPDATE(cammellos): This code is copying over some fields explicitly as some values +;; are alreayd in `multiaccounts/login` and should not be overriden, as they come from +;; the keychain (save-password), this is not very explicit and we should probably +;; make it clearer (fx/defn open-login - [{:keys [db] :as cofx} {:keys [key-uid] :as multiaccount}] + [{:keys [db] :as cofx} override-multiaccount] (fx/merge cofx - {:db (assoc db :multiaccounts/login multiaccount)} - (keychain/get-auth-method key-uid))) + {:db (-> db + (update :multiaccounts/login + merge + override-multiaccount) + (update :multiaccounts/login + dissoc + :error + :password))} + (keychain/get-auth-method (:key-uid override-multiaccount)))) (fx/defn open-login-callback {:events [:multiaccounts.login.callback/get-user-password-success]}