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

View File

@ -9,6 +9,7 @@
[status-im.utils.crypt :refer [gen-random-bytes]] [status-im.utils.crypt :refer [gen-random-bytes]]
[status-im.components.react :refer [geth]] [status-im.components.react :refer [geth]]
[status-im.utils.handlers :refer [register-handler] :as u] [status-im.utils.handlers :refer [register-handler] :as u]
[status-im.models.protocol :as protocol]
status-im.chat.handlers status-im.chat.handlers
status-im.chat.handlers.animation status-im.chat.handlers.animation
status-im.group-settings.handlers status-im.group-settings.handlers
@ -57,7 +58,9 @@
(register-handler :initialize-db (register-handler :initialize-db
(fn [_ _] (fn [_ _]
(assoc app-db (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 (register-handler :initialize-crypt
(u/side-effect! (u/side-effect!
@ -74,11 +77,20 @@
(.toBits (.. js/ecc -sjcl -codec -hex)) (.toBits (.. js/ecc -sjcl -codec -hex))
(.addEntropy (.. js/ecc -sjcl -random))) (.addEntropy (.. js/ecc -sjcl -random)))
(dispatch [:crypt-initialized])))))))) (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 (register-handler :initialize-geth
(u/side-effect! (u/side-effect!
(fn [_ _] (fn [db _]
(log/debug "Starting node") (log/debug "Starting node")
(.startNode geth (fn [result] (log/debug "Started Node: " result)))))) (.startNode geth (fn [result] (node-started db result))))))
(register-handler :crypt-initialized (register-handler :crypt-initialized
(u/side-effect! (u/side-effect!