[#6952] Fix odd app behavior after quick logout
This commit changes the way how/when the node is started/stopped: 1. `node` is not started on the app startup 2. When the user presses "Sign in" button the node is started with user specific configs (`InstallationID`, custom bootnodes, etc), and only after that `Login` call is performed. 3. When the user creates a new account, at first the node is started with default params (the same as would be used when user signs into the app after account creation whithout changing any setting), then `CreateAccount` call happens, then `Login`. 4. When the user restores their account, the flow is the same as `3` but with `RecoverAccount` instead of `CreateAccount` 5. When the user logs out the node is stopped. That's it.
This commit is contained in:
parent
52b7bcd291
commit
07e8f6908d
|
@ -19,7 +19,8 @@
|
|||
[status-im.utils.signing-phrase.core :as signing-phrase]
|
||||
[status-im.utils.types :as types]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.fx :as fx]))
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.node.core :as node]))
|
||||
|
||||
(defn get-signing-phrase [cofx]
|
||||
(assoc cofx :signing-phrase (signing-phrase/generate)))
|
||||
|
@ -33,10 +34,17 @@
|
|||
#(re-frame/dispatch [:accounts.create.callback/create-account-success (types/json->clj %) password])))
|
||||
|
||||
;;;; Handlers
|
||||
|
||||
(defn create-account [{{:accounts/keys [create] :as db} :db}]
|
||||
{:db (update db :accounts/create assoc :step :account-creating :error nil)
|
||||
:accounts.create/create-account (:password create)})
|
||||
(defn create-account
|
||||
[{:keys [db random-guid-generator] :as cofx}]
|
||||
(fx/merge
|
||||
cofx
|
||||
{:db (-> db
|
||||
(update :accounts/create assoc
|
||||
:step :account-creating
|
||||
:error nil)
|
||||
(assoc :node/on-ready :create-account
|
||||
:accounts/new-installation-id (random-guid-generator)))}
|
||||
(node/initialize nil)))
|
||||
|
||||
(fx/defn add-account
|
||||
"Takes db and new account, creates map of effects describing adding account to database and realm"
|
||||
|
@ -51,14 +59,13 @@
|
|||
:data-store/base-tx [(accounts-store/save-account-tx enriched-account)]}))
|
||||
|
||||
(fx/defn on-account-created
|
||||
[{:keys [random-guid-generator
|
||||
signing-phrase
|
||||
[{:keys [signing-phrase
|
||||
status
|
||||
db] :as cofx}
|
||||
{:keys [pubkey address mnemonic]} password seed-backed-up]
|
||||
{:keys [pubkey address mnemonic installation-id]} password seed-backed-up]
|
||||
(let [normalized-address (utils.hex/normalize-hex address)
|
||||
account {:public-key pubkey
|
||||
:installation-id (random-guid-generator)
|
||||
:installation-id (or installation-id (get-in db [:accounts/new-installation-id]))
|
||||
:address normalized-address
|
||||
:name (gfycat/generate-gfy pubkey)
|
||||
:status status
|
||||
|
@ -72,11 +79,11 @@
|
|||
(log/debug "account-created")
|
||||
(when-not (string/blank? pubkey)
|
||||
(fx/merge cofx
|
||||
{:db (assoc db :accounts/login {:address normalized-address
|
||||
:password password
|
||||
{:db (assoc db :accounts/login {:address normalized-address
|
||||
:password password
|
||||
:processing true})}
|
||||
(add-account account)
|
||||
(accounts.login/user-login)))))
|
||||
(accounts.login/user-login true)))))
|
||||
|
||||
(defn reset-account-creation [{db :db}]
|
||||
{:db (update db :accounts/create assoc
|
||||
|
|
|
@ -55,14 +55,16 @@
|
|||
(models.wallet/update-wallet)
|
||||
(transactions/start-sync)))
|
||||
|
||||
(fx/defn user-login [{:keys [db] :as cofx}]
|
||||
(fx/defn user-login [{:keys [db] :as cofx} create-database?]
|
||||
(let [{:keys [address password save-password?]} (accounts.db/credentials cofx)]
|
||||
(fx/merge
|
||||
cofx
|
||||
(merge
|
||||
{:db (assoc-in db [:accounts/login :processing] true)
|
||||
{:db (-> db
|
||||
(assoc-in [:accounts/login :processing] true)
|
||||
(assoc :node/on-ready :login))
|
||||
:accounts.login/clear-web-data nil
|
||||
:data-store/change-account [address password false]}
|
||||
:data-store/change-account [address password create-database?]}
|
||||
(when save-password?
|
||||
{:keychain/save-user-password [address password]})))))
|
||||
|
||||
|
@ -199,7 +201,7 @@
|
|||
(fx/merge cofx
|
||||
{:db (assoc-in db [:accounts/login :password] password)}
|
||||
(navigation/navigate-to-cofx :progress nil)
|
||||
(user-login))
|
||||
(user-login false))
|
||||
(navigation/navigate-to-clean cofx :login nil)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
|
|
|
@ -2,20 +2,21 @@
|
|||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.transport.core :as transport]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.models.transactions :as transactions]))
|
||||
[status-im.models.transactions :as transactions]
|
||||
[status-im.node.core :as node]
|
||||
[status-im.init.core :as init]))
|
||||
|
||||
(fx/defn logout
|
||||
[{:keys [db] :as cofx}]
|
||||
(let [{:transport/keys [chats]} db]
|
||||
(fx/merge cofx
|
||||
{:keychain/clear-user-password (get-in db [:account/account :address])
|
||||
:dev-server/stop nil
|
||||
:keychain/get-encryption-key [:init.callback/get-encryption-key-success]}
|
||||
(transactions/stop-sync)
|
||||
(navigation/navigate-to-clean :login {})
|
||||
(transport/stop-whisper))))
|
||||
(fx/merge cofx
|
||||
{:keychain/clear-user-password (get-in db [:account/account :address])
|
||||
:dev-server/stop nil}
|
||||
(transactions/stop-sync)
|
||||
(transport/stop-whisper)
|
||||
(init/initialize-app-db)
|
||||
(init/load-accounts-and-initialize-views)
|
||||
(node/stop)))
|
||||
|
||||
(fx/defn show-logout-confirmation [_]
|
||||
{:ui/show-confirmation
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.utils.security :as security]
|
||||
[status-im.utils.types :as types]
|
||||
[status-im.utils.fx :as fx]))
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.node.core :as node]))
|
||||
|
||||
(defn check-password-errors [password]
|
||||
(cond (string/blank? password) :required-field
|
||||
|
@ -80,10 +81,15 @@
|
|||
{:db (dissoc db :accounts/recover)}
|
||||
(validate-recover-result data password))))
|
||||
|
||||
(fx/defn recover-account [{:keys [db]}]
|
||||
(let [{:keys [password passphrase]} (:accounts/recover db)]
|
||||
{:db (assoc-in db [:accounts/recover :processing?] true)
|
||||
:accounts.recover/recover-account [(security/mask-data passphrase) password]}))
|
||||
(fx/defn recover-account
|
||||
[{:keys [db random-guid-generator] :as cofx}]
|
||||
(fx/merge
|
||||
cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:accounts/recover :processing?] true)
|
||||
(assoc :node/on-ready :recover-account)
|
||||
(assoc :accounts/new-installation-id (random-guid-generator)))}
|
||||
(node/initialize nil)))
|
||||
|
||||
(fx/defn recover-account-with-checks [{:keys [db] :as cofx}]
|
||||
(let [{:keys [passphrase processing?]} (:accounts/recover db)]
|
||||
|
|
|
@ -118,10 +118,13 @@
|
|||
(re-frame/inject-cofx :data-store/all-browsers)
|
||||
(re-frame/inject-cofx :data-store/all-dapp-permissions)]
|
||||
(fn [{:keys [db] :as cofx} [_ address]]
|
||||
(fx/merge
|
||||
cofx
|
||||
(node/initialize (get-in db [:accounts/login :address]))
|
||||
(init/initialize-account address))))
|
||||
(let [{:node/keys [status]} db]
|
||||
(fx/merge
|
||||
cofx
|
||||
(if (= status :started)
|
||||
(accounts.login/login)
|
||||
(node/initialize (get-in db [:accounts/login :address])))
|
||||
(init/initialize-account address)))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:init.callback/keychain-reset
|
||||
|
@ -176,6 +179,7 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:accounts.create.ui/next-step-pressed
|
||||
[(re-frame/inject-cofx :random-guid-generator)]
|
||||
(fn [cofx [_ step password password-confirm]]
|
||||
(accounts.create/next-step cofx step password password-confirm)))
|
||||
|
||||
|
@ -231,11 +235,13 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:accounts.recover.ui/sign-in-button-pressed
|
||||
[(re-frame/inject-cofx :random-guid-generator)]
|
||||
(fn [cofx _]
|
||||
(accounts.recover/recover-account-with-checks cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:accounts.recover.ui/recover-account-confirmed
|
||||
[(re-frame/inject-cofx :random-guid-generator)]
|
||||
(fn [cofx _]
|
||||
(accounts.recover/recover-account cofx)))
|
||||
|
||||
|
@ -252,7 +258,7 @@
|
|||
(handlers/register-handler-fx
|
||||
:accounts.login.ui/password-input-submitted
|
||||
(fn [cofx _]
|
||||
(accounts.login/user-login cofx)))
|
||||
(accounts.login/user-login cofx false)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:accounts.login.callback/login-success
|
||||
|
@ -293,6 +299,7 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:accounts.logout.ui/logout-confirmed
|
||||
[(re-frame/inject-cofx :data-store/get-all-accounts)]
|
||||
(fn [cofx _]
|
||||
(accounts.logout/logout cofx)))
|
||||
|
||||
|
@ -300,6 +307,7 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:accounts.update.callback/save-settings-success
|
||||
[(re-frame/inject-cofx :data-store/get-all-accounts)]
|
||||
(fn [cofx _]
|
||||
(accounts.logout/logout cofx)))
|
||||
|
||||
|
|
|
@ -99,8 +99,7 @@
|
|||
[cofx encryption-key]
|
||||
(fx/merge cofx
|
||||
{:init/init-store encryption-key}
|
||||
(initialize-app-db)
|
||||
(node/initialize nil)))
|
||||
(initialize-app-db)))
|
||||
|
||||
(fx/defn set-device-uuid
|
||||
[{:keys [db]} device-uuid]
|
||||
|
|
|
@ -77,11 +77,13 @@
|
|||
current-fleet-key (fleet/current-fleet db address)
|
||||
current-fleet (get fleet/fleets current-fleet-key)
|
||||
rendezvous-nodes (pick-nodes 3 (vals (:rendezvous current-fleet)))
|
||||
{:keys [network
|
||||
installation-id
|
||||
settings
|
||||
bootnodes
|
||||
networks]} (get accounts address)
|
||||
{:keys [network installation-id settings bootnodes networks]}
|
||||
(merge
|
||||
{:network config/default-network
|
||||
:networks (:networks/networks db)
|
||||
:settings (constants/default-account-settings)
|
||||
:installation-id (get db :accounts/new-installation-id)}
|
||||
(get accounts address))
|
||||
use-custom-bootnodes (get-in settings [:bootnodes network])
|
||||
log-level (or (:log-level settings)
|
||||
config/log-level-status-go)]
|
||||
|
@ -122,13 +124,6 @@
|
|||
:always
|
||||
(add-log-level log-level))))
|
||||
|
||||
(defn get-node-config [db network]
|
||||
(-> (get-in (:networks/networks db) [network :config])
|
||||
(get-base-node-config)
|
||||
(assoc :PFSEnabled false
|
||||
:NoDiscovery true)
|
||||
(add-log-level config/log-level-status-go)))
|
||||
|
||||
(fx/defn update-sync-state
|
||||
[{:keys [db]} error sync-state]
|
||||
{:db (assoc db :node/chain-sync-state
|
||||
|
@ -146,9 +141,7 @@
|
|||
(let [network (if address
|
||||
(get-account-network db address)
|
||||
(:network db))
|
||||
node-config (if address
|
||||
(get-account-node-config db address)
|
||||
(get-node-config db network))
|
||||
node-config (get-account-node-config db address)
|
||||
node-config-json (types/clj->json node-config)]
|
||||
(log/info "Node config: " node-config-json)
|
||||
{:db (assoc db
|
||||
|
@ -156,7 +149,7 @@
|
|||
:node/status :starting)
|
||||
:node/start node-config-json}))
|
||||
|
||||
(defn stop
|
||||
(fx/defn stop
|
||||
[{:keys [db]}]
|
||||
{:db (assoc db :node/status :stopping)
|
||||
:node/stop nil})
|
||||
|
@ -165,7 +158,7 @@
|
|||
[{{:node/keys [status] :as db} :db :as cofx} address]
|
||||
(let [restart {:db (assoc db :node/restart? true :node/address address)}]
|
||||
(case status
|
||||
:started (stop cofx)
|
||||
:started nil
|
||||
:starting (do
|
||||
(when utils.platform/desktop?
|
||||
(status/stop-node))
|
||||
|
|
|
@ -8,11 +8,13 @@
|
|||
[status-im.transport.message.core :as transport.message]
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.utils.types :as types]
|
||||
[taoensso.timbre :as log]))
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.security :as security]))
|
||||
|
||||
(fx/defn status-node-started
|
||||
[{db :db :as cofx}]
|
||||
(let [{:node/keys [restart? address]} db
|
||||
(let [{:node/keys [restart? address on-ready]
|
||||
:accounts/keys [create]} db
|
||||
can-login? (and (not restart?)
|
||||
(:password (accounts.db/credentials cofx)))]
|
||||
(fx/merge cofx
|
||||
|
@ -24,14 +26,19 @@
|
|||
(when restart?
|
||||
(node/initialize address))
|
||||
(when can-login?
|
||||
(accounts.login/login)))))
|
||||
(accounts.login/login))
|
||||
(when (= :create-account on-ready)
|
||||
(fn [_]
|
||||
{:accounts.create/create-account (:password create)}))
|
||||
(when (= :recover-account on-ready)
|
||||
(fn [{:keys [db]}]
|
||||
(let [{:keys [password passphrase]} (:accounts/recover db)]
|
||||
{:accounts.recover/recover-account
|
||||
[(security/mask-data passphrase) password]}))))))
|
||||
|
||||
(fx/defn status-node-stopped
|
||||
[{db :db :as cofx}]
|
||||
(let [{:keys [address]} (accounts.db/credentials cofx)]
|
||||
(fx/merge cofx
|
||||
{:db (assoc db :node/status :stopped)}
|
||||
(node/start address))))
|
||||
[{db :db}]
|
||||
{:db (assoc db :node/status :stopped)})
|
||||
|
||||
(fx/defn status-module-initialized [{:keys [db]}]
|
||||
{:db (assoc db :status-module-initialized? true)
|
||||
|
|
|
@ -95,29 +95,24 @@
|
|||
(models/validate-password {:db {:accounts/recover {:password "thisisapaswoord"}}}))))
|
||||
|
||||
(deftest recover-account
|
||||
(let [new-cofx (models/recover-account {:db {:accounts/recover
|
||||
(let [new-cofx (models/recover-account {:random-guid-generator (constantly "random")
|
||||
:db {:accounts/recover
|
||||
{:passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater"
|
||||
:password "thisisapaswoord"}}})]
|
||||
(is (= {:accounts/recover {:passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater"
|
||||
:password "thisisapaswoord"
|
||||
:processing? true}}
|
||||
(:db new-cofx)))
|
||||
(is (= security/MaskedData
|
||||
(-> new-cofx :accounts.recover/recover-account first type)))
|
||||
(is (= "thisisapaswoord" (-> new-cofx :accounts.recover/recover-account second)))))
|
||||
(is (contains? new-cofx :node/start))
|
||||
(is (= "random" (get-in new-cofx [:db :accounts/new-installation-id])))
|
||||
(is (= :recover-account (get-in new-cofx [:db :node/on-ready])))))
|
||||
|
||||
(deftest recover-account-with-checks
|
||||
(let [new-cofx (models/recover-account-with-checks {:db {:accounts/recover
|
||||
(let [new-cofx (models/recover-account-with-checks {:random-guid-generator (constantly "random")
|
||||
:db {:accounts/recover
|
||||
{:passphrase "game buzz method pretty olympic fat quit display velvet unveil marine crater"
|
||||
:password "thisisapaswoord"}}})]
|
||||
(is (= {:accounts/recover {:passphrase "game buzz method pretty olympic fat quit display velvet unveil marine crater"
|
||||
:password "thisisapaswoord"
|
||||
:processing? true}}
|
||||
(:db new-cofx)))
|
||||
(is (= security/MaskedData
|
||||
(-> new-cofx :accounts.recover/recover-account first type)))
|
||||
(is (= "thisisapaswoord" (-> new-cofx :accounts.recover/recover-account second))))
|
||||
(let [new-cofx (models/recover-account-with-checks {:db {:accounts/recover
|
||||
(is (contains? new-cofx :node/start))
|
||||
(is (= "random" (get-in new-cofx [:db :accounts/new-installation-id])))
|
||||
(is (= :recover-account (get-in new-cofx [:db :node/on-ready]))))
|
||||
(let [new-cofx (models/recover-account-with-checks {:random-guid-generator (constantly "random")
|
||||
:db {:accounts/recover
|
||||
{:passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater"
|
||||
:password "thisisapaswoord"}}})]
|
||||
(is (= (i18n/label :recovery-typo-dialog-title) (-> new-cofx :ui/show-confirmation :title)))
|
||||
|
|
|
@ -13,34 +13,18 @@
|
|||
(let [address "a"
|
||||
cofx {:db {:accounts/accounts {address {:installation-id "id"}}}}]
|
||||
(testing "installation-id"
|
||||
(testing "the user is not logged in"
|
||||
(let [actual (parse-node-config (node/start cofx nil))]
|
||||
(is (not (:InstallationID actual)))))
|
||||
(testing "the user is logged in"
|
||||
(let [actual (parse-node-config (node/start cofx address))]
|
||||
(is (= "id" (:InstallationID actual))))))
|
||||
(let [actual (parse-node-config (node/start cofx address))]
|
||||
(is (= "id" (:InstallationID actual)))))
|
||||
(testing "pfs & group chats disabled"
|
||||
(with-redefs [config/pfs-encryption-enabled? false
|
||||
config/group-chats-enabled? false]
|
||||
(testing "the user is not logged in"
|
||||
(let [actual (parse-node-config (node/start cofx nil))]
|
||||
(is (not (:PFSEnabled actual)))))
|
||||
(testing "the user is logged in"
|
||||
(let [actual (parse-node-config (node/start cofx address))]
|
||||
(is (not (:PFSEnabled actual))))))
|
||||
(let [actual (parse-node-config (node/start cofx address))]
|
||||
(is (not (:PFSEnabled actual)))))
|
||||
(testing "pfs is enabled"
|
||||
(with-redefs [config/pfs-encryption-enabled? true]
|
||||
(testing "the user is not logged in"
|
||||
(let [actual (parse-node-config (node/start cofx nil))]
|
||||
(is (not (:PFSEnabled actual)))))
|
||||
(testing "the user is logged in"
|
||||
(let [actual (parse-node-config (node/start cofx address))]
|
||||
(is (:PFSEnabled actual))))))
|
||||
(let [actual (parse-node-config (node/start cofx address))]
|
||||
(is (:PFSEnabled actual)))))
|
||||
(testing "group chats is enabled"
|
||||
(with-redefs [config/group-chats-enabled? true]
|
||||
(testing "the user is not logged in"
|
||||
(let [actual (parse-node-config (node/start cofx nil))]
|
||||
(is (not (:PFSEnabled actual)))))
|
||||
(testing "the user is logged in"
|
||||
(let [actual (parse-node-config (node/start cofx address))]
|
||||
(is (:PFSEnabled actual)))))))))
|
||||
(let [actual (parse-node-config (node/start cofx address))]
|
||||
(is (:PFSEnabled actual))))))))
|
||||
|
|
Loading…
Reference in New Issue