diff --git a/src/status_im/accounts/db.cljs b/src/status_im/accounts/db.cljs index b7100ae7c1..8b1c068329 100644 --- a/src/status_im/accounts/db.cljs +++ b/src/status_im/accounts/db.cljs @@ -2,6 +2,7 @@ (:require status-im.utils.db status-im.ui.screens.network-settings.db status-im.ui.screens.bootnodes-settings.db + [clojure.string :as string] [cljs.spec.alpha :as spec] [status-im.constants :as const]) (:require-macros [status-im.utils.db :refer [allowed-keys]])) @@ -16,6 +17,11 @@ (defn valid-length? [password] (>= (count password) const/min-password-length)) +(defn account-creation-next-enabled? [{:keys [step password password-confirm name]}] + (or (and password (= :enter-password step) (spec/valid? ::password password)) + (and password-confirm (= :confirm-password step) (spec/valid? ::password password-confirm)) + (and name (= :enter-name step) (not (string/blank? name))))) + (spec/def ::password (spec/and :global/not-empty-string valid-length?)) (spec/def :account/address :global/address) diff --git a/src/status_im/ui/screens/accounts/create/views.cljs b/src/status_im/ui/screens/accounts/create/views.cljs index c9dc0664bf..f8ceeeae1c 100644 --- a/src/status_im/ui/screens/accounts/create/views.cljs +++ b/src/status_im/ui/screens/accounts/create/views.cljs @@ -27,15 +27,15 @@ :input-placeholder (i18n/label :t/name-placeholder) :input-description (i18n/label :t/name-description)}}) -(defview input [{:keys [step error password password-confirm]}] +(defview input [next-enabled? {:keys [step error password password-confirm]}] [text-input/text-input-with-label - {:label (get-in steps [step :input-label]) - :placeholder (get-in steps [step :input-placeholder]) - :on-change-text #(re-frame/dispatch [:accounts.create.ui/input-text-changed (get-in steps [step :input-key]) %]) - :secure-text-entry (boolean (#{:enter-password :confirm-password} step)) - :auto-focus true - :on-submit-editing #(re-frame/dispatch [:accounts.create.ui/next-step-pressed step password password-confirm]) - :error error}]) + (cond-> {:label (get-in steps [step :input-label]) + :placeholder (get-in steps [step :input-placeholder]) + :on-change-text #(re-frame/dispatch [:accounts.create.ui/input-text-changed (get-in steps [step :input-key]) %]) + :secure-text-entry (boolean (#{:enter-password :confirm-password} step)) + :auto-focus true + :error error} + next-enabled? (assoc :on-submit-editing #(re-frame/dispatch [:accounts.create.ui/next-step-pressed step password password-confirm])))]) (defview create-account [] (letsubs [step [:get-in [:accounts/create :step]] @@ -63,10 +63,11 @@ [react/view components.styles/flex [react/view {:style styles/input-container :important-for-accessibility :no-hide-descendants} - [input {:step step - :error error - :password password - :password-confirm password-confirm}] + [input next-enabled? + {:step step + :error error + :password password + :password-confirm password-confirm}] [react/text {:style styles/input-description} (get-in steps [step :input-description])]] [react/view {:style components.styles/flex}] diff --git a/src/status_im/ui/screens/accounts/subs.cljs b/src/status_im/ui/screens/accounts/subs.cljs index 35f41e79cf..d97997eb69 100644 --- a/src/status_im/ui/screens/accounts/subs.cljs +++ b/src/status_im/ui/screens/accounts/subs.cljs @@ -1,6 +1,5 @@ (ns status-im.ui.screens.accounts.subs (:require [re-frame.core :as re-frame] - [clojure.string :as string] [status-im.accounts.db :as db] [status-im.utils.ethereum.core :as ethereum] [cljs.spec.alpha :as spec])) @@ -29,10 +28,7 @@ (re-frame/reg-sub :get-account-creation-next-enabled? (fn [{:accounts/keys [create]}] - (let [{:keys [step password password-confirm name]} create] - (or (and password (= :enter-password step) (spec/valid? ::db/password password)) - (and password-confirm (= :confirm-password step) (spec/valid? ::db/password password-confirm)) - (and name (= :enter-name step) (not (string/blank? name))))))) + (db/account-creation-next-enabled? create))) (re-frame/reg-sub :get-recover-account