From 2deffd8d502d0b86280ed81cff2dac197caaaadf Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 28 Jul 2020 14:10:42 +0300 Subject: [PATCH] [#9986] Allow to disable fetching of tx history on mobile network --- .env | 1 + .env.jenkins | 1 + .../status/ethereum/module/StatusModule.java | 12 +++ .../ios/RCTStatus/RCTStatus.m | 14 +++ src/status_im/ethereum/subscriptions.cljs | 40 ++++---- src/status_im/native_module/core.cljs | 8 ++ src/status_im/network/net_info.cljs | 21 ++-- src/status_im/subs.cljs | 4 +- .../mobile_network_settings/events.cljs | 19 +++- .../ui/screens/sync_settings/views.cljs | 2 +- src/status_im/utils/config.cljs | 2 + src/status_im/wallet/core.cljs | 96 ++++++++++++++----- status-go-version.json | 6 +- translations/en.json | 6 +- 14 files changed, 169 insertions(+), 63 deletions(-) diff --git a/.env b/.env index be3d8669d371..c7b3113194f1 100644 --- a/.env +++ b/.env @@ -23,3 +23,4 @@ KEYCARD_TEST_MENU=0 QR_READ_TEST_MENU=1 ENABLE_ROOT_ALERT=1 ENABLE_REFERRAL_INVITE=1 +DISABLE_WALLET_ON_MOBILE_NETWORK=1 diff --git a/.env.jenkins b/.env.jenkins index b58a207279c6..0fc26e13169a 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -21,3 +21,4 @@ STATUS_GO_ENABLE_NIMBUS=0 KEYCARD_TEST_MENU=0 ENABLE_ROOT_ALERT=1 ENABLE_REFERRAL_INVITE=1 +DISABLE_WALLET_ON_MOBILE_NETWORK=1 diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java index 507573c0a021..03819714b90c 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java @@ -1099,6 +1099,18 @@ public void appStateChange(final String type) { Statusgo.appStateChange(type); } + @ReactMethod + public void stopWallet() { + Log.d(TAG, "StopWallet"); + Statusgo.stopWallet(); + } + + @ReactMethod + public void startWallet() { + Log.d(TAG, "StartWallet"); + Statusgo.startWallet(); + } + @ReactMethod public void setBlankPreviewFlag(final Boolean blankPreview) { final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.reactContext); diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index edd87695869e..9048ebd11919 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -740,6 +740,20 @@ - (void) migrateKeystore:(NSString *)accountData StatusgoAppStateChange(type); } +RCT_EXPORT_METHOD(stopWallet) { +#if DEBUG + NSLog(@"StopWallet() method called"); +#endif + StatusgoStopWallet(); +} + +RCT_EXPORT_METHOD(startWallet) { +#if DEBUG + NSLog(@"StartWallet() method called"); +#endif + StatusgoStartWallet(); +} + RCT_EXPORT_METHOD(setBlankPreviewFlag:(BOOL *)newValue) { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; diff --git a/src/status_im/ethereum/subscriptions.cljs b/src/status_im/ethereum/subscriptions.cljs index 0bcf6c8c9876..94cae830d4a1 100644 --- a/src/status_im/ethereum/subscriptions.cljs +++ b/src/status_im/ethereum/subscriptions.cljs @@ -1,6 +1,7 @@ (ns status-im.ethereum.subscriptions (:require [status-im.ethereum.eip55 :as eip55] [status-im.wallet.db :as wallet] + [status-im.wallet.core :as wallet.core] [status-im.ethereum.transactions.core :as transactions] [status-im.utils.fx :as fx] [taoensso.timbre :as log])) @@ -59,24 +60,27 @@ (log/debug "[wallet-subs] recent-history-fetching-ended" "accounts" accounts "block" blockNumber) - {:db (-> db - (update-in [:wallet :accounts] - wallet/remove-transactions-since-block blockNumber) - (transactions/update-fetching-status accounts :recent? false)) - :transactions/get-transfers - {:chain-tokens (:wallet/all-tokens db) - :addresses (reduce - (fn [v address] - (let [normalized-address - (eip55/address->checksum address)] - (if (contains? v normalized-address) - v - (conj v address)))) - [] - accounts) - :before-block blockNumber - :limit 20 - :historical? true}}) + (fx/merge + cofx + {:db (-> db + (update-in [:wallet :accounts] + wallet/remove-transactions-since-block blockNumber) + (transactions/update-fetching-status accounts :recent? false)) + :transactions/get-transfers + {:chain-tokens (:wallet/all-tokens db) + :addresses (reduce + (fn [v address] + (let [normalized-address + (eip55/address->checksum address)] + (if (contains? v normalized-address) + v + (conj v address)))) + [] + accounts) + :before-block blockNumber + :limit 20 + :historical? true}} + (wallet.core/restart-wallet-service))) (fx/defn new-wallet-event [cofx {:keys [type blockNumber accounts newTransactions] :as event}] diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index f79dc81d8c5a..501d3d9999a3 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -263,6 +263,14 @@ (log/debug "[native-module] app-state-change") (.appStateChange ^js (status) state)) +(defn stop-wallet [] + (log/debug "[native-module] stop-wallet") + (.stopWallet ^js (status))) + +(defn start-wallet [] + (log/debug "[native-module] start-wallet") + (.startWallet ^js (status))) + (defn set-blank-preview-flag [flag] (log/debug "[native-module] set-blank-preview-flag") (.setBlankPreviewFlag ^js (status) flag)) diff --git a/src/status_im/network/net_info.cljs b/src/status_im/network/net_info.cljs index 8a588825ab98..1902ac112a7c 100644 --- a/src/status_im/network/net_info.cljs +++ b/src/status_im/network/net_info.cljs @@ -4,7 +4,8 @@ [status-im.ui.screens.mobile-network-settings.events :as mobile-network] [status-im.utils.fx :as fx] [status-im.wallet.core :as wallet] - ["@react-native-community/netinfo" :default net-info])) + ["@react-native-community/netinfo" :default net-info] + [taoensso.timbre :as log])) (fx/defn change-network-status [{:keys [db] :as cofx} is-connected?] @@ -24,13 +25,21 @@ (fx/defn handle-network-info-change {:events [::network-info-changed]} [{:keys [db] :as cofx} {:keys [isConnected type details] :as state}] - (let [old-network-status (:network-status db) - old-network-type (:network/type db) - connectivity-status (if isConnected :online :offline)] + (let [old-network-status (:network-status db) + old-network-type (:network/type db) + connectivity-status (if isConnected :online :offline) + status-changed? (= connectivity-status old-network-status) + type-changed? (= type old-network-type)] + (log/debug "[net-info]" + "old-network-status" old-network-status + "old-network-type" old-network-type + "connectivity-status" connectivity-status + "type" type + "details" details) (fx/merge cofx - (when-not (= connectivity-status old-network-status) + (when-not status-changed? (change-network-status isConnected)) - (when-not (= type old-network-type) + (when-not type-changed? (change-network-type old-network-type type (:is-connection-expensive details)))))) (defn add-net-info-listener [] diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index cdee780de734..8cd85c51bd83 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -60,6 +60,7 @@ ;;general (reg-root-key-sub :sync-state :sync-state) (reg-root-key-sub :network-status :network-status) +(reg-root-key-sub :network/type :network/type) (reg-root-key-sub :peers-count :peers-count) (reg-root-key-sub :about-app/node-info :node-info) (reg-root-key-sub :peers-summary :peers-summary) @@ -153,7 +154,8 @@ (reg-root-key-sub :wallet.transactions :wallet.transactions) (reg-root-key-sub :wallet/custom-token-screen :wallet/custom-token-screen) (reg-root-key-sub :wallet/prepare-transaction :wallet/prepare-transaction) - +(reg-root-key-sub :wallet-service/manual-setting :wallet-service/manual-setting) +(reg-root-key-sub :wallet-service/state :wallet-service/state) ;;commands (reg-root-key-sub :commands/select-account :commands/select-account) diff --git a/src/status_im/ui/screens/mobile_network_settings/events.cljs b/src/status_im/ui/screens/mobile_network_settings/events.cljs index 5c6709d599fb..c077d7923098 100644 --- a/src/status_im/ui/screens/mobile_network_settings/events.cljs +++ b/src/status_im/ui/screens/mobile_network_settings/events.cljs @@ -3,11 +3,13 @@ [status-im.utils.handlers :as handlers] [status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.utils.fx :as fx] + [status-im.wallet.core :as wallet] [status-im.ui.components.bottom-sheet.core :as bottom-sheet] [status-im.multiaccounts.model :as multiaccounts.model] [status-im.navigation :as navigation] [status-im.mailserver.core :as mailserver] - [status-im.ui.screens.mobile-network-settings.utils :as utils])) + [status-im.ui.screens.mobile-network-settings.utils :as utils] + [taoensso.timbre :as log])) (fx/defn sheet-defaults [{:keys [db]}] @@ -34,7 +36,8 @@ logged-in? [(mailserver/process-next-messages-request) - (bottom-sheet/hide-bottom-sheet)])))) + (bottom-sheet/hide-bottom-sheet) + (wallet/restart-wallet-service)])))) (defn apply-settings ([sync?] (apply-settings sync? :default)) @@ -44,7 +47,12 @@ remember-choice? (if (not= :default remember?) remember? - (:mobile-network/remember-choice? db))] + (:mobile-network/remember-choice? db)) + cellular? (utils/cellular? network)] + (log/info "apply mobile network settings" + "sunc?" sync? + "remember?" remember? + "cellular?" cellular?) (fx/merge cofx (multiaccounts.update/multiaccount-update @@ -52,8 +60,9 @@ (multiaccounts.update/multiaccount-update :remember-syncing-choice? (boolean remember-choice?) {}) (bottom-sheet/hide-bottom-sheet) - (when (and (utils/cellular? network) sync?) - (mailserver/process-next-messages-request))))))) + (when (and cellular? sync?) + (mailserver/process-next-messages-request)) + (wallet/restart-wallet-service)))))) (handlers/register-handler-fx :mobile-network/continue-syncing diff --git a/src/status_im/ui/screens/sync_settings/views.cljs b/src/status_im/ui/screens/sync_settings/views.cljs index b776b5b70d1d..9cc9f288c9f4 100644 --- a/src/status_im/ui/screens/sync_settings/views.cljs +++ b/src/status_im/ui/screens/sync_settings/views.cljs @@ -13,7 +13,7 @@ [react/view {:style {:flex 1 :background-color colors/white}} [topbar/topbar {:title :t/sync-settings}] [react/scroll-view - [quo/list-header (i18n/label :t/message-syncing)] + [quo/list-header (i18n/label :t/data-syncing)] [quo/list-item {:size :small :title (i18n/label :t/mobile-network-settings) :accessibility-label :notifications-button diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index 387063f1cf85..1e94f3f8f960 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -41,6 +41,8 @@ (def qr-test-menu-enabled? (enabled? (get-config :QR_READ_TEST_MENU "0"))) (def referrals-invite-enabled? (enabled? (get-config :ENABLE_REFERRAL_INVITE "0"))) +(def disable-wallet-on-mobile-network? + (enabled? (get-config :DISABLE_WALLET_ON_MOBILE_NETWORK))) ;; CONFIG VALUES (def log-level (string/upper-case (get-config :LOG_LEVEL ""))) diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index 29b6d4798fcf..859a30c13cd2 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -1,30 +1,33 @@ (ns status-im.wallet.core - (:require [re-frame.core :as re-frame] - [status-im.multiaccounts.update.core :as multiaccounts.update] - [status-im.constants :as constants] - [status-im.waku.core :as waku] - [status-im.ethereum.core :as ethereum] - [status-im.ethereum.eip55 :as eip55] - [status-im.ethereum.json-rpc :as json-rpc] - [status-im.ethereum.tokens :as tokens] - [status-im.i18n :as i18n] - [status-im.navigation :as navigation] - [status-im.utils.config :as config] - [status-im.utils.core :as utils.core] - [status-im.utils.fx :as fx] - [status-im.utils.money :as money] - [status-im.utils.utils :as utils.utils] - [taoensso.timbre :as log] - [status-im.wallet.db :as wallet.db] - [status-im.ethereum.abi-spec :as abi-spec] - [status-im.signing.core :as signing] - [clojure.string :as string] - [status-im.contact.db :as contact.db] - [status-im.ethereum.ens :as ens] - [status-im.ethereum.stateofus :as stateofus] - [status-im.ui.components.bottom-sheet.core :as bottom-sheet] - [status-im.wallet.prices :as prices] - [status-im.wallet.utils :as wallet.utils])) + (:require + [re-frame.core :as re-frame] + [status-im.multiaccounts.update.core :as multiaccounts.update] + [status-im.constants :as constants] + [status-im.waku.core :as waku] + [status-im.ethereum.core :as ethereum] + [status-im.ethereum.eip55 :as eip55] + [status-im.ethereum.json-rpc :as json-rpc] + [status-im.ethereum.tokens :as tokens] + [status-im.i18n :as i18n] + [status-im.navigation :as navigation] + [status-im.utils.config :as config] + [status-im.utils.core :as utils.core] + [status-im.utils.fx :as fx] + [status-im.utils.money :as money] + [status-im.utils.utils :as utils.utils] + [taoensso.timbre :as log] + [status-im.wallet.db :as wallet.db] + [status-im.ethereum.abi-spec :as abi-spec] + [status-im.signing.core :as signing] + [clojure.string :as string] + [status-im.contact.db :as contact.db] + [status-im.ethereum.ens :as ens] + [status-im.ethereum.stateofus :as stateofus] + [status-im.ui.components.bottom-sheet.core :as bottom-sheet] + [status-im.wallet.prices :as prices] + [status-im.wallet.utils :as wallet.utils] + [status-im.native-module.core :as status] + [status-im.ui.screens.mobile-network-settings.utils :as mobile-network-utils])) (defn get-balance [{:keys [address on-success on-error]}] @@ -601,3 +604,44 @@ :cancel-button-text (i18n/label :t/no) :on-accept #(re-frame/dispatch [:wallet.accounts/delete-account account]) :on-cancel #()}}) + +(re-frame/reg-fx + ::stop-wallet + (fn [] + (log/info "stop-wallet fx") + (status/stop-wallet))) + +(re-frame/reg-fx + ::start-wallet + (fn [] + (log/info "start-wallet fx") + (status/start-wallet))) + +(fx/defn stop-wallet + [{:keys [db] :as cofx}] + (let [] + {:db (assoc db :wallet-service/state :stopped) + ::stop-wallet nil})) + +(fx/defn start-wallet + [{:keys [db] :as cofx}] + (let [] + {:db (assoc db :wallet-service/state :started) + ::start-wallet nil})) + +(fx/defn restart-wallet-service + [{:keys [db] :as cofx}] + (when (:multiaccount db) + (let [state (:wallet-service/state db) + syncing-allowed? (mobile-network-utils/syncing-allowed? cofx)] + (log/info "restart-wallet-service" + "syncing-allowed" syncing-allowed? + "state" state) + (cond + (and (not syncing-allowed?) + (not= state :stopped)) + (stop-wallet cofx) + + (and syncing-allowed? + (= state :stopped)) + (start-wallet cofx))))) diff --git a/status-go-version.json b/status-go-version.json index 4e2fe5c5b153..8dc7be7a6fc3 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' instead", "owner": "status-im", "repo": "status-go", - "version": "v0.56.6", - "commit-sha1": "2d0818d873fee570a73867d8ed4bc8e792215cf1", - "src-sha256": "0d9k0c2srhmm5dpzx3dkzn1h0p60x9zwjzim6x08gp9yd87h3zmv" + "version": "stop-wallet", + "commit-sha1": "d3eda2a4270cc194811c03d88d2284d90c6fba72", + "src-sha256": "1bgdm0jryjk2w7f27xb8jid58glr8f0jsgflcygg25264fnah8d6" } diff --git a/translations/en.json b/translations/en.json index 6b4af570962c..e88efedace04 100644 --- a/translations/en.json +++ b/translations/en.json @@ -688,7 +688,7 @@ "message-not-sent": "Message not sent", "message-options-cancel": "Cancel", "message-reply": "Reply", - "message-syncing": "Message syncing", + "data-syncing": "Data syncing", "messages": "Messages", "chat-is-a-contact": "Contact", "chat-is-not-a-contact": "Not a contact", @@ -708,9 +708,9 @@ "mobile-network-stop-syncing": "Stop syncing", "mobile-network-stop-syncing-details": "Until connected to Wi-Fi?", "mobile-network-use-mobile": "Use mobile data", - "mobile-network-use-mobile-data": "Status uses a lot of data when syncing chats.", + "mobile-network-use-mobile-data": "Status uses a lot of data when syncing chats and wallet.", "mobile-network-use-wifi": "Wi-Fi only", - "mobile-syncing-sheet-details": "Status uses a lot of data when syncing chats.", + "mobile-syncing-sheet-details": "Status uses a lot of data when syncing chats and wallet.", "mobile-syncing-sheet-title": "Sync using mobile data?", "more": "more", "multiaccount-exists-title": "Keys for this account already exist",