From 172d63af4cd4d69b7c98448e542303f3887b6fb1 Mon Sep 17 00:00:00 2001 From: Igor Mandrigin Date: Fri, 24 Aug 2018 11:10:25 +0200 Subject: [PATCH] Fix for the navigation after account recovery. Signed-off-by: Igor Mandrigin --- src/status_im/ui/screens/accounts/events.cljs | 10 ++--- .../ui/screens/accounts/login/navigation.cljs | 2 +- src/status_im/ui/screens/accounts/models.cljs | 33 +++++++++------- .../ui/screens/accounts/recover/events.cljs | 6 +-- .../ui/screens/accounts/recover/models.cljs | 39 +++++++------------ 5 files changed, 41 insertions(+), 49 deletions(-) diff --git a/src/status_im/ui/screens/accounts/events.cljs b/src/status_im/ui/screens/accounts/events.cljs index c7527f858d..70a9a5cc92 100644 --- a/src/status_im/ui/screens/accounts/events.cljs +++ b/src/status_im/ui/screens/accounts/events.cljs @@ -8,12 +8,12 @@ ;;;; COFX (re-frame/reg-cofx - ::get-signing-phrase + :get-signing-phrase (fn [cofx _] (models/get-signing-phrase cofx))) (re-frame/reg-cofx - ::get-status + :get-status (fn [cofx _] (models/get-status cofx))) @@ -32,9 +32,9 @@ (handlers/register-handler-fx :account-created - [re-frame/trim-v (re-frame/inject-cofx ::get-signing-phrase) (re-frame/inject-cofx ::get-status)] - (fn [cofx [result password]] - (models/on-account-created result password cofx))) + [(re-frame/inject-cofx :get-signing-phrase) (re-frame/inject-cofx :get-status)] + (fn [cofx [_ result password]] + (models/on-account-created result password false cofx))) (handlers/register-handler-fx :send-account-update-if-needed diff --git a/src/status_im/ui/screens/accounts/login/navigation.cljs b/src/status_im/ui/screens/accounts/login/navigation.cljs index 141620806c..e66cf451fd 100644 --- a/src/status_im/ui/screens/accounts/login/navigation.cljs +++ b/src/status_im/ui/screens/accounts/login/navigation.cljs @@ -3,4 +3,4 @@ (defmethod nav/preload-data! :login [db] - (update db :accounts/login dissoc :error :password :processing)) \ No newline at end of file + (update db :accounts/login dissoc :error :password)) diff --git a/src/status_im/ui/screens/accounts/models.cljs b/src/status_im/ui/screens/accounts/models.cljs index f6fc8878c0..8908dd0989 100644 --- a/src/status_im/ui/screens/accounts/models.cljs +++ b/src/status_im/ui/screens/accounts/models.cljs @@ -18,6 +18,7 @@ status-im.ui.screens.accounts.create.navigation [status-im.ui.screens.accounts.utils :as accounts.utils] [status-im.data-store.accounts :as accounts-store] + [status-im.ui.screens.accounts.login.models :as login.models] [status-im.ui.screens.navigation :as navigation] [status-im.ui.screens.wallet.settings.models :as wallet.settings.models])) @@ -44,29 +45,33 @@ (defn- add-account "Takes db and new account, creates map of effects describing adding account to database and realm" - [{:networks/keys [networks] :as db} {:keys [address] :as account}] - (let [enriched-account (assoc account + [{:keys [address] :as account} cofx] + (let [db (:db cofx) + {:networks/keys [networks]} db + enriched-account (assoc account :network config/default-network :networks networks :address address)] {:db (assoc-in db [:accounts/accounts address] enriched-account) :data-store/base-tx [(accounts-store/save-account-tx enriched-account)]})) -(defn on-account-created [{:keys [pubkey address mnemonic]} password {:keys [signing-phrase status db]}] +(defn on-account-created [{:keys [pubkey address mnemonic]} password seed-backed-up {:keys [signing-phrase status db] :as cofx}] (let [normalized-address (utils.hex/normalize-hex address) - account {:public-key pubkey - :address normalized-address - :name (gfycat/generate-gfy pubkey) - :status status - :signed-up? true - :photo-path (identicon/identicon pubkey) - :signing-phrase signing-phrase - :mnemonic mnemonic - :settings (constants/default-account-settings)}] + account {:public-key pubkey + :address normalized-address + :name (gfycat/generate-gfy pubkey) + :status status + :signed-up? true + :photo-path (identicon/identicon pubkey) + :signing-phrase signing-phrase + :seed-backed-up? seed-backed-up + :mnemonic mnemonic + :settings (constants/default-account-settings)}] (log/debug "account-created") (when-not (str/blank? pubkey) - (-> (add-account db account) - (assoc :dispatch [:login-account normalized-address password]))))) + (handlers-macro/merge-fx cofx + (add-account account) + (login.models/login-account normalized-address password))))) (defn load-accounts [{:keys [db all-accounts]}] (let [accounts (->> all-accounts diff --git a/src/status_im/ui/screens/accounts/recover/events.cljs b/src/status_im/ui/screens/accounts/recover/events.cljs index a99cd6c530..b73b0b2949 100644 --- a/src/status_im/ui/screens/accounts/recover/events.cljs +++ b/src/status_im/ui/screens/accounts/recover/events.cljs @@ -35,14 +35,10 @@ (handlers/register-handler-fx :account-recovered + [(re-frame/inject-cofx :get-signing-phrase) (re-frame/inject-cofx :get-status)] (fn [cofx [_ result password]] (models/on-account-recovered result password cofx))) -(handlers/register-handler-fx - :account-recovered-navigate - (fn [cofx] - (models/account-recovered-navigate cofx))) - (handlers/register-handler-fx :recover-account (fn [cofx _] diff --git a/src/status_im/ui/screens/accounts/recover/models.cljs b/src/status_im/ui/screens/accounts/recover/models.cljs index 53c6850d23..92605eca70 100644 --- a/src/status_im/ui/screens/accounts/recover/models.cljs +++ b/src/status_im/ui/screens/accounts/recover/models.cljs @@ -1,9 +1,12 @@ (ns status-im.ui.screens.accounts.recover.models (:require status-im.ui.screens.accounts.recover.navigation [clojure.string :as string] + [taoensso.timbre :as log] [re-frame.core :as re-frame] + [status-im.utils.handlers-macro :as handlers-macro] [status-im.native-module.core :as status] [status-im.ui.screens.accounts.models :as accounts.models] + [status-im.ui.screens.accounts.login.models :as login.models] [status-im.utils.types :as types] [status-im.utils.identicon :as identicon] [status-im.utils.gfycat.core :as gfycat] @@ -69,31 +72,19 @@ (let [password (get-in db [:accounts/recover :password])] {:db (assoc-in db [:accounts/recover :password-error] (check-password-errors password))})) -(defn on-account-recovered [result password {:keys [db]}] - (let [data (types/json->clj result) - public-key (:pubkey data) - address (-> data :address utils.hex/normalize-hex) - phrase (signing-phrase/generate) - account {:public-key public-key - :address address - :name (gfycat/generate-gfy public-key) - :photo-path (identicon/identicon public-key) - :mnemonic "" - :signed-up? true - :signing-phrase phrase - :settings (constants/default-account-settings) - :wallet-set-up-passed? false - :seed-backed-up? true}] - (when-not (string/blank? public-key) - (-> db - (accounts.models/add-account account) - (assoc :dispatch [:login-account address password]) - (assoc :dispatch-later [{:ms 2000 :dispatch [:account-recovered-navigate]}]))))) +(defn on-account-recovered [result password cofx] + (let [db (:db cofx) + data (types/json->clj result) + pubkey (:pubkey data) + account {:pubkey pubkey + :address (:address data) + :photo-path (identicon/identicon pubkey) + :mnemonic ""}] -(defn account-recovered-navigate [{:keys [db]}] - {:db (assoc-in db [:accounts/recover :processing?] false) - :dispatch-n [[:navigate-to-clean :home] - [:request-notifications]]}) + (handlers-macro/merge-fx cofx + {:db (assoc-in db [:accounts/recover :processing?] false)} + (accounts.models/on-account-created account password true) + (login.models/open-login (:address account) (:photo-path account) (:name account))))) (defn recover-account [{:keys [db]}] (let [{:keys [password passphrase]} (:accounts/recover db)]