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 5208eab95f..46e29997a7 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 @@ -634,4 +634,9 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL thread.start(); } + + @ReactMethod + public void closeApplication() { + System.exit(0); + } } diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index 025e8c5b08..8fd6ef0a61 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -351,7 +351,9 @@ RCT_EXPORT_METHOD(sendWeb3Request:(NSString *)host }); } - +RCT_EXPORT_METHOD(closeApplication) { + exit(0); +} + (void)signalEvent:(const char *) signal { diff --git a/project.clj b/project.clj index 97924a39d3..208e6ed360 100644 --- a/project.clj +++ b/project.clj @@ -72,7 +72,7 @@ :optimize-constants true :optimizations :simple :closure-defines {"goog.DEBUG" false} - :parallel-build true + :parallel-build false :language-in :ecmascript5} :warning-handlers [status-im.utils.build/warning-handler]} :android @@ -84,6 +84,6 @@ :optimize-constants true :optimizations :simple :closure-defines {"goog.DEBUG" false} - :parallel-build true + :parallel-build false :language-in :ecmascript5} :warning-handlers [status-im.utils.build/warning-handler]}}}}}) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index dc3f06a696..753e9556e9 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -29,40 +29,44 @@ (def wallet-chat-id "wallet") (def default-network "testnet_rpc") + +(defn- transform-config [networks] + (->> networks + (map (fn [[network-name {:keys [config] :as data}]] + [network-name (assoc data + :config (types/clj->json config) + :raw-config config)])) + (into {}))) + (def default-networks - {"testnet" {:id "testnet", - :name "Ropsten", - :config (types/clj->json - {:NetworkId 3 - :DataDir "/ethereum/testnet"})} - "testnet_rpc" {:id "testnet_rpc", - :name "Ropsten with upstream RPC", - :config (types/clj->json - {:NetworkId 3 + (transform-config + {"testnet" {:id "testnet", + :name "Ropsten", + :config {:NetworkId 3 + :DataDir "/ethereum/testnet"}} + "testnet_rpc" {:id "testnet_rpc", + :name "Ropsten with upstream RPC", + :config {:NetworkId 3 :DataDir "/ethereum/testnet_rpc" :UpstreamConfig {:Enabled true - :URL "https://ropsten.infura.io/z6GCTmjdP3FETEJmMBI4"}})} - "rinkeby" {:id "rinkeby", - :name "Rinkeby", - :config (types/clj->json - {:NetworkId 4 - :DataDir "/ethereum/rinkeby"})} - "rinkeby_rpc" {:id "rinkeby_rpc", - :name "Rinkeby with upstream RPC", - :config (types/clj->json - {:NetworkId 4 + :URL "https://ropsten.infura.io/z6GCTmjdP3FETEJmMBI4"}}} + "rinkeby" {:id "rinkeby", + :name "Rinkeby", + :config {:NetworkId 4 + :DataDir "/ethereum/rinkeby"}} + "rinkeby_rpc" {:id "rinkeby_rpc", + :name "Rinkeby with upstream RPC", + :config {:NetworkId 4 :DataDir "/ethereum/rinkeby_rpc" :UpstreamConfig {:Enabled true - :URL "https://rinkeby.infura.io/z6GCTmjdP3FETEJmMBI4"}})} - "mainnet" {:id "mainnet", - :name "Mainnet", - :config (types/clj->json - {:NetworkId 1 - :DataDir "/ethereum/mainnet"})} - "mainnet_rpc" {:id "mainnet_rpc", - :name "Mainnet with upstream RPC", - :config (types/clj->json - {:NetworkId 1 + :URL "https://rinkeby.infura.io/z6GCTmjdP3FETEJmMBI4"}}} + "mainnet" {:id "mainnet", + :name "Mainnet", + :config {:NetworkId 1 + :DataDir "/ethereum/mainnet"}} + "mainnet_rpc" {:id "mainnet_rpc", + :name "Mainnet with upstream RPC", + :config {:NetworkId 1 :DataDir "/ethereum/mainnet_rpc" :UpstreamConfig {:Enabled true - :URL "https://mainnet.infura.io/z6GCTmjdP3FETEJmMBI4 "}})}}) + :URL "https://mainnet.infura.io/z6GCTmjdP3FETEJmMBI4 "}}}})) diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index 48f0891cff..c93883af77 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -86,3 +86,6 @@ (defn notify [token callback] (module-interface/-notify rns-module token callback)) + +(defn close-application [] + (module-interface/-close-application rns-module)) diff --git a/src/status_im/native_module/impl/module.cljs b/src/status_im/native_module/impl/module.cljs index 35248232ad..592f395154 100644 --- a/src/status_im/native_module/impl/module.cljs +++ b/src/status_im/native_module/impl/module.cljs @@ -212,6 +212,9 @@ (when status (call-module #(.sendWeb3Request status host payload callback)))) +(defn close-application [] + (.closeApplication status)) + (defrecord ReactNativeStatus [] module/IReactNativeStatus ;; status-go calls @@ -252,4 +255,6 @@ (-module-initialized! [this] (module-initialized!)) (-should-move-to-internal-storage? [this callback] - (should-move-to-internal-storage? callback))) + (should-move-to-internal-storage? callback)) + (-close-application [this] + (close-application))) diff --git a/src/status_im/native_module/impl/non_status_go_module.cljs b/src/status_im/native_module/impl/non_status_go_module.cljs index de5d3a22b8..476ec2098d 100644 --- a/src/status_im/native_module/impl/non_status_go_module.cljs +++ b/src/status_im/native_module/impl/non_status_go_module.cljs @@ -58,4 +58,5 @@ (impl/module-initialized!)) (-should-move-to-internal-storage? [this callback] (impl/should-move-to-internal-storage? callback)) - (-notify [this token callback])) + (-notify [this token callback]) + (-close-application [this])) diff --git a/src/status_im/native_module/module.cljs b/src/status_im/native_module/module.cljs index 0337c09b39..03f8784e0c 100644 --- a/src/status_im/native_module/module.cljs +++ b/src/status_im/native_module/module.cljs @@ -18,5 +18,6 @@ (-call-web3 [this host payload callback]) (-module-initialized! [this]) (-should-move-to-internal-storage? [this callback]) - (-notify [this token callback])) + (-notify [this token callback]) + (-close-application [this])) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 96b80c9740..25a61d1ef7 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -423,4 +423,7 @@ :remove-network "Remove network" :network-settings "Network settings" :edit-network-warning "Be careful, editing the network data may disable this network for you" - :connecting-requires-login "Connecting to another network requires login"}) \ No newline at end of file + :connecting-requires-login "Connecting to another network requires login" + :close-app-title "Warning!" + :close-app-content "App will be closed. When you restart it selected network will be used." + :close-app-button "Confirm"}) diff --git a/src/status_im/ui/screens/events.cljs b/src/status_im/ui/screens/events.cljs index 621897008d..588f60c725 100644 --- a/src/status_im/ui/screens/events.cljs +++ b/src/status_im/ui/screens/events.cljs @@ -18,7 +18,7 @@ status-im.ui.screens.qr-scanner.events status-im.ui.screens.wallet.events status-im.ui.screens.wallet.send.events - [re-frame.core :refer [dispatch reg-fx reg-cofx]] + [re-frame.core :refer [dispatch reg-fx reg-cofx] :as re-frame] [status-im.native-module.core :as status] [status-im.components.permissions :as permissions] [status-im.constants :refer [console-chat-id]] @@ -176,6 +176,17 @@ (fn [] (notifications/get-fcm-token))) +(re-frame/reg-fx + :show-confirmation + (fn [{:keys [title content confirm-button-text on-accept on-cancel]}] + (utils/show-confirmation title content confirm-button-text on-accept on-cancel))) + + +(re-frame/reg-fx + :close-application + (fn [] (status/close-application))) + + ;;;; Handlers (register-handler-db diff --git a/src/status_im/ui/screens/network_settings/events.cljs b/src/status_im/ui/screens/network_settings/events.cljs index 5a7644c85e..f8fb1aea1e 100644 --- a/src/status_im/ui/screens/network_settings/events.cljs +++ b/src/status_im/ui/screens/network_settings/events.cljs @@ -3,7 +3,8 @@ [status-im.utils.handlers :refer [register-handler] :as handlers] [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.ui.screens.accounts.events :as accounts-events] + [status-im.i18n :as i18n])) ;;;; FX @@ -27,9 +28,26 @@ (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])) + +(defn connect-network [cofx [_ network]] + (merge (accounts-events/account-update cofx {:network network}) + {:close-application nil})) + +(handlers/register-handler-fx ::save-network connect-network) + (handlers/register-handler-fx :connect-network - (fn [cofx [_ network]] - (merge (accounts-events/account-update cofx {:network network}) - {:dispatch [:navigate-to-clean :accounts] - :stop-whisper nil}))) + (fn [{:keys [db] :as cofx} [_ network]] + (let [current-network (:network db) + networks (:networks/networks db)] + (if (network-with-upstream-rpc? networks current-network) + (merge (accounts-events/account-update cofx {:network network}) + {:dispatch [:navigate-to-clean :accounts] + :stop-whisper nil}) + {:show-confirmation {:title (i18n/label :t/close-app-title) + :content (i18n/label :t/close-app-content) + :confirm-button-text (i18n/label :t/close-app-button) + :on-accept #(dispatch [::save-network network]) + :on-cancel nil}})))) diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index 3733c93aed..76b0951ad4 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -12,9 +12,9 @@ (defn show-confirmation ([title content on-accept] (show-confirmation title content nil on-accept)) - ([title content s on-accept] - (show-confirmation title content s on-accept nil)) - ([title content s on-accept on-cancel] + ([title content confirm-button-text on-accept] + (show-confirmation title content confirm-button-text on-accept nil)) + ([title content confirm-button-text on-accept on-cancel] (.alert (.-Alert rn-dependencies/react-native) title content @@ -22,7 +22,9 @@ (clj->js (vector (merge {:text (i18n/label :t/cancel) :style "cancel"} (when on-cancel {:onPress on-cancel})) - {:text (or s "OK") :onPress on-accept :style "destructive"}))))) + {:text (or confirm-button-text "OK") + :onPress on-accept + :style "destructive"}))))) (defn show-question ([title content on-accept]