From 29c168dfa198c1981a29cd3ae6f6fdf95901ac9f Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Fri, 22 Mar 2019 14:57:27 +0100 Subject: [PATCH] Upgrade status-go and turn chaos mode on MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- STATUS_GO_VERSION | 2 +- .../status/ethereum/module/StatusModule.java | 20 +++++++++++++++++++ .../react-native-status/desktop/rctstatus.cpp | 10 ++++++++++ .../react-native-status/desktop/rctstatus.h | 1 + .../ios/RCTStatus/RCTStatus.m | 10 ++++++++++ src/status_im/accounts/core.cljs | 15 ++++++++++---- src/status_im/native_module/core.cljs | 2 ++ src/status_im/native_module/impl/module.cljs | 4 ++++ 8 files changed, 59 insertions(+), 5 deletions(-) diff --git a/STATUS_GO_VERSION b/STATUS_GO_VERSION index b324ca27a0..12045771a7 100644 --- a/STATUS_GO_VERSION +++ b/STATUS_GO_VERSION @@ -1 +1 @@ -0.23.0-beta.8 +0.23.0-beta.8-chaos 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 22d7886d60..f9cf48c101 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 @@ -1027,6 +1027,26 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL StatusThreadPoolExecutor.getInstance().execute(r); } + @ReactMethod + public void chaosModeUpdate(final boolean on, final Callback callback) { + Log.d(TAG, "chaosModeUpdate"); + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + Runnable r = new Runnable() { + @Override + public void run() { + String res = Statusgo.chaosModeUpdate(on); + + callback.invoke(res); + } + }; + + StatusThreadPoolExecutor.getInstance().execute(r); + } + @Override public @Nullable Map getConstants() { diff --git a/modules/react-native-status/desktop/rctstatus.cpp b/modules/react-native-status/desktop/rctstatus.cpp index 17bfc4c468..08da035b58 100644 --- a/modules/react-native-status/desktop/rctstatus.cpp +++ b/modules/react-native-status/desktop/rctstatus.cpp @@ -435,3 +435,13 @@ void RCTStatus::updateMailservers(QString enodes, double callbackId) { d->bridge->invokePromiseCallback(callbackId, QVariantList{result}); }, enodes, callbackId); } + +void RCTStatus::chaosModeUpdate(bool on, double callbackId) { + Q_D(RCTStatus); + qCDebug(RCTSTATUS) << "::chaosModeUpdate call - callbackId:" << callbackId; + QtConcurrent::run([&](bool on, double callbackId) { + const char* result = ChaosModeUpdate(on); + logStatusGoResult("::chaosModeUpdate ChaosModeUpdate", result); + d->bridge->invokePromiseCallback(callbackId, QVariantList{result}); + }, on, callbackId); +} diff --git a/modules/react-native-status/desktop/rctstatus.h b/modules/react-native-status/desktop/rctstatus.h index bb99d45bec..780f83ef2d 100644 --- a/modules/react-native-status/desktop/rctstatus.h +++ b/modules/react-native-status/desktop/rctstatus.h @@ -51,6 +51,7 @@ public: Q_INVOKABLE void enableInstallation(QString installationId, double callbackId); Q_INVOKABLE void disableInstallation(QString installationId, double callbackId); Q_INVOKABLE void updateMailservers(QString enodes, double callbackId); + Q_INVOKABLE void chaosModeUpdate(bool on, double callbackId); Q_INVOKABLE void setAdjustResize(); Q_INVOKABLE void setAdjustPan(); diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index eca5af8edc..175511b3ac 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -254,6 +254,16 @@ RCT_EXPORT_METHOD(updateMailservers:(NSString *)enodes #endif } +//////////////////////////////////////////////////////////////////// chaosModeUpdate +RCT_EXPORT_METHOD(chaosModeUpdate:(BOOL)on + callback:(RCTResponseSenderBlock)callback) { + NSString* result = StatusgoChaosModeUpdate(on); + callback(@[result]); +#if DEBUG + NSLog(@"ChaosModeUpdate() method called"); +#endif +} + //////////////////////////////////////////////////////////////////// recoverAccount RCT_EXPORT_METHOD(recoverAccount:(NSString *)passphrase password:(NSString *)password diff --git a/src/status_im/accounts/core.cljs b/src/status_im/accounts/core.cljs index a835e4b211..4df00d43f3 100644 --- a/src/status_im/accounts/core.cljs +++ b/src/status_im/accounts/core.cljs @@ -3,12 +3,18 @@ [status-im.accounts.update.core :as accounts.update] [status-im.i18n :as i18n] [status-im.ui.screens.navigation :as navigation] + [status-im.native-module.core :as native-module] [status-im.ui.screens.wallet.settings.models :as wallet.settings.models] [status-im.utils.config :as config] [status-im.utils.utils :as utils] [status-im.utils.fx :as fx] [status-im.utils.platform :as platform])) +(re-frame/reg-fx + ::chaos-mode-changed + (fn [on] + (native-module/chaos-mode-update on (constantly nil)))) + (fx/defn show-mainnet-is-default-alert [{:keys [db]}] (let [shown? (get-in db [:account/account :mainnet-warning-shown?])] (when (and platform/mobile? @@ -62,10 +68,11 @@ (fx/defn switch-chaos-mode [{:keys [db] :as cofx} chaos-mode?] (let [settings (get-in db [:account/account :settings])] - (accounts.update/update-settings - cofx - (assoc settings :chaos-mode? chaos-mode?) - {}))) + (fx/merge cofx + {::chaos-mode-changed chaos-mode?} + (accounts.update/update-settings + (assoc settings :chaos-mode? chaos-mode?) + {})))) (fx/defn enable-notifications [cofx desktop-notifications?] (accounts.update/account-update cofx diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index 1a609d10c4..343ec81ab4 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -96,3 +96,5 @@ (def update-mailservers native-module/update-mailservers) (def rooted-device? native-module/rooted-device?) + +(def chaos-mode-update native-module/chaos-mode-update) diff --git a/src/status_im/native_module/impl/module.cljs b/src/status_im/native_module/impl/module.cljs index 8639f2268d..9926ac4091 100644 --- a/src/status_im/native_module/impl/module.cljs +++ b/src/status_im/native_module/impl/module.cljs @@ -149,6 +149,10 @@ (when status (.updateMailservers status enodes on-result))) +(defn chaos-mode-update [on on-result] + (when status + (.chaosModeUpdate status on on-result))) + (defn rooted-device? [callback] (cond ;; we assume that iOS is safe by default