Skip to content

Commit

Permalink
Remove recovery duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Vlasov committed Sep 13, 2019
1 parent 3a8ca4b commit 1f46e11
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 185 deletions.
2 changes: 2 additions & 0 deletions src/status_im/multiaccounts/create/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
(fx/merge {:db (assoc db :intro-wizard {:step :generate-key
:biometric-auth (:supported-biometric-auth db)
:weak-password? true
:back-action :intro-wizard/step-back-pressed
:forward-action :intro-wizard/step-forward-pressed
:encrypt-with-password? true
:first-time-setup? first-time-setup?})}
(navigation/navigate-to-cofx :intro-wizard nil)))
Expand Down
45 changes: 29 additions & 16 deletions src/status_im/multiaccounts/recover/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
(fx/defn validate-password
{:events [::password-input-blured]}
[{:keys [db]}]
(let [password (get-in db [:multiaccounts/recover :password])]
(let [password (get-in db [:intro-wizard :key-code])]
{:db (assoc-in db [:multiaccounts/recover :password-error] (check-password-errors password))}))

(fx/defn on-store-multiaccount-success
Expand Down Expand Up @@ -95,7 +95,8 @@
(fx/defn store-multiaccount
{:events [::recover-multiaccount-confirmed]}
[{:keys [db] :as cofx}]
(let [{:keys [password passphrase root-key]} (:multiaccounts/recover db)
(let [password (get-in db [:intro-wizard :key-code])
{:keys [passphrase root-key]} (:multiaccounts/recover db)
{:keys [id address]} root-key
callback #(re-frame/dispatch [::store-multiaccount-success password])
hashed-password (ethereum/sha3 (security/safe-unmask-data password))]
Expand Down Expand Up @@ -141,7 +142,7 @@
(navigation/navigate-to-cofx :recover-multiaccount-success nil)))

(fx/defn re-encrypt-pressed
{:events [::re-encrypt-pressed]}
{:events [:multiaccounts.recover/re-encrypt-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (assoc-in db [:intro-wizard :selected-storage-type] :default)}
Expand All @@ -151,7 +152,13 @@
{:events [::enter-phrase-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (assoc db :multiaccounts/recover {:next-button-disabled? true})
{:db (assoc db :multiaccounts/recover {:next-button-disabled? true}
:intro-wizard {:step :select-key-storage
:weak-password? true
:encrypt-with-password? true
:first-time-setup? false
:back-action :multiaccounts.recover/cancel-pressed
:forward-action :multiaccounts.recover/select-storage-next-pressed})
:dispatch [:bottom-sheet/hide-sheet]}
(navigation/navigate-to-cofx :recover-multiaccount-enter-phrase nil)))

Expand All @@ -164,47 +171,53 @@
:password password}})))

(fx/defn cancel-pressed
{:events [::cancel-pressed]}
{:events [:multiaccounts.recover/cancel-pressed]}
[{:keys [db] :as cofx}]
;; Workaround for multiple Cancel button clicks
;; that can break navigation tree
(when-not (#{:multiaccounts :login} (:view-id db))
(navigation/navigate-back cofx)))
(fx/merge cofx
{:db (update-in db [:intro-wizard :step] multiaccounts.create/dec-step)}
navigation/navigate-back)))

(fx/defn select-storage-next-pressed
{:events [::select-storage-next-pressed]
{:events [:multiaccounts.recover/select-storage-next-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [db] :as cofx}]
(let [storage-type (get-in db [:intro-wizard :selected-storage-type])]
(if (= storage-type :advanced)
{:dispatch [:recovery.ui/keycard-option-pressed]})
(navigation/navigate-to-cofx cofx :recover-multiaccount-enter-password nil)))
(fx/merge cofx
{:db (update db :intro-wizard assoc :step :create-code
:forward-action :multiaccounts.recover/enter-password-next-pressed)}
(navigation/navigate-to-cofx :recover-multiaccount-enter-password nil))))

(fx/defn proceed-to-password-confirm
[{:keys [db] :as cofx}]
(when (nil? (get-in db [:multiaccounts/recover :password-error]))
(navigation/navigate-to-cofx cofx :recover-multiaccount-confirm-password nil)))
(fx/merge cofx
{:db (update db :intro-wizard assoc :step :confirm-code
:forward-action :multiaccounts.recover/confirm-password-next-pressed)}
(navigation/navigate-to-cofx :recover-multiaccount-confirm-password nil))))

