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();
}
@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
{

View File

@ -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]}}}}})

View File

@ -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 "}}}}))

View File

@ -86,3 +86,6 @@
(defn notify [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
(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)))

View File

@ -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]))

View File

@ -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]))

View File

@ -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"})
: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.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

View File

@ -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}}))))

View File

@ -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]