[fix #8760] multiple accounts created

when tapping save account quickly

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2019-08-27 17:29:31 +02:00
parent ab58dcfa36
commit 4e7c7c254b
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
1 changed files with 28 additions and 17 deletions

View File

@ -19,7 +19,7 @@
(list-selection/open-share obj))) (list-selection/open-share obj)))
(re-frame/reg-fx (re-frame/reg-fx
:wallet.accounts/generate-account ::generate-account
(fn [{:keys [address password path-num]}] (fn [{:keys [address password path-num]}]
(status/multiaccount-load-account (status/multiaccount-load-account
address address
@ -27,7 +27,7 @@
(fn [value] (fn [value]
(let [{:keys [id error]} (types/json->clj value)] (let [{:keys [id error]} (types/json->clj value)]
(if error (if error
(re-frame/dispatch [:set-in [:generate-account :error] (i18n/label :t/add-account-incorrect-password)]) (re-frame/dispatch [::generate-new-account-error])
(let [path (str constants/path-root "/" path-num)] (let [path (str constants/path-root "/" path-num)]
(status/multiaccount-derive-addresses (status/multiaccount-derive-addresses
id id
@ -40,7 +40,7 @@
(fn [result] (fn [result]
(let [{:keys [public-key address]} (let [{:keys [public-key address]}
(get (types/json->clj result) (keyword path))] (get (types/json->clj result) (keyword path))]
(re-frame/dispatch [:wallet.accounts/account-generated (re-frame/dispatch [::account-generated
{:name (str "Account " path-num) {:name (str "Account " path-num)
:address address :address address
:public-key public-key :public-key public-key
@ -55,15 +55,25 @@
(fx/defn generate-new-account (fx/defn generate-new-account
{:events [:wallet.accounts/generate-new-account]} {:events [:wallet.accounts/generate-new-account]}
[{:keys [db]} password] [{:keys [db]} password]
{:wallet.accounts/generate-account {:address (get-in db [:multiaccount :address]) (when-not (get-in db [:generate-account :step])
:path-num (inc (get-in db [:multiaccount :latest-derived-path])) {:db (assoc-in db [:generate-account :step] :generating)
:password password}}) ::generate-account {:address (get-in db [:multiaccount :address])
:path-num (inc (get-in db [:multiaccount :latest-derived-path]))
:password password}}))
(fx/defn generate-new-account-error
{:events [::generate-new-account-error]}
[{:keys [db]} password]
{:db (assoc db
:generate-account
{:error (i18n/label :t/add-account-incorrect-password)})})
(fx/defn account-generated (fx/defn account-generated
{:events [:wallet.accounts/account-generated]} {:events [::account-generated]}
[{:keys [db] :as cofx} account] [{:keys [db] :as cofx} account]
(fx/merge cofx (fx/merge cofx
{:db (assoc db :generate-account {:account account})} {:db (assoc db :generate-account {:account account
:step :generated})}
(navigation/navigate-to-cofx :account-added nil))) (navigation/navigate-to-cofx :account-added nil)))
(fx/defn save-account (fx/defn save-account
@ -71,12 +81,13 @@
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [accounts latest-derived-path]} (:multiaccount db) (let [{:keys [accounts latest-derived-path]} (:multiaccount db)
{:keys [account]} (:generate-account db)] {:keys [account]} (:generate-account db)]
(fx/merge cofx (when account
{::json-rpc/call [{:method "accounts_saveAccounts" (fx/merge cofx
:params [[account]] {::json-rpc/call [{:method "accounts_saveAccounts"
:on-success #()}] :params [[account]]
:db (dissoc db :generate-account)} :on-success #()}]
(multiaccounts.update/multiaccount-update {:accounts (conj accounts account) :db (dissoc db :generate-account)}
:latest-derived-path (inc latest-derived-path)} nil) (multiaccounts.update/multiaccount-update {:accounts (conj accounts account)
(wallet/update-balances nil) :latest-derived-path (inc latest-derived-path)} nil)
(navigation/navigate-to-cofx :wallet nil)))) (wallet/update-balances nil)
(navigation/navigate-to-cofx :wallet nil)))))