diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 7406fd2264..f9d0d85b42 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -237,6 +237,11 @@ (fn [cofx [_ _]] (mailserver/retry-next-messages-request cofx))) +(handlers/register-handler-fx + :mailserver.ui/use-history-switch-pressed + (fn [cofx [_ use-mailservers?]] + (mailserver/update-use-mailservers cofx use-mailservers?))) + (handlers/register-handler-fx :mailserver/check-connection-timeout (fn [cofx _] diff --git a/src/status_im/init/core.cljs b/src/status_im/init/core.cljs index 1009562346..03635ee58c 100644 --- a/src/status_im/init/core.cljs +++ b/src/status_im/init/core.cljs @@ -58,10 +58,10 @@ ::open-multiaccounts #(re-frame/dispatch [::initialize-multiaccounts % {:logout? false}]) :ui/listen-to-window-dimensions-change nil ::network/listen-to-network-info nil - :keycard/register-card-events nil - :keycard/check-nfc-support nil - :keycard/check-nfc-enabled nil - :keycard/retrieve-pairings nil} + :keycard/register-card-events nil + :keycard/check-nfc-support nil + :keycard/check-nfc-enabled nil + :keycard/retrieve-pairings nil} (initialize-app-db))) (re-frame/reg-fx diff --git a/src/status_im/mailserver/core.cljs b/src/status_im/mailserver/core.cljs index 99e06ecc0a..54d946c306 100644 --- a/src/status_im/mailserver/core.cljs +++ b/src/status_im/mailserver/core.cljs @@ -220,21 +220,24 @@ Peer summary will change and we will receive a signal from status go when this is successful A connection-check is made after `connection timeout` is reached and - mailserver-state is changed to error if it is not connected by then" + mailserver-state is changed to error if it is not connected by then + No attempt is made if mailserver usage is disabled" {:events [:mailserver.ui/reconnect-mailserver-pressed]} [{:keys [db] :as cofx}] - (let [{:keys [address]} (fetch-current db) + (let [{:keys [address]} (fetch-current db) {:keys [peers-summary]} db - added? (registered-peer? peers-summary address) - gap-request? (executing-gap-request? db)] + use-mailservers? (get-in db [:multiaccount :use-mailservers?]) + added? (registered-peer? peers-summary address) + gap-request? (executing-gap-request? db)] (fx/merge cofx - {:db (cond-> (dissoc db :mailserver/current-request) - gap-request? - (-> (assoc :mailserver/fetching-gaps-in-progress {}) - (dissoc :mailserver/planned-gap-requests)))} - (if added? - (mark-trusted-peer) - (add-peer))))) + (when use-mailservers? + {:db (cond-> (dissoc db :mailserver/current-request) + gap-request? + (-> (assoc :mailserver/fetching-gaps-in-progress {}) + (dissoc :mailserver/planned-gap-requests)))} + (if added? + (mark-trusted-peer) + (add-peer)))))) (defn pool-size [fleet-size] (.ceil js/Math (/ fleet-size 4))) @@ -299,7 +302,7 @@ (mark-trusted-peer cofx) mailserver-removed? (connect-to-mailserver cofx))) - ;; if there is no current mailserver defined, + ;; if there is no current mailserver defined ;; we set it first (set-current-mailserver cofx)))) @@ -489,6 +492,10 @@ dissoc :generating-sym-key?))} (process-next-messages-request)))) +(fx/defn update-use-mailservers + [cofx use-mailservers?] + (multiaccounts.update/multiaccount-update cofx :use-mailservers? use-mailservers? {})) + (fx/defn change-mailserver "mark mailserver status as `:error` if custom mailserver is used otherwise try to reconnect to another mailserver" @@ -1124,11 +1131,14 @@ (let [{:keys [address]} (fetch-current db) pinned-mailservers (get-in db [:multiaccount :pinned-mailservers]) ;; Check if previous mailserver was pinned - pinned? (get pinned-mailservers current-fleet)] + pinned? (get pinned-mailservers current-fleet) + use-mailservers? (get-in db [:multiaccount :use-mailservers?])] (fx/merge cofx {:db (assoc db :mailserver/current-id mailserver-id) :mailserver/remove-peer address} - (connect-to-mailserver) + + (when use-mailservers? (connect-to-mailserver)) + (when pinned? (multiaccounts.update/multiaccount-update :pinned-mailservers (assoc pinned-mailservers diff --git a/src/status_im/mailserver/core_test.cljs b/src/status_im/mailserver/core_test.cljs index 0562f29380..03484fe7d2 100644 --- a/src/status_im/mailserver/core_test.cljs +++ b/src/status_im/mailserver/core_test.cljs @@ -334,7 +334,8 @@ :peers-summary (if registered-peer? [{:id "mailserver-id" :enode "enode://mailserver-id@ip"}] []) - :multiaccount {:fleet :eth.staging} + :multiaccount {:fleet :eth.staging + :use-mailservers? true} :mailserver/current-id "mailserver-a" :mailserver/mailservers {:eth.staging {"mailserver-a" {:sym-key-id sym-key :address "enode://mailserver-id@ip"}}}}}) @@ -611,7 +612,8 @@ :password "mailserver-password"}}} :multiaccount {:fleet :eth.staging - :pinned-mailservers {:eth.staging "mailserverid"}}}] + :pinned-mailservers {:eth.staging "mailserverid"} + :use-mailservers? true}}] (testing "it adds the peer" (is (= "mailserver-address" (:mailserver/add-peer (mailserver/connect-to-mailserver {:db db}))))) @@ -625,7 +627,12 @@ "somesymkeyid")] (testing "it does not generate a sym key if already present" (is (not (-> (mailserver/connect-to-mailserver {:db mailserver-with-sym-key-db}) - :shh/generate-sym-key-from-password))))))) + :shh/generate-sym-key-from-password))))) + + (testing "it returns noops when use-mailservers? is false" + (let [no-mailservers-cofx {:db (assoc-in db [:multiaccount :use-mailservers?] false)}] + (is (= (mailserver/connect-to-mailserver no-mailservers-cofx) + no-mailservers-cofx)))))) (deftest check-existing-gaps (testing "no gaps" diff --git a/src/status_im/multiaccounts/create/core.cljs b/src/status_im/multiaccounts/create/core.cljs index 3cf937a666..639dbafd6e 100644 --- a/src/status_im/multiaccounts/create/core.cljs +++ b/src/status_im/multiaccounts/create/core.cljs @@ -253,6 +253,8 @@ :signing-phrase signing-phrase :send-push-notifications? true :installation-id (random-guid-generator) + ;; default mailserver (history node) setting + :use-mailservers? true :recovered (or recovered (get-in db [:intro-wizard :recovering?]))} constants/default-multiaccount) ;; The address from which we derive any chat diff --git a/src/status_im/ui/screens/offline_messaging_settings/styles.cljs b/src/status_im/ui/screens/offline_messaging_settings/styles.cljs index 4e8040b6c7..ec4d37e9d8 100644 --- a/src/status_im/ui/screens/offline_messaging_settings/styles.cljs +++ b/src/status_im/ui/screens/offline_messaging_settings/styles.cljs @@ -5,15 +5,10 @@ (def wrapper {:flex 1}) -(def mailserver-item-inner - {:padding-horizontal 16}) - -(styles/defn mailserver-item [pinned?] +(styles/defn mailserver-item [] {:flex-direction :row :align-items :center - :opacity (if pinned? - 1 - 0.4) + :justify-content :space-between :padding-horizontal 16 :ios {:height 64} :android {:height 56}}) @@ -31,21 +26,24 @@ :align-items :center :justify-content :center}) -(defn mailserver-icon [connected?] - (hash-map :color - (if connected? colors/white-persist colors/gray))) +(def switch-container + {:height 52}) -(def mailserver-pinned - {:padding-horizontal 16 - :flex-direction :row - :align-items :center - :padding-vertical 5}) +(def automatic-selection-container + {:border-top-width 1 + :border-top-color colors/gray-lighter + :margin-top 16}) -(def mailserver-pinned-checkbox-container - {:width 40 - :height 40 - :align-items :center - :justify-content :center}) +(def explanation-text + {:color colors/gray}) -(def mailserver-pinned-text-container - {:padding-horizontal 15}) +(def use-history-explanation-text-container + {:margin-right 16 + :margin-left 16 + :margin-top 8 + :margin-bottom 16}) + +(def history-nodes-label + {:color colors/gray + :padding-horizontal 16 + :margin-top 48}) diff --git a/src/status_im/ui/screens/offline_messaging_settings/views.cljs b/src/status_im/ui/screens/offline_messaging_settings/views.cljs index 50007af111..30b071c5af 100644 --- a/src/status_im/ui/screens/offline_messaging_settings/views.cljs +++ b/src/status_im/ui/screens/offline_messaging_settings/views.cljs @@ -2,60 +2,78 @@ (:require-macros [status-im.utils.views :as views]) (:require [re-frame.core :as re-frame] [status-im.i18n :as i18n] - [status-im.ui.components.checkbox.view :as checkbox.views] [status-im.ui.components.icons.vector-icons :as vector-icons] [status-im.ui.components.list.views :as list] [status-im.ui.components.react :as react] + [status-im.ui.components.radio :as radio] + [status-im.ui.components.colors :as colors] [status-im.ui.screens.offline-messaging-settings.styles :as styles] + [status-im.ui.screens.profile.components.views :as profile.components] [status-im.ui.components.topbar :as topbar])) -(defn- mailserver-icon [connected?] - [react/view (styles/mailserver-icon-container connected?) - [vector-icons/icon :main-icons/mailserver - (styles/mailserver-icon connected?)]]) - (defn pinned-state [pinned?] - [react/touchable-highlight {:on-press (if pinned? - #(re-frame/dispatch [:mailserver.ui/unpin-pressed]) - #(re-frame/dispatch [:mailserver.ui/pin-pressed]))} - [react/view {:style styles/mailserver-pinned} - [checkbox.views/checkbox - {:checked? (not pinned?) - :style styles/mailserver-pinned-checkbox-container - :on-value-change (if pinned? - #(re-frame/dispatch [:mailserver.ui/unpin-pressed]) - #(re-frame/dispatch [:mailserver.ui/pin-pressed]))}] - [react/view {:style styles/mailserver-pinned-text-container} - [react/text (i18n/label :t/mailserver-automatic)]]]]) + [react/view {:style styles/automatic-selection-container} + [react/view {:style styles/switch-container} + [profile.components/settings-switch-item + {:label-kw :t/mailserver-automatic + :value (not pinned?) + :action-fn #(if pinned? + (re-frame/dispatch [:mailserver.ui/unpin-pressed]) + (re-frame/dispatch [:mailserver.ui/pin-pressed]))}]] + [react/view {:style {:padding-horizontal 16}} + [react/text {:style styles/explanation-text} + (i18n/label :t/mailserver-automatic-switch-explanation)]]]) (defn render-row [current-mailserver-id pinned?] (fn [{:keys [name id user-defined]}] - (let [connected? (= id current-mailserver-id)] - [react/touchable-highlight - {:on-press (when pinned? #(if user-defined - (re-frame/dispatch [:mailserver.ui/user-defined-mailserver-selected id]) - (re-frame/dispatch [:mailserver.ui/default-mailserver-selected id]))) - :accessibility-label :mailserver-item} - [react/view (styles/mailserver-item pinned?) - [mailserver-icon connected?] - [react/view styles/mailserver-item-inner - [react/text {:style styles/mailserver-item-name-text} - name]]]]))) + (let [connected? (= id current-mailserver-id) + visible? (or pinned? ; show everything when auto selection is turned off + (and (not pinned?) ; auto selection turned on + (= current-mailserver-id id) ; show only the selected server + ))] + (when visible? + [react/touchable-highlight + {:on-press (when pinned? #(if user-defined + (re-frame/dispatch [:mailserver.ui/user-defined-mailserver-selected id]) + (re-frame/dispatch [:mailserver.ui/default-mailserver-selected id]))) + :accessibility-label :mailserver-item} + [react/view (styles/mailserver-item) + [react/text {:style styles/mailserver-item-name-text} + name] + + (if pinned? + [radio/radio connected?] + [vector-icons/icon :check {:color colors/blue}])]])))) (views/defview offline-messaging-settings [] - (views/letsubs [current-mailserver-id [:mailserver/current-id] - preferred-mailserver-id [:mailserver/preferred-id] - mailservers [:mailserver/fleet-mailservers]] - [react/view {:flex 1} + (views/letsubs [current-mailserver-id [:mailserver/current-id] + preferred-mailserver-id [:mailserver/preferred-id] + mailservers [:mailserver/fleet-mailservers] + {:keys [use-mailservers?]} [:multiaccount]] + [react/view {:style styles/wrapper} [topbar/topbar - {:title (i18n/label :t/offline-messaging-settings) + {:title (i18n/label :t/offline-messaging-settings) :right-accessories - [{:icon :main-icons/add + [{:icon :main-icons/add-circle :on-press #(re-frame/dispatch [:mailserver.ui/add-pressed])}]}] - [react/view styles/wrapper - [pinned-state preferred-mailserver-id] - [list/flat-list {:data (vals mailservers) - :default-separator? false - :key-fn :name - :render-fn (render-row current-mailserver-id - preferred-mailserver-id)}]]])) + + [react/view {:style styles/switch-container} + [profile.components/settings-switch-item + {:label-kw :t/offline-messaging-use-history-nodes + :value use-mailservers? + :action-fn #(re-frame/dispatch [:mailserver.ui/use-history-switch-pressed (not use-mailservers?)])}]] + [react/view {:style styles/use-history-explanation-text-container} + [react/text {:style styles/explanation-text} + (i18n/label :t/offline-messaging-use-history-explanation)]] + + (when use-mailservers? + [:<> + [pinned-state preferred-mailserver-id] + + [react/text {:style styles/history-nodes-label} + (i18n/label :t/history-nodes)] + [list/flat-list {:data (vals mailservers) + :default-separator? false + :key-fn :name + :render-fn (render-row current-mailserver-id + preferred-mailserver-id)}]])])) diff --git a/src/status_im/ui/screens/sync_settings/views.cljs b/src/status_im/ui/screens/sync_settings/views.cljs index 97c8586385..c63d880263 100644 --- a/src/status_im/ui/screens/sync_settings/views.cljs +++ b/src/status_im/ui/screens/sync_settings/views.cljs @@ -8,7 +8,8 @@ [status-im.ui.components.topbar :as topbar])) (views/defview sync-settings [] - (views/letsubs [{:keys [syncing-on-mobile-network?]} [:multiaccount] + (views/letsubs [{:keys [syncing-on-mobile-network? + use-mailservers?]} [:multiaccount] mailserver-id [:mailserver/current-id]] [react/view {:style {:flex 1 :background-color colors/white}} [topbar/topbar {:title (i18n/label :t/sync-settings)}] @@ -28,7 +29,7 @@ :title (i18n/label :t/offline-messaging) :on-press #(re-frame/dispatch [:navigate-to :offline-messaging-settings]) :accessory :text - :accessory-text mailserver-id + :accessory-text (when use-mailservers? mailserver-id) :chevron true}] ;; TODO(Ferossgp): Devider componemt [react/view {:height 1 diff --git a/status-go-version.json b/status-go-version.json index 8f1f89c4b9..dd3945c896 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' instead", "owner": "status-im", "repo": "status-go", - "version": "v0.62.8", - "commit-sha1": "efbf093bc494e9c3ea00a6a3e8f286826294dff7", - "src-sha256": "0rbyzr360l2dv9gyinc7dwvd8hw6wwgs8lrs5kl3dl8bzxbrfsyj" + "version": "v0.62.11", + "commit-sha1": "4ecca1169d2e0a07b4e0cf5a7a3f4044216c678f", + "src-sha256": "189igps203m2yf3gcqjrghqnncf7vgl3p3bjcrk5dp2ym00jfr9f" } diff --git a/translations/en.json b/translations/en.json index 81de8e5961..4797518844 100644 --- a/translations/en.json +++ b/translations/en.json @@ -502,6 +502,7 @@ "hide-content-when-switching-apps": "Block screenshots", "hide-content-when-switching-apps-ios": "Hide preview", "history": "History", + "history-nodes": "History nodes", "hold-card": "Hold card to the back\n of your phone", "home": "Home", "hooks": "Hooks", @@ -673,6 +674,7 @@ "lost-connection": "Lost connection", "mailserver-address": "Mailserver address", "mailserver-automatic": "Automatic selection", + "mailserver-automatic-switch-explanation": "Choose the fastest history node available", "mailserver-connection-error": "Could not connect to mailserver", "mailserver-details": "Mailserver details", "mailserver-error-content": "The mailserver you selected couldn't be reached.", @@ -807,7 +809,9 @@ "off": "Off", "offline": "Offline", "offline-messaging": "Mailserver", - "offline-messaging-settings": "Mailserver settings", + "offline-messaging-settings": "History nodes", + "offline-messaging-use-history-nodes": "Use history nodes", + "offline-messaging-use-history-explanation": "Enable history nodes to fetch messages that were sent while the app was closed. When enabled, a history node gets your IP address. When disabled you will not receive messages when the app is closed and will not see them when you open the app later.", "ok": "OK", "ok-continue": "Okay, continue", "ok-got-it": "Okay, got it",