From 7f1ac63cdf584b9d69eb28d97eade7c61082c0b8 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Thu, 30 Jun 2016 23:03:43 +0300 Subject: [PATCH] autologin to account when its already created --- src/status_im/accounts/handlers.cljs | 12 +++++++++--- src/status_im/handlers.cljs | 22 +++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index cb64243e8f..cfb6d32d9b 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -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))) \ No newline at end of file + (-> (fn [db [_ address password]] + (.login geth address password (fn [result] (log/debug "Logged in account: " address result))) + db))) \ No newline at end of file diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index cd3ce76f44..ee070f1ceb 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -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!