[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.
This commit is contained in:
Eric Dvorsak 2017-11-20 16:50:03 +01:00 committed by Eric Dvorsak
parent 00132c5921
commit 7cc3918b8d

View File

@ -97,20 +97,25 @@
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} [_ result address]] (fn [{db :db} [_ login-result address]]
(let [data (json->clj result) (let [data (json->clj login-result)
error (:error data) error (:error data)
success (zero? (count error)) success (zero? (count error))
db' (assoc-in db [:accounts/login :processing] false)] db' (assoc-in db [:accounts/login :processing] false)]
(log/debug "Logged in account: " result) (log/debug "Logging result: " login-result)
(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 [is-login-screen? (= (:view-id db) :login) (let [new-account? (is-new-account? db address)]
new-account? (not is-login-screen?)] (log/debug "Logged in" (when new-account? " new account") ":" address)
(log/debug "Logged in: " (:view-id db) is-login-screen? new-account?)
{::clear-web-data nil {::clear-web-data nil
::change-account [address new-account?]})))))) ::change-account [address new-account?]}))))))