From 7cc3918b8dd53e470e3c1a25e95b0e1ea93bcbf6 Mon Sep 17 00:00:00 2001 From: Eric Dvorsak Date: Mon, 20 Nov 2017 16:50:03 +0100 Subject: [PATCH] [bug] check if account is new by checking accounts previous behavior was using context (which screen we were on) to determine if account was new or not. in order to be able to have more straightforward automation this commit now checks the list of accounts to get that information which is more accurate and allows to login without navigating screens. --- .../ui/screens/accounts/login/events.cljs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/status_im/ui/screens/accounts/login/events.cljs b/src/status_im/ui/screens/accounts/login/events.cljs index 66d0336744..076f266350 100644 --- a/src/status_im/ui/screens/accounts/login/events.cljs +++ b/src/status_im/ui/screens/accounts/login/events.cljs @@ -97,22 +97,27 @@ wrap-with-stop-node-fx)] (wrap-fn db' address password)))) +(defn is-new-account? + "checks if the account is in the accounts in the db" + [{:accounts/keys [accounts]} address] + (let [present? (set (keys accounts))] + (not (present? address)))) + (register-handler-fx :login-handler - (fn [{db :db} [_ result address]] - (let [data (json->clj result) + (fn [{db :db} [_ login-result address]] + (let [data (json->clj login-result) error (:error data) success (zero? (count error)) db' (assoc-in db [:accounts/login :processing] false)] - (log/debug "Logged in account: " result) + (log/debug "Logging result: " login-result) (merge - {:db (if success db' (assoc-in db' [:accounts/login :error] error))} - (when success - (let [is-login-screen? (= (:view-id db) :login) - new-account? (not is-login-screen?)] - (log/debug "Logged in: " (:view-id db) is-login-screen? new-account?) - {::clear-web-data nil - ::change-account [address new-account?]})))))) + {:db (if success db' (assoc-in db' [:accounts/login :error] error))} + (when success + (let [new-account? (is-new-account? db address)] + (log/debug "Logged in" (when new-account? " new account") ":" address) + {::clear-web-data nil + ::change-account [address new-account?]})))))) (register-handler-fx :change-account-handler