Skip to content

Commit

Permalink
recovery flow v1
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryn committed Aug 1, 2019
1 parent 79f2eed commit a992034
Show file tree
Hide file tree
Showing 13 changed files with 464 additions and 82 deletions.
3 changes: 3 additions & 0 deletions resources/icons/main/keycard-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 3 additions & 15 deletions src/status_im/hardwallet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,18 @@
(navigation/navigate-to-cofx :keycard-recovery-enter-mnemonic nil)))

(fx/defn recover-with-keycard-pressed
{:events [:recovery.ui/recover-with-keycard-pressed]}
{:events [:recover.ui/recover-with-keycard-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (assoc-in db [:hardwallet :flow] :import)
:dispatch [:bottom-sheet/hide-sheet]
:hardwallet/check-nfc-enabled nil}
(navigation/navigate-to-cofx :keycard-recovery-intro nil)))

(fx/defn access-key-pressed
{:events [:multiaccounts.recover.ui/recover-multiaccount-button-pressed]}
[cofx]
(multiaccounts.recover/navigate-to-recover-multiaccount-screen cofx))
{:dispatch [:bottom-sheet/show-sheet :recover-sheet]})

(fx/defn recovery-keycard-selected
{:events [:recovery.ui/keycard-option-pressed]}
Expand All @@ -437,19 +438,6 @@
:hardwallet/check-nfc-enabled nil}
(navigation/navigate-to-cofx :keycard-onboarding-intro nil)))

;NOTE to be removed when Recovery flow will be implemented
(fx/defn enter-mnemonic-next-button-pressed
{:events [:keycard.recovery.enter-mnemonic.ui/input-submitted
:keycard.recovery.enter-mnemonic.ui/next-pressed]}
[cofx]
(recovery-keycard-selected cofx))

;NOTE to be removed when Recovery flow will be implemented
(fx/defn enter-mnemonic-input-changed
{:events [:keycard.recovery.enter-mnemonic.ui/input-changed]}
[{:keys [db]} input]
{:db (assoc-in db [:hardwallet :secrets :mnemonic] input)})

(fx/defn password-option-pressed
[{:keys [db] :as cofx}]
(if (= (get-in db [:hardwallet :flow]) :create)
Expand Down
4 changes: 4 additions & 0 deletions src/status_im/init/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@
(= (get-in cofx [:db :view-id])
:create-multiaccount))

(defn recovering-multiaccount? [cofx]
(boolean (get-in cofx [:db :multiaccounts/recover])))

(defn- keycard-setup? [cofx]
(boolean (get-in cofx [:db :hardwallet :flow])))

Expand All @@ -243,6 +246,7 @@
(stickers/init-stickers-packs)
(multiaccounts.update/update-sign-in-time)
#(when-not (or (creating-multiaccount? %)
(recovering-multiaccount? %)
(keycard-setup? %))
(login-only-events % address stored-pns)))))

Expand Down
72 changes: 71 additions & 1 deletion src/status_im/multiaccounts/recover/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
(update :multiaccounts/recover assoc
:processing? false
:password ""
:password-confirmation ""
:password-error :recover-password-invalid)
(update :multiaccounts/recover dissoc
:password-valid?))
Expand Down Expand Up @@ -127,9 +128,78 @@
(fx/defn navigate-to-recover-multiaccount-screen [{:keys [db] :as cofx}]
(fx/merge cofx
{:db (dissoc db :multiaccounts/recover)}
(navigation/navigate-to-cofx :recover nil)))
(navigation/navigate-to-cofx :recover-multiaccount nil)))

(re-frame/reg-fx
:multiaccounts.recover/recover-multiaccount
(fn [[masked-passphrase password]]
(recover-multiaccount! masked-passphrase password)))

(fx/defn re-encrypt-pressed
{:events [:recover.success.ui/re-encrypt-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (assoc-in db [:intro-wizard :selected-storage-type] :default)}
(navigation/navigate-to-cofx :recover-multiaccount-select-storage nil)))

(fx/defn enter-phrase-pressed
{:events [:recover.ui/enter-phrase-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:dispatch [:bottom-sheet/hide-sheet]}
(navigation/navigate-to-cofx :recover-multiaccount-enter-phrase nil)))

(fx/defn enter-phrase-next-button-pressed
{:events [:recover.enter-passphrase.ui/input-submitted
:recover.enter-passphrase.ui/next-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (-> db
(assoc-in [:multiaccounts/recover :address] "0xF84E72a8b067993A758F12f8a25Bb839a27e8777")
(assoc-in [:multiaccounts/recover :pubkey] "0x044da4c5e58efe0cb20c42f3719682b8d17e78038a2a0e46483007da9747ada1984d7f053a2b2201ee7d476101be530021da642280e406fc57b4368ea88b43bdb4"))}
(navigation/navigate-to-cofx :recover-multiaccount-success nil)))

(fx/defn cancel-pressed
{:events [:recover.ui/cancel-pressed]}
[cofx]
(navigation/navigate-back cofx))

