From 65e7e06b274e1f16b7334c57fcdac337eaa94bf7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 21 Mar 2019 16:39:37 +0200 Subject: [PATCH] [#7681] Show confirmation dialog on switching to network with upstream RPC --- src/status_im/events.cljs | 5 ++++ src/status_im/network/core.cljs | 45 +++++++++++++++++++++------------ translations/en.json | 1 + 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index b7b28f8201..75b5319395 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -498,6 +498,11 @@ (fn [cofx [_ network]] (network/save-non-rpc-network cofx network))) +(handlers/register-handler-fx + :network.ui/save-rpc-network-pressed + (fn [cofx [_ network]] + (network/save-rpc-network cofx network))) + (handlers/register-handler-fx :network.ui/remove-network-confirmed (fn [cofx [_ network]] diff --git a/src/status_im/network/core.cljs b/src/status_im/network/core.cljs index 220516d066..8a80a9cb20 100644 --- a/src/status_im/network/core.cljs +++ b/src/status_im/network/core.cljs @@ -108,22 +108,27 @@ {:db (assoc db :networks/manage (validate-manage default-manage)) :dispatch [:navigate-to :edit-network]}) -(fx/defn connect-success [{:keys [db now] :as cofx} {:keys [network-id on-success client-version]}] - (let [current-network (get-in db [:account/account :networks (:network db)])] - (if (ethereum/network-with-upstream-rpc? current-network) - (fx/merge cofx - #(action-handler on-success {:network-id network-id :client-version client-version} %) - (accounts.update/account-update - {:network network-id - :last-updated now} - {:success-event [:accounts.update.callback/save-settings-success]})) - (fx/merge cofx - {:ui/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 #(re-frame/dispatch [:network.ui/save-non-rpc-network-pressed network-id]) - :on-cancel nil}} - #(action-handler on-success {:network-id network-id :client-version client-version} %))))) +(fx/defn connect-success [{:keys [db] :as cofx} + {:keys [network-id on-success client-version]}] + (let [current-network (get-in db [:account/account :networks (:network db)]) + network-with-upstream-rpc? (ethereum/network-with-upstream-rpc? + current-network)] + (fx/merge + cofx + {:ui/show-confirmation + {:title (i18n/label :t/close-app-title) + :content (if network-with-upstream-rpc? + (i18n/label :t/logout-app-content) + (i18n/label :t/close-app-content)) + :confirm-button-text (i18n/label :t/close-app-button) + :on-accept #(re-frame/dispatch + [(if network-with-upstream-rpc? + :network.ui/save-rpc-network-pressed + :network.ui/save-non-rpc-network-pressed) + network-id]) + :on-cancel nil}} + #(action-handler on-success {:network-id network-id + :client-version client-version} %)))) (defn connect-failure [{:keys [network-id on-failure reason]}] (action-handler on-failure @@ -193,6 +198,14 @@ :last-updated now} {:success-event [:network.callback/non-rpc-network-saved]})) +(fx/defn save-rpc-network + [{:keys [now] :as cofx} network] + (accounts.update/account-update + cofx + {:network network + :last-updated now} + {:success-event [:accounts.update.callback/save-settings-success]})) + (fx/defn remove-network [{:keys [db now] :as cofx} network] (let [networks (dissoc (get-in db [:account/account :networks]) network)] diff --git a/translations/en.json b/translations/en.json index c26f3ae0d7..0e3af9d224 100644 --- a/translations/en.json +++ b/translations/en.json @@ -640,6 +640,7 @@ "soon": "Soon", "wallet-asset": "Asset", "close-app-content": "The app will stop and close. When you reopen it, the selected network will be used", + "logout-app-content": "The account will be logged out. When you log in again, the selected network will be used", "password-description": "You'll need this password to open the app and confirm transactions.", "currency-display-name-afn": "Afghanistan Afghani", "word-n-description": "In order to check if you have backed up your recovery phrase correctly, enter the word #{{number}} above.",