From 3e8ce2d6d78469f349d39d620770c774c826a625 Mon Sep 17 00:00:00 2001 From: Foo Pang Date: Sat, 23 Dec 2017 00:35:49 +0800 Subject: [PATCH] [Fix #2683] Do not run sync state loop on upstream RPC networks --- src/status_im/protocol/handlers.cljs | 8 +++++--- src/status_im/ui/screens/network_settings/events.cljs | 8 +++----- src/status_im/utils/ethereum/core.cljs | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 3929e65b80..bf8227ccf4 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -15,7 +15,8 @@ [taoensso.timbre :as log :refer-macros [debug]] [status-im.native-module.core :as status] [clojure.string :as string] - [status-im.utils.web3-provider :as web3-provider])) + [status-im.utils.web3-provider :as web3-provider] + [status-im.utils.ethereum.core :as utils])) ;;;; COFX @@ -302,8 +303,9 @@ (handlers/register-handler-fx :initialize-sync-listener - (fn [{{:keys [sync-listening-started] :as db} :db} _] - (when-not sync-listening-started + (fn [{{:keys [sync-listening-started network networks/networks] :as db} :db} _] + (when (and (not sync-listening-started) + (not (utils/network-with-upstream-rpc? networks network))) {:db (assoc db :sync-listening-started true) :dispatch [:check-sync]}))) diff --git a/src/status_im/ui/screens/network_settings/events.cljs b/src/status_im/ui/screens/network_settings/events.cljs index 474094d97b..d8a69c456a 100644 --- a/src/status_im/ui/screens/network_settings/events.cljs +++ b/src/status_im/ui/screens/network_settings/events.cljs @@ -4,7 +4,8 @@ [status-im.data-store.networks :as networks] [status-im.ui.screens.network-settings.navigation] [status-im.ui.screens.accounts.events :as accounts-events] - [status-im.i18n :as i18n])) + [status-im.i18n :as i18n] + [status-im.utils.ethereum.core :as utils])) ;;;; FX @@ -28,9 +29,6 @@ (assoc :new-networks (vals new-networks'))) :save-networks new-networks'}))) -(defn network-with-upstream-rpc? [networks network] - (get-in networks [network :raw-config :UpstreamConfig :Enabled])) - (handlers/register-handler-fx ::save-network (fn [{:keys [db now]} [_ network]] @@ -44,7 +42,7 @@ (fn [{:keys [db now]} [_ network]] (let [current-network (:network db) networks (:networks/networks db)] - (if (network-with-upstream-rpc? networks current-network) + (if (utils/network-with-upstream-rpc? networks current-network) (merge (accounts-events/account-update {:db db} {:network network :last-updated now}) {:dispatch [:navigate-to-clean :accounts] diff --git a/src/status_im/utils/ethereum/core.cljs b/src/status_im/utils/ethereum/core.cljs index 95340ecb3f..e9c7b25200 100644 --- a/src/status_im/utils/ethereum/core.cljs +++ b/src/status_im/utils/ethereum/core.cljs @@ -16,6 +16,9 @@ (defn testnet? [id] (contains? #{(chain-id :ropsten) (chain-id :rinkeby)} id)) +(defn network-with-upstream-rpc? [networks network] + (get-in networks [network :raw-config :UpstreamConfig :Enabled])) + (def hex-prefix "0x") (defn normalized-address [address] @@ -66,4 +69,4 @@ (defn call-params [contract method-sig & params] (let [data (apply format-call-params (sig->method-id method-sig) params)] - {:to contract :data data})) \ No newline at end of file + {:to contract :data data}))