autologin to account when its already created

This commit is contained in:
Adrian Tiberius 2016-06-30 23:03:43 +03:00
parent 6fc1e0b46a
commit 7f1ac63cdf
2 changed files with 26 additions and 8 deletions

View File

@ -4,6 +4,8 @@
[status-im.utils.logging :as log]
[status-im.components.react :refer [geth]]
[status-im.utils.types :refer [json->clj]]
[status-im.persistence.simple-kv-store :as kv]
[status-im.protocol.state.storage :as storage]
[clojure.string :as str]))
@ -15,6 +17,9 @@
(update db :accounts assoc address account))
((after save-account))))
(defn save-password [password]
(storage/put kv/kv-store :password password))
(defn account-created [result password]
(let [data (json->clj result)
public-key (:pubkey data)
@ -24,6 +29,7 @@
(log/debug "Created account: " result)
(when (not (str/blank? public-key))
(do
(save-password password)
(dispatch [:login-account address password])
(dispatch [:initialize-protocol account])
(dispatch [:add-account account])))))
@ -34,6 +40,6 @@
db)))
(register-handler :login-account
(-> (fn [db [_ address password]]
(.login geth address password (fn [result] (log/debug "Logged in account: " address result)))
db)))
(-> (fn [db [_ address password]]
(.login geth address password (fn [result] (log/debug "Logged in account: " address result)))
db)))

View File

@ -9,6 +9,7 @@
[status-im.utils.crypt :refer [gen-random-bytes]]
[status-im.components.react :refer [geth]]
[status-im.utils.handlers :refer [register-handler] :as u]
[status-im.models.protocol :as protocol]
status-im.chat.handlers
status-im.chat.handlers.animation
status-im.group-settings.handlers
@ -57,7 +58,9 @@
(register-handler :initialize-db
(fn [_ _]
(assoc app-db
:signed-up (storage/get kv/kv-store :signed-up))))
:signed-up (storage/get kv/kv-store :signed-up)
:user-identity (protocol/stored-identity nil)
:password (storage/get kv/kv-store :password))))
(register-handler :initialize-crypt
(u/side-effect!
@ -74,11 +77,20 @@
(.toBits (.. js/ecc -sjcl -codec -hex))
(.addEntropy (.. js/ecc -sjcl -random)))
(dispatch [:crypt-initialized]))))))))
(defn node-started [db result]
(let [identity (:user-identity db)
password (:password db)]
(log/debug "Started Node: " result)
(when identity (do
(dispatch [:login-account (:address identity) password])
(dispatch [:initialize-protocol identity])))))
(register-handler :initialize-geth
(u/side-effect!
(fn [_ _]
(log/debug "Starting node")
(.startNode geth (fn [result] (log/debug "Started Node: " result))))))
(u/side-effect!
(fn [db _]
(log/debug "Starting node")
(.startNode geth (fn [result] (node-started db result))))))
(register-handler :crypt-initialized
(u/side-effect!