Skip to content

Commit

Permalink
[#9986] Allow to disable fetching of tx history on mobile network
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Jul 29, 2020
1 parent 10a8147 commit 5641151
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 15 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ STATUS_GO_ENABLE_NIMBUS=0
KEYCARD_TEST_MENU=0
QR_READ_TEST_MENU=1
ENABLE_ROOT_ALERT=1
DISABLE_WALLET_ON_MOBILE_NETWORK=1
3 changes: 2 additions & 1 deletion .env.jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ PARTITIONED_TOPIC=0
CONTRACT_NODES=1
STATUS_GO_ENABLE_NIMBUS=0
KEYCARD_TEST_MENU=0
ENABLE_ROOT_ALERT=1
ENABLE_ROOT_ALERT=1
DISABLE_WALLET_ON_MOBILE_NETWORK=1
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 8 additions & 0 deletions src/status_im/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
24 changes: 17 additions & 7 deletions src/status_im/network/net_info.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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?]
Expand All @@ -24,14 +25,23 @@
(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)
(change-network-type old-network-type type (:is-connection-expensive details))))))
(when-not type-changed?
(change-network-type old-network-type type (:is-connection-expensive details)))
(wallet/restart-wallet-service type-changed?))))

(defn add-net-info-listener []
(when net-info
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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)
Expand Down Expand Up @@ -152,7 +153,7 @@
(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)
;;commands
(reg-root-key-sub :commands/select-account :commands/select-account)

Expand Down
34 changes: 33 additions & 1 deletion src/status_im/ui/screens/wallet/transactions/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
[status-im.ui.components.toolbar.view :as toolbar-old]
[status-im.ui.screens.wallet.transactions.styles :as styles]
[quo.core :as quo]
[status-im.ui.components.toolbar :as toolbar])
[status-im.ui.components.toolbar :as toolbar]
[status-im.wallet.core :as wallet.core]
[status-im.utils.config :as config])
(:require-macros [status-im.utils.views :refer [defview letsubs]]))

(defn- transaction-icon
Expand Down Expand Up @@ -93,13 +95,43 @@
{:style {:color colors/blue}}
(i18n/label :t/check-on-etherscan)]]]))

(defn wallet-service-state []
(let [status @(re-frame/subscribe [:network-status])
type @(re-frame/subscribe [:network/type])
setting @(re-frame/subscribe [:wallet-service/manual-setting])]
[react/view
{:style {:flex 1
:flex-direction :row}}
[react/text {:style {:flex 1}} (str "setting: " setting)]
[react/text
{:style {:background-color :grey
:flex 1}}
status]
[react/text type]
[react/text
{:on-press #(re-frame/dispatch
[::wallet.core/toggle-force-stop-wallet-service])
:style {:color (when (= setting :off) :red)
:background-color :green
:flex 1}}
"force stop"]
[react/text
{:on-press #(re-frame/dispatch
[::wallet.core/toggle-force-start-wallet-service])
:style {:color (when (= setting :on) :red)
:background-color :yellow
:flex 1}}
"force start"]]))

(defn history-list
[transactions-history-sections address]
(let [fetching-recent-history? @(re-frame/subscribe [:wallet/fetching-recent-tx-history? address])
fetching-more-history? @(re-frame/subscribe [:wallet/fetching-tx-history? address])
all-fetched? @(re-frame/subscribe [:wallet/tx-history-fetched? address])]
[react/view components.styles/flex
[etherscan-link address]
(when config/disable-wallet-on-mobile-network?
[wallet-service-state])
(when fetching-recent-history?
[react/view
{:style {:flex 1
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/utils/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
(def commands-enabled? (enabled? (get-config :COMMANDS_ENABLED "0")))
(def keycard-test-menu-enabled? (enabled? (get-config :KEYCARD_TEST_MENU "0")))
(def qr-test-menu-enabled? (enabled? (get-config :QR_READ_TEST_MENU "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 "")))
Expand Down
74 changes: 73 additions & 1 deletion src/status_im/wallet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
[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.wallet.utils :as wallet.utils]
[status-im.native-module.core :as status]))

(defn get-balance
[{:keys [address on-success on-error]}]
Expand Down Expand Up @@ -601,3 +602,74 @@
: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} type-changed?]
(let [network-status (:network-status db)
network-type (:network/type db)
setting (:wallet-service/manual-setting db)
state (:wallet-service/state db)]
(log/info "restart-wallet-service"
"setting?" setting
"state" state
"network-type" network-type
"network-status" network-status)
(when (and config/disable-wallet-on-mobile-network?
(= network-status :online)
(nil? setting))
(cond
(and (not= network-type "wifi")
(not= state :stopped))
(stop-wallet cofx)

(and (= network-type "wifi")
(= state :stopped))
(start-wallet cofx)))))

(fx/defn toggle-force-stop-wallet-service
{:events [::toggle-force-stop-wallet-service]}
[{:keys [db] :as cofx}]
(let [setting (:wallet-service/manual-setting db)
new-setting (when (not= setting :off) :off)]
(fx/merge
cofx
{:db (assoc db :wallet-service/manual-setting new-setting)}
(if (= new-setting :off)
(stop-wallet)
(restart-wallet-service true)))))

(fx/defn toggle-force-start-wallet-service
{:events [::toggle-force-start-wallet-service]}
[{:keys [db] :as cofx}]
(let [setting (:wallet-service/manual-setting db)
new-setting (when (not= setting :on) :on)]
(fx/merge
cofx
{:db (assoc db :wallet-service/manual-setting new-setting)}
(if (= new-setting :on)
(start-wallet)
(restart-wallet-service true)))))
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.55.2",
"commit-sha1": "0b3cdf7362bbdf9ba7fc11da803105f9417dfbac",
"src-sha256": "1vq3z150p0fbwjc1mqmi8lz4vg28dzqhlpsn7kar8j5z4rx5z5hn"
"version": "stop-wallet",
"commit-sha1": "6a830d0d8518ea09e463a3544ec857b40b8350b2",
"src-sha256": "1hh6f4cdm5hcxyjf2zrprqpnc3biijfxsc3pb71q0lm33h4s1ngh"
}

0 comments on commit 5641151

Please sign in to comment.