diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 7525fe61be..88aeabb432 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -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] - (log/debug "Logged in account: " address result) - (dispatch [:set :current-account (get-in db [:accounts address])]))) + (let [account (get-in db [:accounts address])] + (log/debug "Logged in account: " address result) + (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!) \ No newline at end of file diff --git a/src/status_im/accounts/views/user.cljs b/src/status_im/accounts/views/account.cljs similarity index 100% rename from src/status_im/accounts/views/user.cljs rename to src/status_im/accounts/views/account.cljs diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index bc6406e039..e591c69abb 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -8,7 +8,7 @@ [status-im.components.react :refer [navigator app-registry device-event-emitter orientation]] [status-im.components.main-tabs :refer [main-tabs]] - [status-im.contacts.views.contact-list :refer [contact-list] ] + [status-im.contacts.views.contact-list :refer [contact-list]] [status-im.contacts.views.new-contact :refer [new-contact]] [status-im.qr-scanner.screen :refer [qr-scanner]] [status-im.discovery.screen :refer [discovery]] @@ -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]) diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 9d1cc6fa5d..8eefb216ad 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -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 #{} diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index ee070f1ceb..0a6f9b2dda 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -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! diff --git a/src/status_im/login/handlers.cljs b/src/status_im/login/handlers.cljs index 62315642bd..79c6944d31 100644 --- a/src/status_im/login/handlers.cljs +++ b/src/status_im/login/handlers.cljs @@ -7,17 +7,4 @@ [{:keys [login] :as db} [_ _ login-info]] (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)))) \ No newline at end of file +(register-handler :set-login-from-qr set-login-from-qr) \ No newline at end of file diff --git a/src/status_im/login/screen.cljs b/src/status_im/login/screen.cljs index e8974cffff..eef2ff99cc 100644 --- a/src/status_im/login/screen.cljs +++ b/src/status_im/login/screen.cljs @@ -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)]]]]]]) diff --git a/src/status_im/navigation/handlers.cljs b/src/status_im/navigation/handlers.cljs index db33411902..5d61fe3163 100644 --- a/src/status_im/navigation/handlers.cljs +++ b/src/status_im/navigation/handlers.cljs @@ -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)