(fx/defn enter-password-next-button-pressed
{:events [::enter-password-input-submitted
::enter-password-next-pressed]}
{:events [:multiaccounts.recover/enter-password-next-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(validate-password)
(proceed-to-password-confirm)))

(fx/defn confirm-password-next-button-pressed
{:events [::confirm-password-input-submitted
::confirm-password-next-pressed]
{:events [:multiaccounts.recover/confirm-password-next-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [db] :as cofx}]
(let [{:keys [password password-confirmation]} (:multiaccounts/recover db)]
(if (= password password-confirmation)
(let [{:keys [key-code stored-key-code]} (:intro-wizard db)]
(if (= key-code stored-key-code)
(fx/merge cofx
{:db (assoc db :intro-wizard nil)}
(store-multiaccount)
(navigation/navigate-to-cofx :keycard-welcome nil))
{:db (assoc-in db [:multiaccounts/recover :password-error] :password_error1)})))
{:db (assoc-in db [:intro-wizard :confirm-failure?] true)})))

(fx/defn count-words
[{:keys [db]}]
Expand Down
13 changes: 6 additions & 7 deletions src/status_im/ui/screens/intro/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
:width 66 :height 64}])

(defn bottom-bar [{:keys [step generating-keys? weak-password? encrypt-with-password?
forward-action
biometric-auth
processing?] :as wizard-state}]
[react/view {:style {:margin-bottom (if (or (#{:choose-key :select-key-storage} step)
Expand All @@ -255,7 +256,7 @@
:enable-notifications :intro-wizard-title7)]
[components.common/button {:button-style styles/bottom-button
:on-press #(re-frame/dispatch
[:intro-wizard/step-forward-pressed])
[forward-action])
:label (i18n/label label-kw)}])
(and (#{:create-code :confirm-code} step)
(not encrypt-with-password?))
Expand All @@ -267,15 +268,14 @@
:else
[react/view {:style styles/bottom-arrow}
[react/view {:style {:margin-right 10}}
[components.common/bottom-button {:on-press #(re-frame/dispatch
[:intro-wizard/step-forward-pressed])
[components.common/bottom-button {:on-press #(re-frame/dispatch [forward-action])
:disabled? (or processing?
(and (= step :create-code) weak-password?))
:forward? true}]]])
(when (#{:enable-fingerprint :enable-notifications} step)
[components.common/button {:button-style (assoc styles/bottom-button :margin-top 20)
:label (i18n/label :t/maybe-later)
:on-press #(re-frame/dispatch [:intro-wizard/step-forward-pressed {:skip? true}])
:on-press #(re-frame/dispatch [forward-action {:skip? true}])
:background? false}])
(when (= :generate-key step)
[react/text {:style (assoc styles/wizard-text :margin-top 20)}
Expand Down Expand Up @@ -313,16 +313,15 @@
:else nil)]))

(defview wizard []
(letsubs [{:keys [step generating-keys? biometric-auth] :as wizard-state} [:intro-wizard]
(letsubs [{:keys [step generating-keys? biometric-auth back-action] :as wizard-state} [:intro-wizard]
{view-height :height view-width :width} [:dimensions/window]]
[react/keyboard-avoiding-view {:style {:flex 1}}
[toolbar/toolbar
{:style {:border-bottom-width 0
:margin-top 16}}
(when-not (#{:enable-fingerprint :enable-notifications} step)
(toolbar/nav-button
(actions/back #(re-frame/dispatch
[:intro-wizard/step-back-pressed]))))
(actions/back #(re-frame/dispatch [back-action]))))
nil]
[react/view {:style {:flex 1
:justify-content :space-between}}
Expand Down
169 changes: 7 additions & 162 deletions src/status_im/ui/screens/multiaccounts/recover/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
(utils/get-shortened-address pubkey)]]]
[react/view {:margin-bottom 50}
[react/touchable-highlight
{:on-press #(re-frame/dispatch [::multiaccounts.recover/re-encrypt-pressed])}
{:on-press #(re-frame/dispatch [:multiaccounts.recover/re-encrypt-pressed])}
[react/view {:background-color colors/blue-light
:align-items :center
:justify-content :center
Expand All @@ -212,166 +212,11 @@
[react/text {:style {:color colors/blue}}
(i18n/label :t/re-encrypt-key)]]]]]])))

(defview select-storage []
(letsubs [{:keys [selected-storage-type]} [:intro-wizard]
{view-height :height} [:dimensions/window]]
[react/view {:flex 1
:justify-content :space-between
:background-color colors/white}
[toolbar/toolbar
{:transparent? true
:style {:margin-top 32}}
[toolbar/nav-text
{:handler #(re-frame/dispatch [::multiaccounts.recover/cancel-pressed])
:style {:padding-left 21}}
(i18n/label :t/cancel)]
nil]
[react/view {:flex 1
:justify-content :space-between}
[react/view {:flex-direction :column
:align-items :center}
[react/view {:margin-top 16}
[react/text {:style {:typography :header
:text-align :center}}
(i18n/label :t/intro-wizard-title3)]]
[react/view {:margin-top 16
:width "85%"
:align-items :center}
[react/text {:style {:color colors/gray
:text-align :center}}
(i18n/label :t/intro-wizard-text3)]]]
[intro.views/select-key-storage {:selected-storage-type (if config/hardwallet-enabled? selected-storage-type :default)} view-height]
[react/view {:flex-direction :row
:justify-content :space-between
:align-items :center
:width "100%"
:height 86}
[react/view components.styles/flex]
[react/view {:margin-right 20}
[components.common/bottom-button
{:on-press #(re-frame/dispatch [::multiaccounts.recover/select-storage-next-pressed])
:forward? true}]]]]]))
(defn select-storage []
[intro.views/wizard])

(defview enter-password []
(letsubs [{:keys [password password-error]} [:get-recover-multiaccount]]
[react/keyboard-avoiding-view {:flex 1
:justify-content :space-between
:background-color colors/white}
[toolbar/toolbar
{:transparent? true
:style {:margin-top 32}}
[toolbar/nav-text
{:handler #(re-frame/dispatch [::multiaccounts.recover/cancel-pressed])
:style {:padding-left 21}}
(i18n/label :t/cancel)]
[react/text {:style {:color colors/gray}}
(i18n/label :t/step-i-of-n {:step "1"
:number "2"})]]
[react/view {:flex 1
:flex-direction :column
:justify-content :space-between
:align-items :center}
[react/view {:flex-direction :column
:align-items :center}
[react/view {:margin-top 16}
[react/text {:style {:typography :header
:text-align :center}}
(i18n/label :t/intro-wizard-title-alt4)]]
[react/view {:margin-top 16
:width "85%"
:align-items :center}
[react/text {:style {:color colors/gray
:text-align :center}}
(i18n/label :t/password-description)]]
[react/view {:margin-top 16}
[text-input/text-input-with-label
{:on-change-text #(re-frame/dispatch [::multiaccounts.recover/enter-password-input-changed (security/mask-data %)])
:auto-focus true
:on-submit-editing #(re-frame/dispatch [::multiaccounts.recover/enter-password-input-submitted])
:secure-text-entry true
:error (when password-error (i18n/label password-error))
:placeholder nil
:height 125
:multiline false
:auto-correct false
:container {:background-color :white
:min-width "50%"}
:style {:background-color :white
:width 200
:text-align :center
:font-size 20
:font-weight "700"}}]]]
[react/view {:flex-direction :row
:justify-content :space-between
:align-items :center
:width "100%"
:height 86}
[react/view]
[react/view {:margin-right 20}
[components.common/bottom-button
{:on-press #(re-frame/dispatch [::multiaccounts.recover/enter-password-next-pressed])
:label (i18n/label :t/next)
:disabled? (empty? password)
:forward? true}]]]]]))
(defn enter-password []
[intro.views/wizard])

(defview confirm-password []
(letsubs [{:keys [password-confirmation password-error]} [:get-recover-multiaccount]]
[react/keyboard-avoiding-view {:flex 1
:justify-content :space-between
:background-color colors/white}
[toolbar/toolbar
{:transparent? true
:style {:margin-top 32}}
[toolbar/nav-text
{:handler #(re-frame/dispatch [::multiaccounts.recover/cancel-pressed])
:style {:padding-left 21}}
(i18n/label :t/cancel)]
[react/text {:style {:color colors/gray}}
(i18n/label :t/step-i-of-n {:step "1"
:number "2"})]]
[react/view {:flex 1
:flex-direction :column
:justify-content :space-between
:align-items :center}
[react/view {:flex-direction :column
:align-items :center}
[react/view {:margin-top 16}
[react/text {:style {:typography :header
:text-align :center}}
(i18n/label :t/intro-wizard-title-alt5)]]
[react/view {:margin-top 16
:width "85%"
:align-items :center}
[react/text {:style {:color colors/gray
:text-align :center}}
(i18n/label :t/password-description)]]
[react/view {:margin-top 16}
[text-input/text-input-with-label
{:on-change-text #(re-frame/dispatch [::multiaccounts.recover/confirm-password-input-changed %])
:auto-focus true
:on-submit-editing #(re-frame/dispatch [::multiaccounts.recover/confirm-password-input-submitted])
:error (when password-error (i18n/label password-error))
:secure-text-entry true
:placeholder nil
:height 125
:multiline false
:auto-correct false
:container {:background-color :white
:min-width "50%"}
:style {:background-color :white
:width 200
:text-align :center
:font-size 20
:font-weight "700"}}]]]
[react/view {:flex-direction :row
:justify-content :space-between
:align-items :center
:width "100%"
:height 86}
[react/view]
[react/view {:margin-right 20}
[components.common/bottom-button
{:on-press #(re-frame/dispatch [::multiaccounts.recover/confirm-password-next-pressed])
:label (i18n/label :t/next)
:disabled? (empty? password-confirmation)
:forward? true}]]]]]))
(defn confirm-password []
[intro.views/wizard])

0 comments on commit 1f46e11

Please sign in to comment.