diff --git a/src/status_im/accounts/login/core.cljs b/src/status_im/accounts/login/core.cljs index 30b0593ef5..d8d23cbb5d 100644 --- a/src/status_im/accounts/login/core.cljs +++ b/src/status_im/accounts/login/core.cljs @@ -14,7 +14,8 @@ [status-im.protocol.core :as protocol] [status-im.models.wallet :as models.wallet] [status-im.models.transactions :as transactions] - [status-im.i18n :as i18n])) + [status-im.i18n :as i18n] + [status-im.node.core :as node])) ;; login flow: ;; @@ -126,21 +127,25 @@ :on-accept #(re-frame/dispatch [:init.ui/account-data-reset-accepted address])}})) (fx/defn verify-callback - [{:keys [db] :as cofx} verify-result realm-error] + [cofx verify-result realm-error] (let [data (types/json->clj verify-result) error (:error data) success (empty? error)] - (if success - (case (:error realm-error) - :decryption-failed - (show-migration-error-dialog cofx realm-error) + (fx/merge + cofx + {:node/stop nil} + (fn [{:keys [db] :as cofx}] + (if success + (case (:error realm-error) + :decryption-failed + (show-migration-error-dialog cofx realm-error) - :database-does-not-exist - (let [{:keys [address password]} (accounts.db/credentials cofx)] - {:data-store/change-account [address password true]})) - {:db (update db :accounts/login assoc - :error error - :processing false)}))) + :database-does-not-exist + (let [{:keys [address password]} (accounts.db/credentials cofx)] + {:data-store/change-account [address password true]})) + {:db (update db :accounts/login assoc + :error error + :processing false)}))))) (fx/defn handle-change-account-error [{:keys [db] :as cofx} error] @@ -148,7 +153,7 @@ (if (map? error) error {:message (str error)}) - {:keys [address password]} (accounts.db/credentials cofx) + {:keys [address]} (accounts.db/credentials cofx) erase-button (i18n/label :migrations-erase-accounts-data-button)] (case error :migrations-failed @@ -168,12 +173,12 @@ :on-accept #(re-frame/dispatch [:init.ui/account-data-reset-accepted address])}}) - :database-does-not-exist - {:accounts.login/verify [address password realm-error]} - - :decryption-failed - ;; check if decryption failed because of wrong password - {:accounts.login/verify [address password realm-error]} + (:database-does-not-exist :decryption-failed) + (fx/merge cofx + {:db (-> db + (assoc :node/on-ready :verify-account) + (assoc :realm-error realm-error))} + (node/initialize nil)) {:ui/show-confirmation {:title (i18n/label :unknown-realm-error) diff --git a/src/status_im/init/core.cljs b/src/status_im/init/core.cljs index 1b3511d2e5..59c8f0b61e 100644 --- a/src/status_im/init/core.cljs +++ b/src/status_im/init/core.cljs @@ -150,7 +150,7 @@ :keys [accounts/accounts accounts/create networks/networks network network-status peers-count peers-summary view-id navigation-stack status-module-initialized? device-UUID semaphores accounts/login] - :node/keys [status] + :node/keys [status on-ready] :or {network (get app-db :network)}} db current-account (get accounts address) account-network-id (get current-account :network network) @@ -160,6 +160,7 @@ :navigation-stack navigation-stack :status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?) :node/status status + :node/on-ready on-ready :accounts/create create :networks/networks networks :account/account current-account diff --git a/src/status_im/node/core.cljs b/src/status_im/node/core.cljs index 47c38d8e2a..2318d8ffff 100644 --- a/src/status_im/node/core.cljs +++ b/src/status_im/node/core.cljs @@ -125,6 +125,16 @@ :always (add-log-level log-level)))) +(defn get-verify-account-config + "Is used when the node has to be started before + `VerifyAccountPassword` call." + [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 @@ -142,7 +152,9 @@ (let [network (if address (get-account-network db address) (:network db)) - node-config (get-account-node-config db address) + node-config (if (= (:node/on-ready db) :verify-account) + (get-verify-account-config db network) + (get-account-node-config db address)) node-config-json (types/clj->json node-config)] (log/info "Node config: " node-config-json) {:db (assoc db diff --git a/src/status_im/signals/core.cljs b/src/status_im/signals/core.cljs index 30b4b35ca8..c09ec74105 100644 --- a/src/status_im/signals/core.cljs +++ b/src/status_im/signals/core.cljs @@ -14,9 +14,7 @@ (fx/defn status-node-started [{db :db :as cofx}] (let [{:node/keys [restart? address on-ready] - :accounts/keys [create]} db - can-login? (and (not restart?) - (:password (accounts.db/credentials cofx)))] + :accounts/keys [create]} db] (fx/merge cofx {:db (-> db (assoc :node/status :started) @@ -25,12 +23,18 @@ (when restart? (node/initialize address)) - (when can-login? - (accounts.login/login)) - (when (= :create-account on-ready) + (case on-ready + :login + (accounts.login/login) + :verify-account + (let [{:keys [address password]} (accounts.db/credentials cofx)] + (fn [_] + {:accounts.login/verify + [address password (:realm-error db)]})) + :create-account (fn [_] - {:accounts.create/create-account (:password create)})) - (when (= :recover-account on-ready) + {:accounts.create/create-account (:password create)}) + :recover-account (fn [{:keys [db]}] (let [{:keys [password passphrase]} (:accounts/recover db)] {:accounts.recover/recover-account diff --git a/src/status_im/ui/screens/accounts/login/views.cljs b/src/status_im/ui/screens/accounts/login/views.cljs index 5ba1c29f0d..403fd1dd9d 100644 --- a/src/status_im/ui/screens/accounts/login/views.cljs +++ b/src/status_im/ui/screens/accounts/login/views.cljs @@ -55,9 +55,10 @@ name]]]) (defview login [] - (letsubs [{:keys [address photo-path name password error processing save-password? can-save-password?]} [:get :accounts/login] + (letsubs [{:keys [photo-path name error processing save-password? can-save-password?]} [:get :accounts/login] can-navigate-back? [:can-navigate-back?] - password-text-input (atom nil)] + password-text-input (atom nil) + sign-in-enabled? [:sign-in-enabled?]] [react/keyboard-avoiding-view {:style ast/accounts-view} [status-bar/status-bar] [login-toolbar can-navigate-back?] @@ -72,7 +73,8 @@ :placeholder (i18n/label :t/password) :ref #(reset! password-text-input %) :auto-focus true - :on-submit-editing #(login-account @password-text-input) + :on-submit-editing (when sign-in-enabled? + #(login-account @password-text-input)) :on-change-text #(do (re-frame/dispatch [:set-in [:accounts/login :password] (security/mask-data %)]) @@ -82,11 +84,11 @@ (when platform/ios? [react/view {:style styles/save-password-checkbox-container} [profile.components/settings-switch-item - {:label-kw (if can-save-password? - :t/save-password - :t/save-password-unavailable) - :active? can-save-password? - :value save-password? + {:label-kw (if can-save-password? + :t/save-password + :t/save-password-unavailable) + :active? can-save-password? + :value save-password? :action-fn #(re-frame/dispatch [:set-in [:accounts/login :save-password?] %])}]])]] (when processing [react/view styles/processing-view @@ -102,5 +104,5 @@ [components.common/bottom-button {:forward? true :label (i18n/label :t/sign-in) - :disabled? (not (spec/valid? ::db/password (security/safe-unmask-data password))) + :disabled? (not sign-in-enabled?) :on-press #(login-account @password-text-input)}]])])) diff --git a/src/status_im/ui/screens/accounts/subs.cljs b/src/status_im/ui/screens/accounts/subs.cljs index 93624a5bbf..c8ad0708cf 100644 --- a/src/status_im/ui/screens/accounts/subs.cljs +++ b/src/status_im/ui/screens/accounts/subs.cljs @@ -2,7 +2,8 @@ (:require [re-frame.core :as re-frame] [status-im.accounts.db :as db] [status-im.utils.ethereum.core :as ethereum] - [cljs.spec.alpha :as spec])) + [cljs.spec.alpha :as spec] + [status-im.utils.security :as security])) (re-frame/reg-sub :accounts/accounts @@ -40,3 +41,12 @@ :get-recover-account (fn [db] (:accounts/recover db))) + +(re-frame/reg-sub + :sign-in-enabled? + :<- [:get :accounts/login] + :<- [:get :node/status] + (fn [[{:keys [password]} status]] + (and (or (nil? status) (= status :stopped)) + (spec/valid? ::db/password + (security/safe-unmask-data password)))))