(fx/defn select-storage-next-pressed
{:events [:recover.select-storage.ui/next-pressed]}
[{: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/defn enter-password-next-button-pressed
{:events [:recover.enter-password.ui/input-submitted
:recover.enter-password.ui/next-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(navigation/navigate-to-cofx :recover-multiaccount-confirm-password nil)))

(fx/defn confirm-password-next-button-pressed
{:events [:recover.confirm-password.ui/input-submitted
:recover.confirm-password.ui/next-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (assoc db :intro-wizard nil)}
(recover-multiaccount)
(navigation/navigate-to-cofx :welcome nil)))

(fx/defn enter-phrase-input-changed
{:events [:recover.enter-passphrase.ui/input-changed]}
[{:keys [db]} input]
{:db (assoc-in db [:multiaccounts/recover :passphrase] input)})

(fx/defn enter-password-input-changed
{:events [:recover.enter-password.ui/input-changed]}
[{:keys [db]} input]
{:db (assoc-in db [:multiaccounts/recover :password] input)})

(fx/defn confirm-password-input-changed
{:events [:recover.confirm-password.ui/input-changed]}
[{:keys [db]} input]
{:db (assoc-in db [:multiaccounts/recover :password-confirmation] input)})
3 changes: 2 additions & 1 deletion src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
status-im.ui.screens.hardwallet.connect.subs
status-im.ui.screens.hardwallet.settings.subs
status-im.ui.screens.hardwallet.pin.subs
status-im.ui.screens.hardwallet.setup.subs))
status-im.ui.screens.hardwallet.setup.subs
status-im.ui.screens.multiaccounts.recover.subs))

;; TOP LEVEL ===========================================================================================================

Expand Down
1 change: 1 addition & 0 deletions src/status_im/ui/components/icons/vector_icons.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
:main-icons/in-contacts (js/require "./resources/icons/main/in_contacts.svg")
:main-icons/info (js/require "./resources/icons/main/info.svg")
:main-icons/keycard (js/require "./resources/icons/main/keycard.svg")
:main-icons/keycard-logo (js/require "./resources/icons/main/keycard-logo.svg")
:main-icons/language (js/require "./resources/icons/main/language.svg")
:main-icons/link (js/require "./resources/icons/main/link.svg")
:main-icons/log-level (js/require "./resources/icons/main/mailserver.svg")
Expand Down
55 changes: 0 additions & 55 deletions src/status_im/ui/screens/keycard/onboarding/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -394,58 +394,3 @@
:label (i18n/label :t/next)
:disabled? (empty? input-word)
:forward? true}]]]]])))

;NOTE temporary screen, to be removed after Recovery will be implemented
(defview enter-mnemonic []
(letsubs [mnemonic [:hardwallet-mnemonic]]
[react/view styles/container
[toolbar/toolbar
{:transparent? true
:style {:margin-top 32}}
[toolbar/nav-text
{:handler #(re-frame/dispatch [:keycard.onboarding.ui/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}}
"Enter your recovery phrase"]]
[react/view {:margin-top 16
:width "85%"
:align-items :center}
[react/text {:style {:color colors/gray
:text-align :center}}
"Enter your recovery phrase, separate the words by single spaces"]]]
[react/view
[text-input/text-input-with-label
{:on-change-text #(re-frame/dispatch [:keycard.recovery.enter-mnemonic.ui/input-changed %])
:auto-focus true
:on-submit-editing #(re-frame/dispatch [:keycard.recovery.enter-mnemonic.ui/input-submitted])
:placeholder nil
:height 125
:multiline true
:auto-correct false
:container {:background-color :white}
:style {:background-color :white
:typography :header}}]]
[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 [:keycard.recovery.enter-mnemonic.ui/next-pressed])
:label (i18n/label :t/next)
:disabled? (empty? mnemonic)
:forward? true}]]]]]))
32 changes: 32 additions & 0 deletions src/status_im/ui/screens/multiaccounts/recover/subs.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(ns status-im.ui.screens.multiaccounts.recover.subs
(:require [re-frame.core :as re-frame]))

(re-frame/reg-sub
:multiaccounts.recover/passphrase
(fn [db]
(get-in db [:multiaccounts/recover :passphrase])))

(re-frame/reg-sub
:multiaccounts.recover/password
(fn [db]
(get-in db [:multiaccounts/recover :password])))

(re-frame/reg-sub
:multiaccounts.recover/password-confirmation
(fn [db]
(get-in db [:multiaccounts/recover :password-confirmation])))

(re-frame/reg-sub
:multiaccounts.recover/address
(fn [db]
(get-in db [:multiaccounts/recover :address])))

(re-frame/reg-sub
:multiaccounts.recover/pubkey
(fn [db]
(get-in db [:multiaccounts/recover :pubkey])))

(re-frame/reg-sub
:multiaccounts.recover/processing?
(fn [db]
(get-in db [:multiaccounts/recover :processing?])))
Loading

0 comments on commit a992034

Please sign in to comment.