From 619e176087f55e7d9bf22166a3d0dbbe8b3f7c17 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Thu, 27 Feb 2020 13:24:45 +0100 Subject: [PATCH] Set waku mode dynamically This commit allows setting waku-mode and waku-bloom-filter-mode dynamically. It requires a relogin for the changes to take effect. Signed-off-by: Andrea Maria Piana --- src/status_im/chat/models.cljs | 3 +- src/status_im/chat/models/loading.cljs | 13 +- src/status_im/chat/models/message.cljs | 6 +- src/status_im/commands/core.cljs | 9 +- src/status_im/contact/core.cljs | 3 +- src/status_im/data_store/chats.cljs | 5 +- src/status_im/data_store/contacts.cljs | 7 +- src/status_im/data_store/messages.cljs | 52 +++----- src/status_im/ens/core.cljs | 28 ---- src/status_im/ethereum/json_rpc.cljs | 4 +- src/status_im/events.cljs | 1 + src/status_im/group_chats/core.cljs | 15 ++- src/status_im/mailserver/core.cljs | 49 ++++--- src/status_im/multiaccounts/login/core.cljs | 2 +- src/status_im/multiaccounts/update/core.cljs | 4 +- .../multiaccounts/update/publisher.cljs | 5 +- src/status_im/node/core.cljs | 4 +- src/status_im/pairing/core.cljs | 121 ++++++++++-------- src/status_im/signing/core.cljs | 5 +- src/status_im/subs.cljs | 12 ++ src/status_im/transport/core.cljs | 3 +- src/status_im/transport/filters/core.cljs | 50 ++++---- src/status_im/transport/message/protocol.cljs | 20 +-- src/status_im/transport/shh.cljs | 28 ++-- .../ui/screens/advanced_settings/views.cljs | 60 +++++++-- src/status_im/utils/fx.cljs | 1 - src/status_im/waku/core.cljs | 28 ++++ src/status_im/wallet/core.cljs | 5 +- test/cljs/status_im/test/mailserver/core.cljs | 2 +- .../test/transport/filters/core.cljs | 22 ++-- translations/en.json | 4 +- 31 files changed, 327 insertions(+), 244 deletions(-) create mode 100644 src/status_im/waku/core.cljs diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index 7eb96eccbc..ac2fed9d0c 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -3,6 +3,7 @@ [status-im.multiaccounts.model :as multiaccounts.model] [status-im.transport.filters.core :as transport.filters] [status-im.contact.core :as contact.core] + [status-im.waku.core :as waku] [status-im.contact.db :as contact.db] [status-im.data-store.chats :as chats-store] [status-im.data-store.messages :as messages-store] @@ -127,7 +128,7 @@ {:events [:chat.ui/mark-all-read-pressed :chat.ui/mark-public-all-read]} [{:keys [db] :as cofx} chat-id] - {::json-rpc/call [{:method (json-rpc/call-ext-method "markAllRead") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "markAllRead") :params [chat-id] :on-success #(re-frame/dispatch [::mark-all-read-successful chat-id])}]}) diff --git a/src/status_im/chat/models/loading.cljs b/src/status_im/chat/models/loading.cljs index 932e3950d0..82f01bc9b7 100644 --- a/src/status_im/chat/models/loading.cljs +++ b/src/status_im/chat/models/loading.cljs @@ -2,6 +2,7 @@ (:require [re-frame.core :as re-frame] [status-im.constants :as constants] [status-im.ui.screens.chat.state :as chat.state] + [status-im.waku.core :as waku] [status-im.data-store.chats :as data-store.chats] [status-im.data-store.messages :as data-store.messages] [status-im.transport.filters.core :as filters] @@ -140,11 +141,13 @@ (when-not (or (get-in db [:chats current-chat-id :all-loaded?]) (get-in db [:chats current-chat-id :loading-messages?])) (let [cursor (get-in db [:chats current-chat-id :cursor]) - load-messages-fx (data-store.messages/messages-by-chat-id-rpc current-chat-id - cursor - constants/default-number-of-messages - #(re-frame/dispatch [::messages-loaded current-chat-id session-id %]) - #(re-frame/dispatch [::failed-loading-messages current-chat-id session-id %]))] + load-messages-fx (data-store.messages/messages-by-chat-id-rpc + (waku/enabled? cofx) + current-chat-id + cursor + constants/default-number-of-messages + #(re-frame/dispatch [::messages-loaded current-chat-id session-id %]) + #(re-frame/dispatch [::failed-loading-messages current-chat-id session-id %]))] (fx/merge cofx load-messages-fx (mailserver/load-gaps-fx current-chat-id))))))) diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index 99b7a89124..ced7a237a4 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -4,6 +4,7 @@ [status-im.ethereum.json-rpc :as json-rpc] [status-im.utils.config :as config] [status-im.chat.db :as chat.db] + [status-im.waku.core :as waku] [status-im.chat.models :as chat-model] [status-im.chat.models.loading :as chat-loading] [status-im.chat.models.message-list :as message-list] @@ -207,7 +208,7 @@ (fx/defn resend-message [{:keys [db] :as cofx} chat-id message-id] (fx/merge cofx - {::json-rpc/call [{:method (json-rpc/call-ext-method "reSendChatMessage") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "reSendChatMessage") :params [message-id] :on-success #(log/debug "re-sent message successfully") :on-error #(log/error "failed to re-send message" %)}]} @@ -228,9 +229,6 @@ :current-chat? true}) messages))) -(fx/defn add-system-messages [cofx messages] - (data-store.messages/save-system-messages cofx messages)) - (fx/defn send-message [{:keys [db now] :as cofx} {:keys [chat-id] :as message}] (protocol/send-chat-message cofx message)) diff --git a/src/status_im/commands/core.cljs b/src/status_im/commands/core.cljs index 2a56c05793..5565ef67d9 100644 --- a/src/status_im/commands/core.cljs +++ b/src/status_im/commands/core.cljs @@ -2,6 +2,7 @@ (:require [re-frame.core :as re-frame] [status-im.ethereum.core :as ethereum] + [status-im.waku.core :as waku] [status-im.utils.config :as config] [status-im.ethereum.json-rpc :as json-rpc] [status-im.utils.fx :as fx])) @@ -22,22 +23,22 @@ (fx/defn handle-accept-request-address-for-transaction {:events [::accept-request-address-for-transaction]} - [{:keys [db]} message-id address] + [{:keys [db] :as cofx} message-id address] {:db (dissoc db :commands/select-account) - ::json-rpc/call [{:method (json-rpc/call-ext-method "acceptRequestAddressForTransaction") + ::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "acceptRequestAddressForTransaction") :params [message-id address] :on-success #(re-frame/dispatch [:transport/message-sent % 1])}]}) (fx/defn handle-decline-request-address-for-transaction {:events [::decline-request-address-for-transaction]} [cofx message-id] - {::json-rpc/call [{:method (json-rpc/call-ext-method "declineRequestAddressForTransaction") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "declineRequestAddressForTransaction") :params [message-id] :on-success #(re-frame/dispatch [:transport/message-sent % 1])}]}) (fx/defn handle-decline-request-transaction {:events [::decline-request-transaction]} [cofx message-id] - {::json-rpc/call [{:method (json-rpc/call-ext-method "declineRequestTransaction") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "declineRequestTransaction") :params [message-id] :on-success #(re-frame/dispatch [:transport/message-sent % 1])}]}) diff --git a/src/status_im/contact/core.cljs b/src/status_im/contact/core.cljs index a06a1f6c3d..11cc09482c 100644 --- a/src/status_im/contact/core.cljs +++ b/src/status_im/contact/core.cljs @@ -3,6 +3,7 @@ [re-frame.core :as re-frame] [taoensso.timbre :as log] [status-im.multiaccounts.update.core :as multiaccounts.update] + [status-im.waku.core :as waku] [status-im.multiaccounts.model :as multiaccounts.model] [status-im.transport.filters.core :as transport.filters] [status-im.contact.db :as contact.db] @@ -76,7 +77,7 @@ (fx/defn send-contact-request [{:keys [db] :as cofx} {:keys [public-key] :as contact}] (let [{:keys [name profile-image]} (own-info db)] - {::json-rpc/call [{:method (json-rpc/call-ext-method "sendContactUpdate") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "sendContactUpdate") :params [public-key name profile-image] :on-success #(log/debug "contact request sent" public-key)}]})) diff --git a/src/status_im/data_store/chats.cljs b/src/status_im/data_store/chats.cljs index fb91d481d7..85b41d4013 100644 --- a/src/status_im/data_store/chats.cljs +++ b/src/status_im/data_store/chats.cljs @@ -2,6 +2,7 @@ (:require [goog.object :as object] [re-frame.core :as re-frame] [status-im.data-store.messages :as messages] + [status-im.waku.core :as waku] [status-im.utils.config :as config] [status-im.utils.fx :as fx] [status-im.ethereum.json-rpc :as json-rpc] @@ -114,13 +115,13 @@ (dissoc :chatType :members))) (fx/defn save-chat [cofx {:keys [chat-id] :as chat}] - {::json-rpc/call [{:method (json-rpc/call-ext-method "saveChat") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "saveChat") :params [(->rpc chat)] :on-success #(log/debug "saved chat" chat-id "successfuly") :on-failure #(log/error "failed to save chat" chat-id %)}]}) (fx/defn fetch-chats-rpc [cofx {:keys [on-success]}] - {::json-rpc/call [{:method (json-rpc/call-ext-method "chats") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "chats") :params [] :on-success #(on-success (map <-rpc %)) :on-failure #(log/error "failed to fetch chats" 0 -1 %)}]}) diff --git a/src/status_im/data_store/contacts.cljs b/src/status_im/data_store/contacts.cljs index 21e6826dcb..311f5e5b58 100644 --- a/src/status_im/data_store/contacts.cljs +++ b/src/status_im/data_store/contacts.cljs @@ -2,6 +2,7 @@ (:require [re-frame.core :as re-frame] [status-im.utils.fx :as fx] [status-im.utils.config :as config] + [status-im.waku.core :as waku] [status-im.data-store.chats :as data-store.chats] [status-im.ethereum.json-rpc :as json-rpc] [taoensso.timbre :as log] @@ -46,20 +47,20 @@ (fx/defn fetch-contacts-rpc [cofx on-success] - {::json-rpc/call [{:method (json-rpc/call-ext-method "contacts") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "contacts") :params [] :on-success #(on-success (map <-rpc %)) :on-failure #(log/error "failed to fetch contacts" %)}]}) (fx/defn save-contact [cofx {:keys [public-key] :as contact}] - {::json-rpc/call [{:method (json-rpc/call-ext-method "saveContact") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "saveContact") :params [(->rpc contact)] :on-success #(log/debug "saved contact" public-key "successfuly") :on-failure #(log/error "failed to save contact" public-key %)}]}) (fx/defn block [cofx contact on-success] - {::json-rpc/call [{:method (json-rpc/call-ext-method "blockContact") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "blockContact") :params [(->rpc contact)] :on-success on-success :on-failure #(log/error "failed to block contact" % contact)}]}) diff --git a/src/status_im/data_store/messages.cljs b/src/status_im/data_store/messages.cljs index b12f42b2f0..dc121a40cf 100644 --- a/src/status_im/data_store/messages.cljs +++ b/src/status_im/data_store/messages.cljs @@ -5,6 +5,7 @@ [clojure.string :as string] [taoensso.timbre :as log] [re-frame.core :as re-frame] + [status-im.waku.core :as waku] [status-im.utils.types :as utils.types] [status-im.utils.config :as config] [status-im.ethereum.json-rpc :as json-rpc] @@ -46,72 +47,59 @@ :outgoing (boolean (:outgoingStatus message))) (dissoc :ensName :chatId :text :rtl :responseTo :sticker :lineCount :parsedText))) -(defn update-outgoing-status-rpc [message-id status] - {::json-rpc/call [{:method (json-rpc/call-ext-method "updateMessageOutgoingStatus") +(defn update-outgoing-status-rpc [waku-enabled? message-id status] + {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "updateMessageOutgoingStatus") :params [message-id status] :on-success #(log/debug "updated message outgoing stauts" message-id status) :on-failure #(log/error "failed to update message outgoing status" message-id status %)}]}) -(defn save-system-messages-rpc [messages] - (json-rpc/call {:method (json-rpc/call-ext-method "addSystemMessages") - :params [(map ->rpc messages)] - :on-success #(re-frame/dispatch [:messages/system-messages-saved (map <-rpc %)]) - :on-failure #(log/error "failed to save messages" %)})) - -(defn messages-by-chat-id-rpc [chat-id +(defn messages-by-chat-id-rpc [waku-enabled? + chat-id cursor limit on-success on-failure] - {::json-rpc/call [{:method (json-rpc/call-ext-method "chatMessages") + {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "chatMessages") :params [chat-id cursor limit] :on-success (fn [result] (on-success (update result :messages #(map <-rpc %)))) :on-failure on-failure}]}) -(defn mark-seen-rpc [chat-id ids] - {::json-rpc/call [{:method (json-rpc/call-ext-method "markMessagesSeen") +(defn mark-seen-rpc [waku-enabled? chat-id ids] + {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "markMessagesSeen") :params [chat-id ids] :on-success #(log/debug "successfully marked as seen") :on-failure #(log/error "failed to get messages" %)}]}) -(defn delete-message-rpc [id] - {::json-rpc/call [{:method (json-rpc/call-ext-method "deleteMessage") +(defn delete-message-rpc [waku-enabled? id] + {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "deleteMessage") :params [id] :on-success #(log/debug "successfully deleted message" id) :on-failure #(log/error "failed to delete message" % id)}]}) -(defn delete-messages-from-rpc [author] - {::json-rpc/call [{:method (json-rpc/call-ext-method "deleteMessagesFrom") +(defn delete-messages-from-rpc [waku-enabled? author] + {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "deleteMessagesFrom") :params [author] :on-success #(log/debug "successfully deleted messages from" author) :on-failure #(log/error "failed to delete messages from" % author)}]}) -(defn delete-messages-by-chat-id-rpc [chat-id] - {::json-rpc/call [{:method (json-rpc/call-ext-method "deleteMessagesByChatID") +(defn delete-messages-by-chat-id-rpc [waku-enabled? chat-id] + {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "deleteMessagesByChatID") :params [chat-id] :on-success #(log/debug "successfully deleted messages by chat-id" chat-id) :on-failure #(log/error "failed to delete messages by chat-id" % chat-id)}]}) -(re-frame/reg-fx - ::save-system-message - (fn [messages] - (save-system-messages-rpc messages))) - -(fx/defn save-system-messages [cofx messages] - {::save-system-message messages}) - (fx/defn delete-message [cofx id] - (delete-message-rpc id)) + (delete-message-rpc (waku/enabled? cofx) id)) (fx/defn delete-messages-from [cofx author] - (delete-messages-from-rpc author)) + (delete-messages-from-rpc (waku/enabled? cofx) author)) -(fx/defn mark-messages-seen [_ chat-id ids] - (mark-seen-rpc chat-id ids)) +(fx/defn mark-messages-seen [cofx chat-id ids] + (mark-seen-rpc (waku/enabled? cofx) chat-id ids)) (fx/defn update-outgoing-status [cofx message-id status] - (update-outgoing-status-rpc message-id status)) + (update-outgoing-status-rpc (waku/enabled? cofx) message-id status)) (fx/defn delete-messages-by-chat-id [cofx chat-id] - (delete-messages-by-chat-id-rpc chat-id)) + (delete-messages-by-chat-id-rpc (waku/enabled? cofx) chat-id)) diff --git a/src/status_im/ens/core.cljs b/src/status_im/ens/core.cljs index 322b4bfe9a..6baba5b7d0 100644 --- a/src/status_im/ens/core.cljs +++ b/src/status_im/ens/core.cljs @@ -291,31 +291,3 @@ (fx/merge cofx (set-username-candidate (get-in db [:ens/registration :username] "")) (navigation/navigate-to-cofx :ens-search {}))) - -(defn verify-names [names] - (json-rpc/call {:method (json-rpc/call-ext-method "verifyENSNames") - :params [names] - :on-success #(re-frame/dispatch [:contacts/ens-names-verified %]) - :on-failure #(log/error "failed to resolve ens names" % names)})) - -(re-frame/reg-fx - ::verify-names - (fn [names] - (verify-names (distinct names)))) - -(defn should-be-verified? [cofx ens-name signature] - (and ens-name - (not (get-in cofx [:contacts/contacts signature :ens-verified])) - (not= signature (multiaccounts.model/current-public-key cofx)) - (or (valid-custom-domain? ens-name) - (stateofus/valid-username? ens-name)))) - -(fx/defn verify-names-from-message [cofx {:keys [content]} signature] - (when (should-be-verified? cofx (:ens-name content) signature) - {::verify-names [{:name (:ens-name content) - :publicKey (subs signature 2)}]})) - -(fx/defn verify-names-from-contact-request [cofx {:keys [name]} signature] - (when (should-be-verified? cofx name signature) - {::verify-names [{:name name - :publicKey (subs signature 2)}]})) diff --git a/src/status_im/ethereum/json_rpc.cljs b/src/status_im/ethereum/json_rpc.cljs index c4c3f8e4d1..4b1372b2ff 100644 --- a/src/status_im/ethereum/json_rpc.cljs +++ b/src/status_im/ethereum/json_rpc.cljs @@ -178,8 +178,8 @@ (call-method (update arg :number-of-retries dec))) on-error)) -(defn call-ext-method [method] - (if config/waku-enabled? +(defn call-ext-method [waku-enabled? method] + (if waku-enabled? (str "wakuext_" method) (str "shhext_" method))) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 16761c2f61..1f3f9d87fc 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -30,6 +30,7 @@ [status-im.i18n :as i18n] [status-im.init.core :as init] [status-im.log-level.core :as log-level] + status-im.waku.core [status-im.mailserver.core :as mailserver] [status-im.mailserver.constants :as mailserver.constants] [status-im.mailserver.topics :as mailserver.topics] diff --git a/src/status_im/group_chats/core.cljs b/src/status_im/group_chats/core.cljs index 2bb0be1819..00ca41661d 100644 --- a/src/status_im/group_chats/core.cljs +++ b/src/status_im/group_chats/core.cljs @@ -14,6 +14,7 @@ [status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.model :as multiaccounts.model] [status-im.utils.pairing :as pairing.utils] + [status-im.waku.core :as waku] [status-im.chat.models :as models.chat] [status-im.chat.models.message :as models.message] [status-im.contact.core :as models.contact] @@ -31,7 +32,7 @@ (fx/defn remove-member "Format group update message and sign membership" [{:keys [db] :as cofx} chat-id member] - {::json-rpc/call [{:method (json-rpc/call-ext-method "removeMemberFromGroupChat") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "removeMemberFromGroupChat") :params [nil chat-id member] :on-success #(re-frame/dispatch [::chat-updated %])}]}) @@ -74,33 +75,33 @@ (fx/defn join-chat [cofx chat-id] - {::json-rpc/call [{:method (json-rpc/call-ext-method "confirmJoiningGroup") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "confirmJoiningGroup") :params [chat-id] :on-success #(re-frame/dispatch [::chat-updated %])}]}) (fx/defn create [{:keys [db] :as cofx} group-name] (let [selected-contacts (:group/selected-contacts db)] - {::json-rpc/call [{:method (json-rpc/call-ext-method "createGroupChatWithMembers") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "createGroupChatWithMembers") :params [nil group-name (into [] selected-contacts)] :on-success #(re-frame/dispatch [::chat-updated %])}]})) (fx/defn make-admin [{:keys [db] :as cofx} chat-id member] - {::json-rpc/call [{:method (json-rpc/call-ext-method "addAdminsToGroupChat") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "addAdminsToGroupChat") :params [nil chat-id [member]] :on-success #(re-frame/dispatch [::chat-updated %])}]}) (fx/defn add-members "Add members to a group chat" [{{:keys [current-chat-id selected-participants]} :db :as cofx}] - {::json-rpc/call [{:method (json-rpc/call-ext-method "addMembersToGroupChat") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "addMembersToGroupChat") :params [nil current-chat-id selected-participants] :on-success #(re-frame/dispatch [::chat-updated %])}]}) (fx/defn remove "Remove & leave chat" [{:keys [db] :as cofx} chat-id] - {::json-rpc/call [{:method (json-rpc/call-ext-method "leaveGroupChat") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "leaveGroupChat") :params [nil chat-id] :on-success #(re-frame/dispatch [::chat-updated %])}]}) @@ -123,7 +124,7 @@ (let [new-name (get-in cofx [:db :group-chat-profile/profile :name]) current-chat-id (:current-chat-id db)] (when (valid-name? new-name) - {::json-rpc/call [{:method (json-rpc/call-ext-method "changeGroupChatName") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "changeGroupChatName") :params [nil current-chat-id new-name] :on-success #(re-frame/dispatch [::chat-updated %])}]}))) diff --git a/src/status_im/mailserver/core.cljs b/src/status_im/mailserver/core.cljs index 0b17cf95e0..bdee683492 100644 --- a/src/status_im/mailserver/core.cljs +++ b/src/status_im/mailserver/core.cljs @@ -4,6 +4,7 @@ [re-frame.core :as re-frame] [status-im.data-store.mailservers :as data-store.mailservers] [status-im.ethereum.json-rpc :as json-rpc] + [status-im.waku.core :as waku] [status-im.node.core :as node] [status-im.i18n :as i18n] [status-im.mailserver.constants :as constants] @@ -87,9 +88,9 @@ ;; We now wait for a confirmation from the mailserver before marking the message ;; as sent. -(defn update-mailservers! [enodes] +(defn update-mailservers! [waku-enabled? enodes] (json-rpc/call - {:method (json-rpc/call-ext-method "updateMailservers") + {:method (json-rpc/call-ext-method waku-enabled? "updateMailservers") :params [enodes] :on-success #(log/debug "mailserver: update-mailservers success" %) :on-error #(log/error "mailserver: update-mailservers error" %)})) @@ -117,8 +118,9 @@ (re-frame/reg-fx :mailserver/update-mailservers - (fn [enodes] - (update-mailservers! enodes))) + (fn [[waku-enabled? enodes]] + (println "HERE" waku-enabled? enodes) + (update-mailservers! waku-enabled? enodes))) (defn decrease-limit [] (max constants/min-limit (/ @limit 2))) @@ -144,9 +146,9 @@ (reset! limit (decrease-limit)) (reset! success-counter 0))) -(defn mark-trusted-peer! [enode] +(defn mark-trusted-peer! [waku-enabled? enode] (json-rpc/call - {:method (if config/waku-enabled? + {:method (if waku-enabled? "waku_markTrustedPeer" "shh_markTrustedPeer") :params [enode] @@ -157,7 +159,8 @@ (re-frame/reg-fx :mailserver/mark-trusted-peer - mark-trusted-peer!) + (fn [[waku-enabled? enode]] + (mark-trusted-peer! waku-enabled? enode))) (fx/defn generate-mailserver-symkey [{:keys [db] :as cofx} {:keys [password id] :as mailserver}] @@ -166,7 +169,8 @@ :generating-sym-key?] true) :shh/generate-sym-key-from-password - [{:password password + [(waku/enabled? cofx) + {:password password :on-success (fn [_ sym-key-id] (re-frame/dispatch @@ -189,7 +193,7 @@ (fetch-current db)] (fx/merge cofx {:db (update-mailserver-state db :added) - :mailserver/mark-trusted-peer address} + :mailserver/mark-trusted-peer [(waku/enabled? cofx) address]} (when-not (or sym-key-id generating-sym-key?) (generate-mailserver-symkey mailserver))))) @@ -206,7 +210,7 @@ ;; Any message sent before this takes effect will not be marked as sent ;; probably we should improve the UX so that is more transparent to the ;; user - :mailserver/update-mailservers [address]} + :mailserver/update-mailservers [(waku/enabled? cofx) [address]]} (when-not (or sym-key-id generating-sym-key?) (generate-mailserver-symkey mailserver))))) @@ -345,7 +349,8 @@ request-id)})))) (defn request-messages! - [{:keys [sym-key-id address]} + [waku-enabled? + {:keys [sym-key-id address]} {:keys [topics cursor to from force-to?] :as request}] ;; Add some room to from, unless we break day boundaries so that ;; messages that have been received after the last request are also fetched @@ -361,7 +366,7 @@ " cursor " cursor " limit " actual-limit) (json-rpc/call - {:method (json-rpc/call-ext-method "requestMessages") + {:method (json-rpc/call-ext-method waku-enabled? "requestMessages") :params [(cond-> {:topics topics :mailServerPeer address :symKeyID sym-key-id @@ -387,8 +392,8 @@ (re-frame/reg-fx :mailserver/request-messages - (fn [{:keys [mailserver request]}] - (request-messages! mailserver request))) + (fn [{:keys [mailserver request waku-enabled?]}] + (request-messages! waku-enabled? mailserver request))) (defn get-mailserver-when-ready "return the mailserver if the mailserver is ready" @@ -460,7 +465,8 @@ :mailserver/pending-requests (count requests) :mailserver/current-request request :mailserver/request-to request-to) - :mailserver/request-messages {:mailserver mailserver + :mailserver/request-messages {:waku-enabled? (waku/enabled? cofx) + :mailserver mailserver :request request}} {:db (dissoc db :mailserver/pending-requests @@ -783,7 +789,8 @@ (when-let [mailserver (get-mailserver-when-ready cofx)] (let [request-with-cursor (assoc request :cursor cursor)] {:db (assoc db :mailserver/current-request request-with-cursor) - :mailserver/request-messages {:mailserver mailserver + :mailserver/request-messages {:waku-enabled? (waku/enabled? cofx) + :mailserver mailserver :request request-with-cursor}})) (let [{:keys [gap chat-id]} request] (fx/merge @@ -927,8 +934,9 @@ (not current-request) (-> (assoc-in [:db :mailserver/current-request] first-request) (assoc :mailserver/request-messages - {:mailserver mailserver - :request first-request}))))) + {:waku-enabled? (waku/enabled? cofx) + :mailserver mailserver + :request first-request}))))) (fx/defn resend-request [{:keys [db] :as cofx} {:keys [request-id]}] @@ -969,8 +977,9 @@ {:db (update-in db [:mailserver/current-request :attempts] inc) :mailserver/decrease-limit [] :mailserver/request-messages - {:mailserver mailserver - :request (assoc request :limit (decrease-limit))}}) + {:waku-enabled? (waku/enabled? cofx) + :mailserver mailserver + :request (assoc request :limit (decrease-limit))}}) :else {:mailserver/decrease-limit []})))))) diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index e82917cb9b..8251441064 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -261,7 +261,7 @@ ;;so here we set it at 1 already so that it passes the check once it has ;;been initialized :filters/initialized 1) - :filters/load-filters []} + :filters/load-filters [[(:waku-enabled multiaccount) []]]} (finish-keycard-setup) (protocol/initialize-protocol {:mailservers [] :mailserver-ranges {} diff --git a/src/status_im/multiaccounts/update/core.cljs b/src/status_im/multiaccounts/update/core.cljs index 8e96b7dbef..d98c4eaf59 100644 --- a/src/status_im/multiaccounts/update/core.cljs +++ b/src/status_im/multiaccounts/update/core.cljs @@ -7,10 +7,10 @@ [status-im.utils.types :as types] [taoensso.timbre :as log])) -(fx/defn send-multiaccount-update [{:keys [db]}] +(fx/defn send-multiaccount-update [{:keys [db] :as cofx}] (let [multiaccount (:multiaccount db) {:keys [name preferred-name photo-path address]} multiaccount] - {::json-rpc/call [{:method (json-rpc/call-ext-method "sendContactUpdates") + {::json-rpc/call [{:method (json-rpc/call-ext-method (get-in db [:multiaccount :waku-enabled]) "sendContactUpdates") :params [(or preferred-name name) photo-path] :on-success #(log/debug "sent contact update")}]})) diff --git a/src/status_im/multiaccounts/update/publisher.cljs b/src/status_im/multiaccounts/update/publisher.cljs index 72e99a946d..e3f6a7a875 100644 --- a/src/status_im/multiaccounts/update/publisher.cljs +++ b/src/status_im/multiaccounts/update/publisher.cljs @@ -1,6 +1,7 @@ (ns status-im.multiaccounts.update.publisher (:require [taoensso.timbre :as log] [re-frame.core :as re-frame] + [status-im.waku.core :as waku] [status-im.utils.config :as config] [status-im.constants :as constants] [status-im.multiaccounts.update.core :as multiaccounts] @@ -11,7 +12,7 @@ ;; Publish updates every 48 hours (def publish-updates-interval (* 48 60 60 1000)) -(defn publish-update! [{:keys [db now]}] +(defn publish-update! [{:keys [db now] :as cofx}] (let [my-public-key (get-in db [:multiaccount :public-key]) peers-count (:peers-count db) last-updated (get-in @@ -25,7 +26,7 @@ {:keys [name preferred-name photo-path address]} multiaccount] (log/debug "sending contact updates") - (json-rpc/call {:method (json-rpc/call-ext-method "sendContactUpdates") + (json-rpc/call {:method (json-rpc/call-ext-method (waku/enabled? cofx) "sendContactUpdates") :params [(or preferred-name name) photo-path] :on-failure #(do (log/warn "failed to send contact updates") diff --git a/src/status_im/node/core.cljs b/src/status_im/node/core.cljs index cae49c0a0f..5660af07f2 100644 --- a/src/status_im/node/core.cljs +++ b/src/status_im/node/core.cljs @@ -95,6 +95,7 @@ current-fleet (get-current-fleet db) rendezvous-nodes (pick-nodes 3 (vals (:rendezvous current-fleet))) {:keys [installation-id log-level + waku-enabled waku-bloom-filter-mode custom-bootnodes custom-bootnodes-enabled?]} multiaccount use-custom-bootnodes (get custom-bootnodes-enabled? current-network)] (cond-> (get-in networks [current-network :config]) @@ -122,8 +123,9 @@ :PermissionsConfig {:Enabled true} :MailserversConfig {:Enabled true} :EnableNTPSync true - (if config/waku-enabled? :WakuConfig :WhisperConfig) + (if waku-enabled :WakuConfig :WhisperConfig) {:Enabled true + :BloomFilterMode waku-bloom-filter-mode :LightClient true :MinimumPoW 0.001} :ShhextConfig diff --git a/src/status_im/pairing/core.cljs b/src/status_im/pairing/core.cljs index 2bfb31a390..993b82ac85 100644 --- a/src/status_im/pairing/core.cljs +++ b/src/status_im/pairing/core.cljs @@ -1,43 +1,43 @@ -(ns status-im.pairing.core - (:require [clojure.string :as string] - [re-frame.core :as re-frame] - [status-im.chat.models :as models.chat] - [status-im.contact.core :as contact] - [status-im.contact.db :as contact.db] - [taoensso.timbre :as log] - [status-im.ethereum.json-rpc :as json-rpc] - [status-im.i18n :as i18n] - [status-im.multiaccounts.model :as multiaccounts.model] - [status-im.multiaccounts.update.core :as multiaccounts.update] - [status-im.transport.message.protocol :as protocol] - [status-im.ui.screens.navigation :as navigation] - [status-im.utils.config :as config] - [status-im.utils.fx :as fx] - [status-im.utils.identicon :as identicon] - [status-im.utils.pairing :as pairing.utils] - [status-im.utils.platform :as utils.platform] - [status-im.utils.types :as types])) +(ns status-im.pairing.core (:require [clojure.string :as string] + [re-frame.core :as re-frame] + [status-im.chat.models :as models.chat] + [status-im.waku.core :as waku] + [status-im.contact.core :as contact] + [status-im.contact.db :as contact.db] + [taoensso.timbre :as log] + [status-im.ethereum.json-rpc :as json-rpc] + [status-im.i18n :as i18n] + [status-im.multiaccounts.model :as multiaccounts.model] + [status-im.multiaccounts.update.core :as multiaccounts.update] + [status-im.transport.message.protocol :as protocol] + [status-im.ui.screens.navigation :as navigation] + [status-im.utils.config :as config] + [status-im.utils.fx :as fx] + [status-im.utils.identicon :as identicon] + [status-im.utils.pairing :as pairing.utils] + [status-im.utils.platform :as utils.platform] + [status-im.utils.types :as types])) -(defn enable-installation-rpc [installation-id on-success on-failure] - (json-rpc/call {:method (json-rpc/call-ext-method "enableInstallation") +(defn enable-installation-rpc [waku-enabled? installation-id on-success on-failure] + (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "enableInstallation") :params [installation-id] :on-success on-success :on-failure on-failure})) -(defn disable-installation-rpc [installation-id on-success on-failure] - (json-rpc/call {:method (json-rpc/call-ext-method "disableInstallation") +(defn disable-installation-rpc [waku-enabled? installation-id on-success on-failure] + (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "disableInstallation") :params [installation-id] :on-success on-success :on-failure on-failure})) -(defn set-installation-metadata-rpc [installation-id metadata on-success on-failure] - (json-rpc/call {:method (json-rpc/call-ext-method "setInstallationMetadata") +(defn set-installation-metadata-rpc [waku-enabled? installation-id metadata on-success on-failure] + (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "setInstallationMetadata") :params [installation-id metadata] :on-success on-success :on-failure on-failure})) -(defn get-our-installations-rpc [on-success on-failure] - (json-rpc/call {:method (json-rpc/call-ext-method "getOurInstallations") +(defn get-our-installations-rpc [waku-enabled? on-success on-failure] + (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "getOurInstallations") :params [] :on-success on-success :on-failure on-failure})) @@ -65,7 +65,7 @@ (defn send-pair-installation [cofx] - {::json-rpc/call [{:method (json-rpc/call-ext-method "sendPairInstallation") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "sendPairInstallation") :params [] :on-success #(log/info "sent pair installation message")}]}) @@ -91,11 +91,13 @@ "Set the name of the device" [{:keys [db] :as cofx} installation-name] (let [our-installation-id (get-in db [:multiaccount :installation-id])] - {:pairing/set-installation-metadata [[our-installation-id {:name installation-name - :deviceType utils.platform/os}]]})) + {:pairing/set-installation-metadata [(waku/enabled? cofx) + our-installation-id + {:name installation-name + :deviceType utils.platform/os}]})) (fx/defn init [cofx] - {:pairing/get-our-installations nil}) + {:pairing/get-our-installations (waku/enabled? cofx)}) (defn handle-bundles-added [{:keys [db] :as cofx} bundle] (let [installation-id (:installationID bundle)] @@ -139,57 +141,64 @@ [result] (re-frame/dispatch [:pairing.callback/get-our-installations-success result])) -(defn enable-installation! [installation-id] - (enable-installation-rpc installation-id - (partial handle-enable-installation-response-success installation-id) - nil)) +(defn enable-installation! [waku-enabled? installation-id] + (enable-installation-rpc + waku-enabled? + installation-id + (partial handle-enable-installation-response-success installation-id) + nil)) -(defn disable-installation! [installation-id] - (disable-installation-rpc installation-id - (partial handle-disable-installation-response-success installation-id) - nil)) +(defn disable-installation! [waku-enabled? installation-id] + (disable-installation-rpc + waku-enabled? + installation-id + (partial handle-disable-installation-response-success installation-id) + nil)) -(defn set-installation-metadata! [installation-id metadata] - (set-installation-metadata-rpc installation-id - metadata - (partial handle-set-installation-metadata-response-success installation-id metadata) - nil)) +(defn set-installation-metadata! [waku-enabled? installation-id metadata] + (set-installation-metadata-rpc + waku-enabled? + installation-id + metadata + (partial handle-set-installation-metadata-response-success installation-id metadata) + nil)) -(defn get-our-installations [] - (get-our-installations-rpc handle-get-our-installations-response-success nil)) +(defn get-our-installations [waku-enabled?] + (get-our-installations-rpc waku-enabled? handle-get-our-installations-response-success nil)) (defn enable-fx [cofx installation-id] (if (< (count (filter :enabled? (vals (get-in cofx [:db :pairing/installations])))) (inc config/max-installations)) - {:pairing/enable-installation installation-id} + {:pairing/enable-installation [(waku/enabled? cofx) installation-id]} {:utils/show-popup {:title (i18n/label :t/pairing-maximum-number-reached-title) :content (i18n/label :t/pairing-maximum-number-reached-content)}})) -(defn disable-fx [_ installation-id] - {:pairing/disable-installation installation-id}) +(defn disable-fx [cofx installation-id] + {:pairing/disable-installation [(waku/enabled? cofx) installation-id]}) (re-frame/reg-fx :pairing/enable-installation - enable-installation!) + (fn [[waku-enabled? installation-id]] + (enable-installation! waku-enabled? installation-id))) (re-frame/reg-fx :pairing/disable-installation - disable-installation!) + (fn [[waku-enabled? installation-id]] + (disable-installation! waku-enabled? installation-id))) (re-frame/reg-fx :pairing/set-installation-metadata - (fn [pairs] - (doseq [[installation-id metadata] pairs] - (set-installation-metadata! installation-id metadata)))) + (fn [[waku-enabled? installation-id metadata]] + (set-installation-metadata! waku-enabled? installation-id metadata))) (re-frame/reg-fx :pairing/get-our-installations get-our-installations) -(defn send-installation-messages [{:keys [db]}] +(defn send-installation-messages [{:keys [db] :as cofx}] (let [multiaccount (:multiaccount db) {:keys [name preferred-name photo-path]} multiaccount] - {::json-rpc/call [{:method (json-rpc/call-ext-method "syncDevices") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "syncDevices") :params [(or preferred-name name) photo-path] :on-success #(log/debug "successfully synced devices")}]})) diff --git a/src/status_im/signing/core.cljs b/src/status_im/signing/core.cljs index aab1226323..b3cdc21847 100644 --- a/src/status_im/signing/core.cljs +++ b/src/status_im/signing/core.cljs @@ -3,6 +3,7 @@ [re-frame.core :as re-frame] [status-im.constants :as constants] [status-im.utils.config :as config] + [status-im.waku.core :as waku] [status-im.ethereum.abi-spec :as abi-spec] [status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.core :as ethereum] @@ -213,7 +214,7 @@ (fx/defn send-transaction-message {:events [::send-transaction-message]} [cofx chat-id value contract transaction-hash signature] - {::json-rpc/call [{:method (json-rpc/call-ext-method "sendTransaction") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "sendTransaction") :params [chat-id value contract transaction-hash (:result (types/json->clj signature))] :on-success @@ -222,7 +223,7 @@ (fx/defn send-accept-request-transaction-message {:events [::send-accept-transaction-message]} [cofx message-id transaction-hash signature] - {::json-rpc/call [{:method (json-rpc/call-ext-method "acceptRequestTransaction") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "acceptRequestTransaction") :params [transaction-hash message-id (:result (types/json->clj signature))] :on-success diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index bd5a983d36..bf79a38e15 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -487,6 +487,18 @@ (or (get multiaccount :log-level) config/log-level-status-go))) +(re-frame/reg-sub + :waku/enabled + :<- [:multiaccount] + (fn [multiaccount] + (boolean (get multiaccount :waku-enabled)))) + +(re-frame/reg-sub + :waku/bloom-filter-mode + :<- [:multiaccount] + (fn [multiaccount] + (boolean (get multiaccount :waku-bloom-filter-mode)))) + (re-frame/reg-sub :dapps-address :<- [:multiaccount] diff --git a/src/status_im/transport/core.cljs b/src/status_im/transport/core.cljs index bb9317ef79..317e4c29db 100644 --- a/src/status_im/transport/core.cljs +++ b/src/status_im/transport/core.cljs @@ -3,6 +3,7 @@ (:require [re-frame.core :as re-frame] [status-im.ethereum.json-rpc :as json-rpc] + [status-im.waku.core :as waku] [status-im.native-module.core :as status] [status-im.mailserver.core :as mailserver] [status-im.transport.message.core :as message] @@ -40,7 +41,7 @@ initializiation is completed, otherwise we might receive messages/topics when the state has not been properly initialized." [cofx] - {::json-rpc/call [{:method (json-rpc/call-ext-method "startMessenger") + {::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "startMessenger") :on-success #(do (log/debug "messenger initialized") (re-frame/dispatch [::init-whisper])) diff --git a/src/status_im/transport/filters/core.cljs b/src/status_im/transport/filters/core.cljs index 4c9dbccf68..86e0fcd8dc 100644 --- a/src/status_im/transport/filters/core.cljs +++ b/src/status_im/transport/filters/core.cljs @@ -5,6 +5,7 @@ [re-frame.core :as re-frame] [clojure.string :as string] [status-im.contact.db :as contact.db] + [status-im.waku.core :as waku] [status-im.ethereum.json-rpc :as json-rpc] [status-im.utils.fx :as fx] [status-im.utils.config :as config] @@ -17,26 +18,26 @@ (defn is-public-key? [k] (string/starts-with? k "0x")) -(defn load-filters-rpc [chats on-success on-failure] - (json-rpc/call {:method (json-rpc/call-ext-method "loadFilters") +(defn load-filters-rpc [waku-enabled? chats on-success on-failure] + (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "loadFilters") :params [chats] :on-success on-success :on-failure on-failure})) -(defn remove-filters-rpc [chats on-success on-failure] - (json-rpc/call {:method (json-rpc/call-ext-method "removeFilters") +(defn remove-filters-rpc [waku-enabled? chats on-success on-failure] + (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "removeFilters") :params [chats] :on-success on-success :on-failure on-failure})) ;; fx functions -(defn load-filter-fx [filters] - {:filters/load-filters filters}) +(defn load-filter-fx [waku-enabled? filters] + {:filters/load-filters [[waku-enabled? filters]]}) -(defn remove-filter-fx [filters] +(defn remove-filter-fx [waku-enabled? filters] (when (seq filters) - {:filters/remove-filters filters})) + {:filters/remove-filters [waku-enabled? filters]})) ;; dispatches @@ -249,37 +250,37 @@ (fx/defn load-filters "Load all contacts and chats as filters" - [{:keys [db]}] + [{:keys [db] :as cofx}] (log/debug "loading filters") (let [chats (vals (:chats db)) contacts (vals (:contacts/contacts db)) filters (concat (chats->filter-requests chats) (contacts->filter-requests contacts))] - (load-filter-fx filters))) + (load-filter-fx (waku/enabled? cofx) filters))) ;; Load functions: utility function to load filters (fx/defn load-chat "Check if a filter already exists for that chat, otherw load the filter" - [{:keys [db]} chat-id] + [{:keys [db] :as cofx} chat-id] (when (and (filters-initialized? db) (not (chat-loaded? db chat-id))) (let [chat (get-in db [:chats chat-id])] - (load-filter-fx (->filter-request chat))))) + (load-filter-fx (waku/enabled? cofx) (->filter-request chat))))) (fx/defn load-contact "Check if we already have a filter for that contact, otherwise load the filter if the contact has been added" - [{:keys [db]} contact] + [{:keys [db] :as cofx} contact] (when-not (chat-loaded? db (:public-key contact)) - (load-filter-fx (contacts->filter-requests [contact])))) + (load-filter-fx (waku/enabled? cofx) (contacts->filter-requests [contact])))) (fx/defn load-member "Check if we already have a filter for that member, otherwise load the filter, regardless of whether is in our contacts" - [{:keys [db]} public-key] + [{:keys [db] :as cofx} public-key] (when-not (chat-loaded? db public-key) - (load-filter-fx (->filter-request {:chat-id public-key})))) + (load-filter-fx (waku/enabled? cofx) (->filter-request {:chat-id public-key})))) (fx/defn load-members "Load multiple members" @@ -310,6 +311,7 @@ ;; we exclude the negotiated filters as those are not to be removed ;; otherwise we might miss messages (remove-filter-fx + (waku/enabled? cofx) (non-negotiated-filters-for-chat-id db chat-id)))))) ;; reg-fx @@ -336,17 +338,21 @@ ;; we should recreate it. (re-frame/reg-fx :filters/remove-filters - (fn [filters] + (fn [[waku-enabled? filters]] (log/debug "removing filters" filters) (remove-filters-rpc + waku-enabled? (map ->remove-filter-request filters) #(filters-removed! filters) #(log/error "remove-filters: failed error" %)))) (re-frame/reg-fx :filters/load-filters - (fn [filters] - (load-filters-rpc - filters - #(filters-added! (map responses->filters %)) - #(log/error "load-filters: failed error" %)))) + (fn [raw-filters] + (let [waku-enabled? (first (first raw-filters)) + all-filters (mapcat second raw-filters)] + (load-filters-rpc + waku-enabled? + all-filters + #(filters-added! (map responses->filters %)) + #(log/error "load-filters: failed error" %))))) diff --git a/src/status_im/transport/message/protocol.cljs b/src/status_im/transport/message/protocol.cljs index 81d58380ba..652b29b98b 100644 --- a/src/status_im/transport/message/protocol.cljs +++ b/src/status_im/transport/message/protocol.cljs @@ -6,15 +6,17 @@ [status-im.utils.fx :as fx] [taoensso.timbre :as log])) -(fx/defn send-chat-message [_ {:keys [chat-id - text - response-to - ens-name - message-type - sticker - content-type] - :as message}] - {::json-rpc/call [{:method (json-rpc/call-ext-method "sendChatMessage") +(fx/defn send-chat-message [cofx {:keys [chat-id + text + response-to + ens-name + message-type + sticker + content-type] + :as message}] + {::json-rpc/call [{:method (json-rpc/call-ext-method + (get-in cofx [:db :multiaccount :waku-enabled]) + "sendChatMessage") :params [{:chatId chat-id :text text :responseTo response-to diff --git a/src/status_im/transport/shh.cljs b/src/status_im/transport/shh.cljs index c6374ffafc..630bde6810 100644 --- a/src/status_im/transport/shh.cljs +++ b/src/status_im/transport/shh.cljs @@ -8,8 +8,8 @@ [status-im.ethereum.json-rpc :as json-rpc])) (defn generate-sym-key-from-password - [{:keys [password on-success on-error]}] - (json-rpc/call {:method (if config/waku-enabled? + [waku-enabled? {:keys [password on-success on-error]}] + (json-rpc/call {:method (if waku-enabled? "waku_generateSymKeyFromPassword" "shh_generateSymKeyFromPassword") :params [password] @@ -17,8 +17,8 @@ :on-error on-error})) (defn get-sym-key - [{:keys [sym-key-id on-success on-error]}] - (json-rpc/call {:method (if config/waku-enabled? + [waku-enabled? {:keys [sym-key-id on-success on-error]}] + (json-rpc/call {:method (if waku-enabled? "waku_getSymKey" "shh_getSymKey") :params [sym-key-id] @@ -30,12 +30,14 @@ (re-frame/reg-fx :shh/generate-sym-key-from-password - (fn [args] - (doseq [{:keys [password on-success]} args] - (generate-sym-key-from-password {:password password - :on-success (fn [sym-key-id] - (get-sym-key {:sym-key-id sym-key-id - :on-success (fn [sym-key] - (on-success sym-key sym-key-id)) - :on-error log-error})) - :on-error log-error})))) + (fn [[waku-enabled? {:keys [password on-success]}]] + (generate-sym-key-from-password + waku-enabled? + {:password password + :on-success (fn [sym-key-id] + (get-sym-key waku-enabled? + {:sym-key-id sym-key-id + :on-success (fn [sym-key] + (on-success sym-key sym-key-id)) + :on-error log-error})) + :on-error log-error}))) diff --git a/src/status_im/ui/screens/advanced_settings/views.cljs b/src/status_im/ui/screens/advanced_settings/views.cljs index ec8f9f353c..fb3399a89f 100644 --- a/src/status_im/ui/screens/advanced_settings/views.cljs +++ b/src/status_im/ui/screens/advanced_settings/views.cljs @@ -6,8 +6,12 @@ [status-im.ui.components.react :as react] [status-im.ui.components.topbar :as topbar])) -(defn- normal-mode-settings-data [network-name current-log-level - current-fleet dev-mode?] +(defn- normal-mode-settings-data [{:keys [network-name + current-log-level + waku-enabled + waku-bloom-filter-mode + current-fleet + dev-mode?]}] [{:type :small :title :t/network :accessibility-label :network-button @@ -45,6 +49,36 @@ :on-press #(re-frame/dispatch [:navigate-to :bootnodes-settings]) :accessories [:chevron]} + {:type :small + :title :t/waku-enabled + :accessibility-label :waku-enabled-settings-switch + :container-margin-bottom 8 + :on-press + #(re-frame/dispatch + [:multiaccounts.ui/waku-enabled-switched (not waku-enabled)]) + :accessories + [[react/switch + {:track-color #js {:true colors/blue :false nil} + :value waku-enabled + :on-value-change + #(re-frame/dispatch + [:multiaccounts.ui/waku-enabled-switched (not waku-enabled)]) + :disabled false}]]} + {:type :small + :title :t/waku-bloom-filter-mode + :accessibility-label :waku-bloom-filter-mode-settings-switch + :container-margin-bottom 8 + :on-press + #(re-frame/dispatch + [:multiaccounts.ui/waku-bloom-filter-mode-switched (not waku-bloom-filter-mode)]) + :accessories + [[react/switch + {:track-color #js {:true colors/blue :false nil} + :value waku-bloom-filter-mode + :on-value-change + #(re-frame/dispatch + [:multiaccounts.ui/waku-bloom-filter-mode-switched (not waku-bloom-filter-mode)]) + :disabled false}]]} #_{:type :small :title :t/dev-mode :accessibility-label :dev-mode-settings-switch @@ -82,28 +116,34 @@ :disabled false}]]} [react/view {:height 24}]]) -(defn- flat-list-data [network-name current-log-level current-fleet - dev-mode? chaos-mode?] +(defn- flat-list-data [{:keys [dev-mode? + chaos-mode?] + :as options}] (if dev-mode? (into - (normal-mode-settings-data - network-name current-log-level current-fleet dev-mode?) + (normal-mode-settings-data options) (dev-mode-settings-data chaos-mode?)) ;; else - (normal-mode-settings-data - network-name current-log-level current-fleet dev-mode?))) + (normal-mode-settings-data options))) (views/defview advanced-settings [] (views/letsubs [{:keys [chaos-mode?]} [:multiaccount] network-name [:network-name] + waku-enabled [:waku/enabled] + waku-bloom-filter-mode [:waku/bloom-filter-mode] current-log-level [:log-level/current-log-level] current-fleet [:fleets/current-fleet]] [react/view {:flex 1 :background-color colors/white} [topbar/topbar {:title :t/advanced}] [list/flat-list {:data (flat-list-data - network-name current-log-level - current-fleet false chaos-mode?) + {:network-name network-name + :current-log-level current-log-level + :current-fleet current-fleet + :dev-mode? false + :waku-enabled waku-enabled + :waku-bloom-filter-mode waku-bloom-filter-mode + :chaos-mode? chaos-mode?}) :key-fn (fn [_ i] (str i)) :render-fn list/flat-list-generic-render-fn}]])) diff --git a/src/status_im/utils/fx.cljs b/src/status_im/utils/fx.cljs index d551acbcf2..e4b42cf442 100644 --- a/src/status_im/utils/fx.cljs +++ b/src/status_im/utils/fx.cljs @@ -17,7 +17,6 @@ :status-im.ens.core/verify-names :shh/send-direct-message :shh/remove-filter - :shh/generate-sym-key-from-password :transport/confirm-messages-processed :group-chats/extract-membership-signature :utils/dispatch-later diff --git a/src/status_im/waku/core.cljs b/src/status_im/waku/core.cljs new file mode 100644 index 0000000000..b6d9c62106 --- /dev/null +++ b/src/status_im/waku/core.cljs @@ -0,0 +1,28 @@ +(ns status-im.waku.core + (:require [re-frame.core :as re-frame] + [status-im.multiaccounts.update.core :as multiaccounts.update] + [status-im.node.core :as node] + [status-im.utils.fx :as fx])) + +(defn enabled? [cofx] + (get-in cofx [:db :multiaccount :waku-enabled])) + +(fx/defn switch-waku-enabled + {:events [:multiaccounts.ui/waku-enabled-switched]} + [cofx enabled?] + (fx/merge cofx + (multiaccounts.update/multiaccount-update :waku-enabled enabled? + {}) + (node/prepare-new-config + {:on-success #(re-frame/dispatch [:logout])}))) + +(fx/defn switch-waku-bloom-filter-mode + {:events [:multiaccounts.ui/waku-bloom-filter-mode-switched]} + [cofx enabled?] + (fx/merge cofx + (multiaccounts.update/multiaccount-update + :waku-bloom-filter-mode enabled? + {}) + (node/prepare-new-config + {:on-success #(re-frame/dispatch [:logout])}))) + diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index ce42be8ff1..fe5b222bf6 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -3,6 +3,7 @@ [re-frame.core :as re-frame] [status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.constants :as constants] + [status-im.waku.core :as waku] [status-im.chat.models.message :as chat.message] [status-im.ethereum.core :as ethereum] [status-im.ethereum.eip55 :as eip55] @@ -407,7 +408,7 @@ [to-norm amount-hex])})})) {:db db ::json-rpc/call - [{:method (json-rpc/call-ext-method "requestAddressForTransaction") + [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "requestAddressForTransaction") :params [(:current-chat-id db) from-address amount @@ -426,7 +427,7 @@ {:db (-> db (update-in [:chat-ui-props identity] dissoc :input-bottom-sheet) (dissoc db :wallet/prepare-transaction)) - ::json-rpc/call [{:method (json-rpc/call-ext-method "requestTransaction") + ::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "requestTransaction") :params [(:public-key to) amount (when-not (= symbol :ETH) diff --git a/test/cljs/status_im/test/mailserver/core.cljs b/test/cljs/status_im/test/mailserver/core.cljs index 7d0efeff86..0ba5551680 100644 --- a/test/cljs/status_im/test/mailserver/core.cljs +++ b/test/cljs/status_im/test/mailserver/core.cljs @@ -625,7 +625,7 @@ (is (= "mailserver-password" (-> (mailserver/connect-to-mailserver {:db db}) :shh/generate-sym-key-from-password - first + second :password)))) (let [mailserver-with-sym-key-db (assoc-in db [:mailserver/mailservers :eth.staging "mailserverid" :sym-key-id] diff --git a/test/cljs/status_im/test/transport/filters/core.cljs b/test/cljs/status_im/test/transport/filters/core.cljs index e7e6d2d5f1..e8f7be8f2e 100644 --- a/test/cljs/status_im/test/transport/filters/core.cljs +++ b/test/cljs/status_im/test/transport/filters/core.cljs @@ -24,7 +24,7 @@ "b" {:chat-id chat-id :negotiated? true}}}} chat-id)] (is fx) - (is (= fx {:filters/remove-filters [{:chat-id chat-id :filter-id "a"}]}))))) + (is (= fx {:filters/remove-filters [nil [{:chat-id chat-id :filter-id "a"}]]}))))) (testing "the user is still in some group chats" (testing "we joined, and group chat is active it does not remove filters" (let [fx (transport.filters/stop-listening {:db {:multiaccount {:public-key me} @@ -46,7 +46,7 @@ {member-1 {:chat-id member-1 :filter-id "a"}}}} member-1)] (is fx) - (is (= fx {:filters/remove-filters [{:chat-id member-1 :filter-id "a"}]}))))) + (is (= fx {:filters/remove-filters [nil [{:chat-id member-1 :filter-id "a"}]]}))))) (testing "we have a 1-to-1 chat with the user" (testing "it does not remove filter" (let [fx (transport.filters/stop-listening {:db {:chats @@ -98,19 +98,19 @@ (deftest load-member (testing "it returns fx for a member" - (is (= {:filters/load-filters [{:ChatID "0xchat-id-2" - :OneToOne true - :Identity "chat-id-2"}]} + (is (= {:filters/load-filters [[nil [{:ChatID "0xchat-id-2" + :OneToOne true + :Identity "chat-id-2"}]]]} (transport.filters/load-member {:db {}} "0xchat-id-2")))) (testing "merging fx" (is (= {:db {} - :filters/load-filters [{:ChatID "0xchat-id-1" - :OneToOne true - :Identity "chat-id-1"} - {:ChatID "0xchat-id-2" - :OneToOne true - :Identity "chat-id-2"}]} + :filters/load-filters [[nil [{:ChatID "0xchat-id-1" + :OneToOne true + :Identity "chat-id-1"}]] + [nil [{:ChatID "0xchat-id-2" + :OneToOne true + :Identity "chat-id-2"}]]]} (apply fx/merge {:db {}} (map transport.filters/load-member ["0xchat-id-1" "0xchat-id-2"])))))) diff --git a/translations/en.json b/translations/en.json index a225efe084..2a59c401e9 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1096,5 +1096,7 @@ "add-seed-account": "Add account with a seed phrase", "account-exists-title": "Account already exists", "add-private-key-account": "Add account from private key", - "user-not-found": "User not found" + "user-not-found": "User not found", + "waku-enabled": "Waku enabled", + "waku-bloom-filter-mode": "Waku bloom filter mode" }