implemented login flow on startup

Former-commit-id: 14c2b19402
This commit is contained in:
Adrian Tiberius 2016-07-05 19:59:03 +03:00
parent 70026a7694
commit 7d6ff2bd68
8 changed files with 39 additions and 30 deletions

View File

@ -7,6 +7,7 @@
[status-im.persistence.simple-kv-store :as kv]
[status-im.protocol.state.storage :as storage]
[status-im.utils.identicon :refer [identicon]]
[status-im.db :refer [default-view]]
[clojure.string :as str]))
@ -34,8 +35,7 @@
(do
(save-password password)
(dispatch [:add-account account])
(dispatch [:login-account address password])
(dispatch [:initialize-protocol account])))))
(dispatch [:login-account address password])))))
(register-handler :create-account
(-> (fn [db [_ password]]
@ -45,7 +45,19 @@
(register-handler :login-account
(-> (fn [db [_ address password]]
(.login geth address password (fn [result]
(let [account (get-in db [:accounts address])]
(log/debug "Logged in account: " address result)
(dispatch [:set :current-account (get-in db [:accounts address])])))
(dispatch [:set :login {}])
(dispatch [:set :current-account account])
(dispatch [:initialize-protocol account])
(dispatch [:navigate-to-clean default-view]))))
db)))
(defn load-accounts! [db _]
(let [accounts (->> (accounts/get-accounts)
(map (fn [{:keys [address] :as account}]
[address account]))
(into {}))]
(assoc db :accounts accounts)))
(register-handler :load-accounts load-accounts!)

View File

@ -23,7 +23,8 @@
[status-im.group-settings.screen :refer [group-settings]]
[status-im.profile.screen :refer [profile my-profile]]
[status-im.utils.utils :refer [toast]]
[status-im.utils.encryption]))
[status-im.utils.encryption]
[status-im.utils.logging :as log]))
(defn init-back-button-handler! []
(let [new-listener (fn []
@ -42,7 +43,9 @@
(defn app-root []
(let [signed-up (subscribe [:get :signed-up])
view-id (subscribe [:get :view-id])
account (subscribe [:get :current-account])
keyboard-height (subscribe [:get :keyboard-height])]
(log/debug "Current account: " @account)
(r/create-class
{:component-will-mount
(fn []
@ -64,7 +67,9 @@
#(dispatch [:set :keyboard-height 0]))))
:render
(fn []
(case (if @signed-up @view-id :chat)
(let [startup-view (if @account @view-id (if (= @view-id :login) :login :users))]
(log/debug startup-view)
(case (if @signed-up startup-view :chat)
:discovery [main-tabs]
:discovery-tag [discovery-tag]
:add-participants [new-participants]
@ -80,12 +85,13 @@
:profile [profile]
:users [accounts]
:login [login]
:my-profile [my-profile]))})))
:my-profile [my-profile])))})))
(defn init []
(dispatch-sync [:initialize-db])
(dispatch [:initialize-crypt])
(dispatch [:initialize-geth])
(dispatch [:load-accounts])
(dispatch [:initialize-chats])
;protocol must be initialized after user enters password and we create account
;(dispatch [:initialize-protocol])

View File

@ -12,6 +12,7 @@
(def app-db {:identity-password "replace-me-with-user-entered-password"
:identity "me"
:accounts {}
:current-account false
:contacts []
:contacts-ids #{}
:selected-contacts #{}

View File

@ -79,12 +79,7 @@
(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])))))
(log/debug "Started Node: " result))
(register-handler :initialize-geth
(u/side-effect!

View File

@ -8,16 +8,3 @@
(assoc db :login (merge login login-info)))
(register-handler :set-login-from-qr set-login-from-qr)
(defn go-back
[_ _]
(dispatch [:navigate-back]))
(defn login
[{:keys [login] :as db} [_ _]]
(assoc db :current-account {:address (:address login)}))
(register-handler :login-account
(-> login
((after go-back))))

View File

@ -52,7 +52,7 @@
""])
(defview login []
[{:keys [address]} [:get :login]]
[{:keys [address password]} [:get :login]]
[view st/screen-container
[linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"]
:start [0, 0]
@ -78,6 +78,6 @@
[text {:style st/recover-text} (label :t/recover-from-passphrase)]]]
[view st/connect-button-container
[touchable-highlight
{:on-press #(dispatch [:login-account])}
{:on-press #(dispatch [:login-account address password])}
[view st/connect-button
[text {:style st/connect-button-text} (label :t/connect)]]]]]])

View File

@ -80,3 +80,11 @@
(push-view :profile)))
(register-handler :show-profile show-profile)
(defn navigate-to-clean
[db [_ view-id]]
(-> db
(assoc :navigation-stack (list))
(push-view view-id)))
(register-handler :navigate-to-clean navigate-to-clean)