From 48d3087f814fe6e2366e8e2277e98f7dacf9d116 Mon Sep 17 00:00:00 2001 From: yenda Date: Fri, 10 Jan 2020 14:18:59 +0100 Subject: [PATCH] fix 9792 Signed-off-by: yenda --- src/status_im/events.cljs | 15 ------------ src/status_im/multiaccounts/login/core.cljs | 7 ++++-- src/status_im/wallet/custom_tokens/core.cljs | 24 ++++++++++++++------ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index da139648a5..4637103368 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -1423,21 +1423,6 @@ (fn [cofx [_ field-key value]] (custom-tokens/field-is-edited cofx field-key value))) -(handlers/register-handler-fx - :wallet.custom-token.ui/add-pressed - (fn [cofx _] - (fx/merge cofx - (custom-tokens/add-custom-token) - (navigation/navigate-back)))) - -(handlers/register-handler-fx - :wallet.custom-token.ui/remove-pressed - (fn [cofx [_ token navigate-back?]] - (fx/merge cofx - (custom-tokens/remove-custom-token token) - (when navigate-back? - (navigation/navigate-back))))) - ;; ethereum subscriptions events (handlers/register-handler-fx diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 2e0e244fd9..7b92837dda 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -181,7 +181,8 @@ :on-success resolve :on-error reject})))])) (.then (fn [[accounts custom-tokens]] - (callback accounts custom-tokens))) + (callback accounts + (mapv #(update % :symbol keyword) custom-tokens)))) (.catch (fn [error] (log/error "Failed to initialize wallet")))))) @@ -203,7 +204,9 @@ (assoc ::notifications/enable nil) (not platform/desktop?) (assoc ::initialize-wallet - #(re-frame/dispatch [::initialize-wallet %]))) + (fn [accounts custom-tokens] + (re-frame/dispatch [::initialize-wallet + accounts custom-tokens])))) ;; NOTE: initializing mailserver depends on user mailserver ;; preference which is why we wait for config callback (protocol/initialize-protocol {:default-mailserver true}) diff --git a/src/status_im/wallet/custom_tokens/core.cljs b/src/status_im/wallet/custom_tokens/core.cljs index 850fab88a0..9f72ef1486 100644 --- a/src/status_im/wallet/custom_tokens/core.cljs +++ b/src/status_im/wallet/custom_tokens/core.cljs @@ -9,6 +9,7 @@ [status-im.utils.fx :as fx] [status-im.utils.money :as money] [status-im.wallet.core :as wallet] + [status-im.ui.screens.navigation :as navigation] [status-im.multiaccounts.update.core :as multiaccounts.update])) (re-frame/reg-fx @@ -165,6 +166,7 @@ :error (i18n/label :t/wrong-contract)})})) (fx/defn add-custom-token + {:events [:wallet.custom-token.ui/add-pressed]} [{:keys [db] :as cofx}] (let [{:keys [contract name symbol decimals]} (get db :wallet/custom-token-screen) chain-key (ethereum/chain-keyword db) @@ -174,19 +176,27 @@ :symbol symbol :decimals (int decimals) :color (rand-nth colors/chat-colors)}] - (fx/merge {:db (assoc-in db [:wallet/all-tokens chain-key contract] + (fx/merge cofx + {:db (assoc-in db [:wallet/all-tokens chain-key contract] (assoc new-token :custom? true)) ::json-rpc/call [{:method "wallet_addCustomToken" - :params [new-token]}]} - (wallet/add-custom-token new-token)))) + :params [new-token] + :on-success #()}]} + (wallet/add-custom-token new-token) + (navigation/navigate-back)))) (fx/defn remove-custom-token - [{:keys [db] :as cofx} {:keys [address] :as token}] + {:events [:wallet.custom-token.ui/remove-pressed]} + [{:keys [db] :as cofx} {:keys [address] :as token} navigate-back?] (let [chain-key (ethereum/chain-keyword db)] - (fx/merge {:db (update-in db [:wallet/all-tokens chain-key] dissoc address) + (fx/merge cofx + {:db (update-in db [:wallet/all-tokens chain-key] dissoc address) ::json-rpc/call [{:method "wallet_deleteCustomToken" - :params [address]}]} - (wallet/remove-custom-token token)))) + :params [address] + :on-success #()}]} + (wallet/remove-custom-token token) + (when navigate-back? + (navigation/navigate-back))))) (fx/defn field-is-edited [{:keys [db] :as cofx} field-key value]