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
(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

View File

@ -3,4 +3,4 @@
(defmethod nav/preload-data! :login
[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.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,15 +45,17 @@
(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
@ -61,12 +64,14 @@
: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

View File

@ -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 _]

View File

@ -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)]