close app on switching from network with local LES (#2007)

This commit is contained in:
Roman Volosovskyi 2017-10-05 13:23:25 +02:00 committed by GitHub
parent 23eeadf95a
commit 2a9ac44564
12 changed files with 102 additions and 47 deletions

View File

@ -634,4 +634,9 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
thread.start(); thread.start();
} }
@ReactMethod
public void closeApplication() {
System.exit(0);
}
} }

View File

@ -351,7 +351,9 @@ RCT_EXPORT_METHOD(sendWeb3Request:(NSString *)host
}); });
} }
RCT_EXPORT_METHOD(closeApplication) {
exit(0);
}
+ (void)signalEvent:(const char *) signal + (void)signalEvent:(const char *) signal
{ {

View File

@ -72,7 +72,7 @@
:optimize-constants true :optimize-constants true
:optimizations :simple :optimizations :simple
:closure-defines {"goog.DEBUG" false} :closure-defines {"goog.DEBUG" false}
:parallel-build true :parallel-build false
:language-in :ecmascript5} :language-in :ecmascript5}
:warning-handlers [status-im.utils.build/warning-handler]} :warning-handlers [status-im.utils.build/warning-handler]}
:android :android
@ -84,6 +84,6 @@
:optimize-constants true :optimize-constants true
:optimizations :simple :optimizations :simple
:closure-defines {"goog.DEBUG" false} :closure-defines {"goog.DEBUG" false}
:parallel-build true :parallel-build false
:language-in :ecmascript5} :language-in :ecmascript5}
:warning-handlers [status-im.utils.build/warning-handler]}}}}}) :warning-handlers [status-im.utils.build/warning-handler]}}}}})

View File

@ -29,40 +29,44 @@
(def wallet-chat-id "wallet") (def wallet-chat-id "wallet")
(def default-network "testnet_rpc") (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 (def default-networks
{"testnet" {:id "testnet", (transform-config
:name "Ropsten", {"testnet" {:id "testnet",
:config (types/clj->json :name "Ropsten",
{:NetworkId 3 :config {:NetworkId 3
:DataDir "/ethereum/testnet"})} :DataDir "/ethereum/testnet"}}
"testnet_rpc" {:id "testnet_rpc", "testnet_rpc" {:id "testnet_rpc",
:name "Ropsten with upstream RPC", :name "Ropsten with upstream RPC",
:config (types/clj->json :config {:NetworkId 3
{:NetworkId 3
:DataDir "/ethereum/testnet_rpc" :DataDir "/ethereum/testnet_rpc"
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL "https://ropsten.infura.io/z6GCTmjdP3FETEJmMBI4"}})} :URL "https://ropsten.infura.io/z6GCTmjdP3FETEJmMBI4"}}}
"rinkeby" {:id "rinkeby", "rinkeby" {:id "rinkeby",
:name "Rinkeby", :name "Rinkeby",
:config (types/clj->json :config {:NetworkId 4
{:NetworkId 4 :DataDir "/ethereum/rinkeby"}}
:DataDir "/ethereum/rinkeby"})} "rinkeby_rpc" {:id "rinkeby_rpc",
"rinkeby_rpc" {:id "rinkeby_rpc", :name "Rinkeby with upstream RPC",
:name "Rinkeby with upstream RPC", :config {:NetworkId 4
:config (types/clj->json
{:NetworkId 4
:DataDir "/ethereum/rinkeby_rpc" :DataDir "/ethereum/rinkeby_rpc"
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL "https://rinkeby.infura.io/z6GCTmjdP3FETEJmMBI4"}})} :URL "https://rinkeby.infura.io/z6GCTmjdP3FETEJmMBI4"}}}
"mainnet" {:id "mainnet", "mainnet" {:id "mainnet",
:name "Mainnet", :name "Mainnet",
:config (types/clj->json :config {:NetworkId 1
{:NetworkId 1 :DataDir "/ethereum/mainnet"}}
:DataDir "/ethereum/mainnet"})} "mainnet_rpc" {:id "mainnet_rpc",
"mainnet_rpc" {:id "mainnet_rpc", :name "Mainnet with upstream RPC",
:name "Mainnet with upstream RPC", :config {:NetworkId 1
:config (types/clj->json
{:NetworkId 1
:DataDir "/ethereum/mainnet_rpc" :DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL "https://mainnet.infura.io/z6GCTmjdP3FETEJmMBI4 "}})}}) :URL "https://mainnet.infura.io/z6GCTmjdP3FETEJmMBI4 "}}}}))

View File

