[bug] fix regressions on creating new account

This commit is contained in:
Eric Dvorsak 2017-11-30 06:21:24 +01:00 committed by Eric Dvorsak
parent cfa14ff6b3
commit 92b22abbef
1 changed files with 13 additions and 22 deletions

View File

@ -1,7 +1,5 @@
(ns status-im.ui.screens.accounts.login.events (ns status-im.ui.screens.accounts.login.events
(:require (:require status-im.ui.screens.accounts.login.navigation
status-im.ui.screens.accounts.login.navigation
[re-frame.core :refer [dispatch reg-fx]] [re-frame.core :refer [dispatch reg-fx]]
[status-im.utils.handlers :refer [register-handler-db register-handler-fx]] [status-im.utils.handlers :refer [register-handler-db register-handler-fx]]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@ -97,15 +95,9 @@
wrap-with-stop-node-fx)] wrap-with-stop-node-fx)]
(wrap-fn db' address password)))) (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 (register-handler-fx
:login-handler :login-handler
(fn [{db :db} [_ login-result address]] (fn [{{:accounts/keys [account-creation?] :as db} :db} [_ login-result address]]
(let [data (json->clj login-result) (let [data (json->clj login-result)
error (:error data) error (:error data)
success (zero? (count error)) success (zero? (count error))
@ -114,10 +106,9 @@
(merge (merge
{:db (if success db' (assoc-in db' [:accounts/login :error] error))} {:db (if success db' (assoc-in db' [:accounts/login :error] error))}
(when success (when success
(let [new-account? (is-new-account? db address)] (log/debug "Logged in" (when account-creation? " new account") ":" address)
(log/debug "Logged in" (when new-account? " new account") ":" address)
{::clear-web-data nil {::clear-web-data nil
::change-account [address new-account?]})))))) ::change-account [address account-creation?]})))))
(register-handler-fx (register-handler-fx
:change-account-handler :change-account-handler