fix account switching
This commit is contained in:
parent
04440181b2
commit
753bdbbd4f
|
@ -57,10 +57,14 @@
|
|||
(when is-login-screen? (dispatch [:navigate-to-clean default-view]))))
|
||||
|
||||
(defn logged-in [db address]
|
||||
(let [account (get-in db [:accounts address])]
|
||||
(let [account (get-in db [:accounts address])
|
||||
is-login-screen? (= (:view-id db) :login)
|
||||
new-account? (not is-login-screen?)]
|
||||
(log/debug "Logged in: " address account)
|
||||
(realm/change-account-realm address #(when (nil? %)
|
||||
(initialize-account db account)))))
|
||||
(realm/change-account-realm address new-account?
|
||||
#(if (nil? %)
|
||||
(initialize-account db account)
|
||||
(log/debug "Error changing acount realm: " %)))))
|
||||
|
||||
(register-handler :login-account
|
||||
(-> (fn [db [_ address password]]
|
||||
|
|
|
@ -40,8 +40,9 @@
|
|||
:key row-id}]))
|
||||
|
||||
(defn create-account [event]
|
||||
;(dispatch [:console-create-account])
|
||||
(dispatch-sync [:reset-app])
|
||||
; add accounts screen to history ( maybe there is a better way ? )
|
||||
(dispatch [:navigate-to-clean :accounts])
|
||||
(dispatch [:navigate-to :chat "console"]))
|
||||
|
||||
(defview accounts []
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
[status-im.profile.screen :refer [profile my-profile]]
|
||||
[status-im.utils.utils :refer [toast]]
|
||||
[status-im.utils.encryption]
|
||||
status-im.persistence.realm.core
|
||||
[status-im.utils.logging :as log]))
|
||||
|
||||
(defn init-back-button-handler! []
|
||||
|
|
|
@ -61,8 +61,8 @@
|
|||
:user-identity nil)))
|
||||
|
||||
(register-handler :initialize-account-db
|
||||
(fn [_ _]
|
||||
(assoc app-db
|
||||
(fn [db _]
|
||||
(assoc db
|
||||
:signed-up (storage/get kv/kv-store :signed-up)
|
||||
:password (storage/get kv/kv-store :password))))
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
(when (cljs.core/exists? js/window)
|
||||
(realm-class. (clj->js base))))
|
||||
|
||||
(def account-realm (atom nil))
|
||||
(def account-realm (atom (create-account-realm new-account-filename)))
|
||||
|
||||
(defn is-new-account? []
|
||||
(let [path (.-path @account-realm)
|
||||
|
@ -50,18 +50,21 @@
|
|||
(.write @account-realm #(.deleteAll @account-realm)))
|
||||
|
||||
(defn move-file-handler [address err handler]
|
||||
(log/debug "Moved file with error: " err address)
|
||||
(if err
|
||||
(log/error "Error moving account realm: " (.-message err))
|
||||
(reset! account-realm (create-account-realm address)))
|
||||
(handler err))
|
||||
|
||||
(defn change-account-realm [address handler]
|
||||
(defn change-account-realm [address new-account? handler]
|
||||
(let [path (.-path @account-realm)
|
||||
realm-file (str new-account-filename ".realm")
|
||||
is-new-account? (str/ends-with? path realm-file)]
|
||||
realm-file (str new-account-filename ".realm")]
|
||||
(log/debug "closing account realm: " path)
|
||||
(close-account-realm)
|
||||
(if is-new-account?
|
||||
(log/debug "is new account? " new-account?)
|
||||
(if new-account?
|
||||
(let [new-path (str/replace path realm-file (str address ".realm"))]
|
||||
(log/debug "Moving file to " new-path)
|
||||
(fs/move-file path new-path #(move-file-handler address % handler)))
|
||||
(do
|
||||
(reset! account-realm (create-account-realm address))
|
||||
|
|
Loading…
Reference in New Issue