@ -86,3 +86,6 @@
(defn notify [token callback] (defn notify [token callback]
(module-interface/-notify rns-module token callback)) (module-interface/-notify rns-module token callback))
(defn close-application []
(module-interface/-close-application rns-module))

View File

@ -212,6 +212,9 @@
(when status (when status
(call-module #(.sendWeb3Request status host payload callback)))) (call-module #(.sendWeb3Request status host payload callback))))
(defn close-application []
(.closeApplication status))
(defrecord ReactNativeStatus [] (defrecord ReactNativeStatus []
module/IReactNativeStatus module/IReactNativeStatus
;; status-go calls ;; status-go calls
@ -252,4 +255,6 @@
(-module-initialized! [this] (-module-initialized! [this]
(module-initialized!)) (module-initialized!))
(-should-move-to-internal-storage? [this callback] (-should-move-to-internal-storage? [this callback]
(should-move-to-internal-storage? callback))) (should-move-to-internal-storage? callback))
(-close-application [this]
(close-application)))

View File

@ -58,4 +58,5 @@
(impl/module-initialized!)) (impl/module-initialized!))
(-should-move-to-internal-storage? [this callback] (-should-move-to-internal-storage? [this callback]
(impl/should-move-to-internal-storage? callback)) (impl/should-move-to-internal-storage? callback))
(-notify [this token callback])) (-notify [this token callback])
(-close-application [this]))

View File

@ -18,5 +18,6 @@
(-call-web3 [this host payload callback]) (-call-web3 [this host payload callback])
(-module-initialized! [this]) (-module-initialized! [this])
(-should-move-to-internal-storage? [this callback]) (-should-move-to-internal-storage? [this callback])
(-notify [this token callback])) (-notify [this token callback])
(-close-application [this]))

View File

@ -423,4 +423,7 @@
:remove-network "Remove network" :remove-network "Remove network"
:network-settings "Network settings" :network-settings "Network settings"
:edit-network-warning "Be careful, editing the network data may disable this network for you" :edit-network-warning "Be careful, editing the network data may disable this network for you"
:connecting-requires-login "Connecting to another network requires login"}) :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"})

View File

@ -18,7 +18,7 @@
status-im.ui.screens.qr-scanner.events status-im.ui.screens.qr-scanner.events
status-im.ui.screens.wallet.events status-im.ui.screens.wallet.events
status-im.ui.screens.wallet.send.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.native-module.core :as status]
[status-im.components.permissions :as permissions] [status-im.components.permissions :as permissions]
[status-im.constants :refer [console-chat-id]] [status-im.constants :refer [console-chat-id]]
@ -176,6 +176,17 @@
(fn [] (fn []
(notifications/get-fcm-token))) (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 ;;;; Handlers
(register-handler-db (register-handler-db

View File

@ -3,7 +3,8 @@
[status-im.utils.handlers :refer [register-handler] :as handlers] [status-im.utils.handlers :refer [register-handler] :as handlers]
[status-im.data-store.networks :as networks] [status-im.data-store.networks :as networks]
[status-im.ui.screens.network-settings.navigation] [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 ;;;; FX
@ -27,9 +28,26 @@
(assoc :new-networks (vals new-networks'))) (assoc :new-networks (vals new-networks')))
:save-networks 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 (handlers/register-handler-fx
:connect-network :connect-network
(fn [cofx [_ network]] (fn [{:keys [db] :as cofx} [_ network]]
(merge (accounts-events/account-update cofx {:network network}) (let [current-network (:network db)
{:dispatch [:navigate-to-clean :accounts] networks (:networks/networks db)]
:stop-whisper nil}))) (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}}))))

View File

@ -12,9 +12,9 @@
(defn show-confirmation (defn show-confirmation
([title content on-accept] ([title content on-accept]
(show-confirmation title content nil on-accept)) (show-confirmation title content nil on-accept))
([title content s on-accept] ([title content confirm-button-text on-accept]
(show-confirmation title content s on-accept nil)) (show-confirmation title content confirm-button-text on-accept nil))
([title content s on-accept on-cancel] ([title content confirm-button-text on-accept on-cancel]
(.alert (.-Alert rn-dependencies/react-native) (.alert (.-Alert rn-dependencies/react-native)
title title
content content
@ -22,7 +22,9 @@
(clj->js (clj->js
(vector (merge {:text (i18n/label :t/cancel) :style "cancel"} (vector (merge {:text (i18n/label :t/cancel) :style "cancel"}
(when on-cancel {:onPress on-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 (defn show-question
([title content on-accept] ([title content on-accept]