Skip to content

Commit

Permalink
change recover flow
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryn committed Aug 5, 2019
1 parent 05809ca commit 41fa926
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
7 changes: 0 additions & 7 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,6 @@
(fn [cofx _]
(multiaccounts.recover/recover-multiaccount cofx)))

(handlers/register-handler-fx
:multiaccounts.recover.callback/recover-multiaccount-success
[(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx :multiaccounts.create/get-signing-phrase)]
(fn [cofx [_ result password]]
(multiaccounts.recover/on-multiaccount-recovered cofx result password)))

;; multiaccounts login module

(handlers/register-handler-fx
Expand Down
66 changes: 52 additions & 14 deletions src/status_im/multiaccounts/recover/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,22 @@
:node/stop nil}))

(fx/defn on-multiaccount-recovered
{:events [:multiaccounts.recover.callback/recover-multiaccount-success]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx :multiaccounts.create/get-signing-phrase)]}
[cofx result password]
(let [data (types/json->clj result)]
(validate-recover-result cofx data password)))

(fx/defn recover-multiaccount
[{:keys [db random-guid-generator] :as cofx}]
(fx/merge
cofx
{:db (-> db
(assoc-in [:multiaccounts/recover :processing?] true)
(assoc :node/on-ready :recover-multiaccount)
(assoc :multiaccounts/new-installation-id (random-guid-generator)))}
(node/initialize nil)))
(let [{:keys [password passphrase]} (:multiaccounts/recover db)]
(fx/merge cofx
{:db (-> db
(assoc-in [:multiaccounts/recover :processing?] true)
(assoc :multiaccounts/new-installation-id (random-guid-generator)))
:multiaccounts.recover/recover-multiaccount
[(security/mask-data passphrase) password]})))

(fx/defn recover-multiaccount-with-checks [{:keys [db] :as cofx}]
(let [{:keys [passphrase processing?]} (:multiaccounts/recover db)]
Expand All @@ -135,6 +138,15 @@
(fn [[masked-passphrase password]]
(recover-multiaccount! masked-passphrase password)))

(re-frame/reg-fx
:multiaccounts.recover/get-public-key
(fn [{:keys [passphrase password]}]
;FIXME use status-go method
(js/setTimeout #(re-frame/dispatch [:multiaccounts.recover/get-public-key-success
{:public-key "0x044da4c5e58efe0cb20c42f3719682b8d17e78038a2a0e46483007da9747ada1984d7f053a2b2201ee7d476101be530021da642280e406fc57b4368ea88b43bdb4"
:address "0xF84E72a8b067993A758F12f8a25Bb839a27e8777"}])
200)))

(fx/defn re-encrypt-pressed
{:events [:recover.success.ui/re-encrypt-pressed]}
[{:keys [db] :as cofx}]
Expand All @@ -149,23 +161,49 @@
{: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/defn on-get-public-key-success
{:events [:multiaccounts.recover/get-public-key-success]}
[{:keys [db] :as cofx} {:keys [public-key address]}]
(fx/merge cofx
{:db (-> db
(assoc-in [:multiaccounts/recover :address] "0xF84E72a8b067993A758F12f8a25Bb839a27e8777")
(assoc-in [:multiaccounts/recover :pubkey] "0x044da4c5e58efe0cb20c42f3719682b8d17e78038a2a0e46483007da9747ada1984d7f053a2b2201ee7d476101be530021da642280e406fc57b4368ea88b43bdb4"))}
(assoc-in [:multiaccounts/recover :address] address)
(assoc-in [:multiaccounts/recover :pubkey] public-key))}
(navigation/navigate-to-cofx :recover-multiaccount-success nil)))

(fx/defn prepare-to-recover
[{:keys [db random-guid-generator] :as cofx}]
(fx/merge cofx
{:db (-> db
(assoc :node/on-ready :get-public-key)
(assoc :multiaccounts/new-installation-id (random-guid-generator)))}
(node/initialize nil)))

(fx/defn get-public-key
[{:keys [db]}]
(let [{:keys [password passphrase]} (:multiaccounts/recover db)]
{:multiaccounts.recover/get-public-key
{:mnemonic (security/mask-data passphrase)
:password password}}))

(fx/defn enter-phrase-next-button-pressed
{:events [:recover.enter-passphrase.ui/input-submitted
:recover.enter-passphrase.ui/next-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [db] :as cofx}]
(let [node-started? (= :started (:node/status db))]
(fx/merge cofx
(if node-started?
(get-public-key)
(prepare-to-recover)))))

(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]}
{:events [:recover.select-storage.ui/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)
Expand Down
10 changes: 4 additions & 6 deletions src/status_im/signals/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
[status-im.utils.fx :as fx]
[status-im.utils.security :as security]
[status-im.utils.types :as types]
[taoensso.timbre :as log]))
[taoensso.timbre :as log]
[status-im.multiaccounts.recover.core :as multiaccounts.recover]))

(fx/defn status-node-started
[{db :db :as cofx}]
Expand All @@ -38,11 +39,8 @@
:create-multiaccount
(fn [_]
{:multiaccounts.create/create-multiaccount (select-keys create [:id :password])})
:recover-multiaccount
(fn [{:keys [db]}]
(let [{:keys [password passphrase]} (:multiaccounts/recover db)]
{:multiaccounts.recover/recover-multiaccount
[(security/mask-data passphrase) password]}))
:get-public-key
(multiaccounts.recover/get-public-key)
:create-keycard-multiaccount
(hardwallet/create-keycard-multiaccount)
:start-onboarding
Expand Down

0 comments on commit 41fa926

Please sign in to comment.