Fix for the navigation after account recovery.

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Igor Mandrigin 2018-08-24 11:10:25 +02:00
parent c5b17ac637
commit 172d63af4c
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
5 changed files with 41 additions and 49 deletions

View File

@ -8,12 +8,12 @@
;;;; COFX ;;;; COFX
(re-frame/reg-cofx (re-frame/reg-cofx
::get-signing-phrase :get-signing-phrase
(fn [cofx _] (fn [cofx _]
(models/get-signing-phrase cofx))) (models/get-signing-phrase cofx)))
(re-frame/reg-cofx (re-frame/reg-cofx
::get-status :get-status
(fn [cofx _] (fn [cofx _]
(models/get-status cofx))) (models/get-status cofx)))
@ -32,9 +32,9 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:account-created :account-created
[re-frame/trim-v (re-frame/inject-cofx ::get-signing-phrase) (re-frame/inject-cofx ::get-status)] [(re-frame/inject-cofx :get-signing-phrase) (re-frame/inject-cofx :get-status)]
(fn [cofx [result password]] (fn [cofx [_ result password]]
(models/on-account-created result password cofx))) (models/on-account-created result password false cofx)))
(handlers/register-handler-fx (handlers/register-handler-fx
:send-account-update-if-needed :send-account-update-if-needed

View File

@ -3,4 +3,4 @@
(defmethod nav/preload-data! :login (defmethod nav/preload-data! :login
[db] [db]
(update db :accounts/login dissoc :error :password :processing)) (update db :accounts/login dissoc :error :password))

View File

@ -18,6 +18,7 @@
status-im.ui.screens.accounts.create.navigation status-im.ui.screens.accounts.create.navigation
[status-im.ui.screens.accounts.utils :as accounts.utils] [status-im.ui.screens.accounts.utils :as accounts.utils]
[status-im.data-store.accounts :as accounts-store] [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.navigation :as navigation]
[status-im.ui.screens.wallet.settings.models :as wallet.settings.models])) [status-im.ui.screens.wallet.settings.models :as wallet.settings.models]))
@ -44,15 +45,17 @@
(defn- add-account (defn- add-account
"Takes db and new account, creates map of effects describing adding account to database and realm" "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}] [{:keys [address] :as account} cofx]
(let [enriched-account (assoc account (let [db (:db cofx)
{:networks/keys [networks]} db
enriched-account (assoc account
:network config/default-network :network config/default-network
:networks networks :networks networks
:address address)] :address address)]
{:db (assoc-in db [:accounts/accounts address] enriched-account) {:db (assoc-in db [:accounts/accounts address] enriched-account)
:data-store/base-tx [(accounts-store/save-account-tx 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) (let [normalized-address (utils.hex/normalize-hex address)
account {:public-key pubkey account {:public-key pubkey
:address normalized-address :address normalized-address
@ -61,12 +64,14 @@
:signed-up? true :signed-up? true
:photo-path (identicon/identicon pubkey) :photo-path (identicon/identicon pubkey)
:signing-phrase signing-phrase :signing-phrase signing-phrase
:seed-backed-up? seed-backed-up
:mnemonic mnemonic :mnemonic mnemonic
:settings (constants/default-account-settings)}] :settings (constants/default-account-settings)}]
(log/debug "account-created") (log/debug "account-created")
(when-not (str/blank? pubkey) (when-not (str/blank? pubkey)
(-> (add-account db account) (handlers-macro/merge-fx cofx
(assoc :dispatch [:login-account normalized-address password]))))) (add-account account)
(login.models/login-account normalized-address password)))))
(defn load-accounts [{:keys [db all-accounts]}] (defn load-accounts [{:keys [db all-accounts]}]
(let [accounts (->> all-accounts (let [accounts (->> all-accounts

View File

@ -35,14 +35,10 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:account-recovered :account-recovered
[(re-frame/inject-cofx :get-signing-phrase) (re-frame/inject-cofx :get-status)]
(fn [cofx [_ result password]] (fn [cofx [_ result password]]
(models/on-account-recovered result password cofx))) (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 (handlers/register-handler-fx
:recover-account :recover-account
(fn [cofx _] (fn [cofx _]

View File

@ -1,9 +1,12 @@
(ns status-im.ui.screens.accounts.recover.models (ns status-im.ui.screens.accounts.recover.models
(:require status-im.ui.screens.accounts.recover.navigation (:require status-im.ui.screens.accounts.recover.navigation
[clojure.string :as string] [clojure.string :as string]
[taoensso.timbre :as log]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.ui.screens.accounts.models :as accounts.models] [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.types :as types]
[status-im.utils.identicon :as identicon] [status-im.utils.identicon :as identicon]
[status-im.utils.gfycat.core :as gfycat] [status-im.utils.gfycat.core :as gfycat]
@ -69,31 +72,19 @@
(let [password (get-in db [:accounts/recover :password])] (let [password (get-in db [:accounts/recover :password])]
{:db (assoc-in db [:accounts/recover :password-error] (check-password-errors password))})) {:db (assoc-in db [:accounts/recover :password-error] (check-password-errors password))}))
(defn on-account-recovered [result password {:keys [db]}] (defn on-account-recovered [result password cofx]
(let [data (types/json->clj result) (let [db (:db cofx)
public-key (:pubkey data) data (types/json->clj result)
address (-> data :address utils.hex/normalize-hex) pubkey (:pubkey data)
phrase (signing-phrase/generate) account {:pubkey pubkey
account {:public-key public-key :address (:address data)
:address address :photo-path (identicon/identicon pubkey)
:name (gfycat/generate-gfy public-key) :mnemonic ""}]
: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 account-recovered-navigate [{:keys [db]}] (handlers-macro/merge-fx cofx
{:db (assoc-in db [:accounts/recover :processing?] false) {:db (assoc-in db [:accounts/recover :processing?] false)}
:dispatch-n [[:navigate-to-clean :home] (accounts.models/on-account-created account password true)
[:request-notifications]]}) (login.models/open-login (:address account) (:photo-path account) (:name account)))))
(defn recover-account [{:keys [db]}] (defn recover-account [{:keys [db]}]
(let [{:keys [password passphrase]} (:accounts/recover db)] (let [{:keys [password passphrase]} (:accounts/recover db)]