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 <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2020-02-27 13:24:45 +01:00
parent b8861c6c14
commit 619e176087
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
31 changed files with 327 additions and 244 deletions

View File

@ -3,6 +3,7 @@
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
[status-im.transport.filters.core :as transport.filters] [status-im.transport.filters.core :as transport.filters]
[status-im.contact.core :as contact.core] [status-im.contact.core :as contact.core]
[status-im.waku.core :as waku]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[status-im.data-store.chats :as chats-store] [status-im.data-store.chats :as chats-store]
[status-im.data-store.messages :as messages-store] [status-im.data-store.messages :as messages-store]
@ -127,7 +128,7 @@
{:events [:chat.ui/mark-all-read-pressed {:events [:chat.ui/mark-all-read-pressed
:chat.ui/mark-public-all-read]} :chat.ui/mark-public-all-read]}
[{:keys [db] :as cofx} chat-id] [{: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] :params [chat-id]
:on-success #(re-frame/dispatch [::mark-all-read-successful chat-id])}]}) :on-success #(re-frame/dispatch [::mark-all-read-successful chat-id])}]})

View File

@ -2,6 +2,7 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.ui.screens.chat.state :as chat.state] [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.chats :as data-store.chats]
[status-im.data-store.messages :as data-store.messages] [status-im.data-store.messages :as data-store.messages]
[status-im.transport.filters.core :as filters] [status-im.transport.filters.core :as filters]
@ -140,7 +141,9 @@
(when-not (or (get-in db [:chats current-chat-id :all-loaded?]) (when-not (or (get-in db [:chats current-chat-id :all-loaded?])
(get-in db [:chats current-chat-id :loading-messages?])) (get-in db [:chats current-chat-id :loading-messages?]))
(let [cursor (get-in db [:chats current-chat-id :cursor]) (let [cursor (get-in db [:chats current-chat-id :cursor])
load-messages-fx (data-store.messages/messages-by-chat-id-rpc current-chat-id load-messages-fx (data-store.messages/messages-by-chat-id-rpc
(waku/enabled? cofx)
current-chat-id
cursor cursor
constants/default-number-of-messages constants/default-number-of-messages
#(re-frame/dispatch [::messages-loaded current-chat-id session-id %]) #(re-frame/dispatch [::messages-loaded current-chat-id session-id %])

View File

@ -4,6 +4,7 @@
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.chat.db :as chat.db] [status-im.chat.db :as chat.db]
[status-im.waku.core :as waku]
[status-im.chat.models :as chat-model] [status-im.chat.models :as chat-model]
[status-im.chat.models.loading :as chat-loading] [status-im.chat.models.loading :as chat-loading]
[status-im.chat.models.message-list :as message-list] [status-im.chat.models.message-list :as message-list]
@ -207,7 +208,7 @@
(fx/defn resend-message (fx/defn resend-message
[{:keys [db] :as cofx} chat-id message-id] [{:keys [db] :as cofx} chat-id message-id]
(fx/merge cofx (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] :params [message-id]
:on-success #(log/debug "re-sent message successfully") :on-success #(log/debug "re-sent message successfully")
:on-error #(log/error "failed to re-send message" %)}]} :on-error #(log/error "failed to re-send message" %)}]}
@ -228,9 +229,6 @@
:current-chat? true}) :current-chat? true})
messages))) messages)))
(fx/defn add-system-messages [cofx messages]
(data-store.messages/save-system-messages cofx messages))
(fx/defn send-message (fx/defn send-message
[{:keys [db now] :as cofx} {:keys [chat-id] :as message}] [{:keys [db now] :as cofx} {:keys [chat-id] :as message}]
(protocol/send-chat-message cofx message)) (protocol/send-chat-message cofx message))

View File

@ -2,6 +2,7 @@
(:require (:require
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.waku.core :as waku]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx])) [status-im.utils.fx :as fx]))
@ -22,22 +23,22 @@
(fx/defn handle-accept-request-address-for-transaction (fx/defn handle-accept-request-address-for-transaction
{:events [::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) {: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] :params [message-id address]
:on-success #(re-frame/dispatch [:transport/message-sent % 1])}]}) :on-success #(re-frame/dispatch [:transport/message-sent % 1])}]})
(fx/defn handle-decline-request-address-for-transaction (fx/defn handle-decline-request-address-for-transaction
{:events [::decline-request-address-for-transaction]} {:events [::decline-request-address-for-transaction]}
[cofx message-id] [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] :params [message-id]
:on-success #(re-frame/dispatch [:transport/message-sent % 1])}]}) :on-success #(re-frame/dispatch [:transport/message-sent % 1])}]})
(fx/defn handle-decline-request-transaction (fx/defn handle-decline-request-transaction
{:events [::decline-request-transaction]} {:events [::decline-request-transaction]}
[cofx message-id] [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] :params [message-id]
:on-success #(re-frame/dispatch [:transport/message-sent % 1])}]}) :on-success #(re-frame/dispatch [:transport/message-sent % 1])}]})

View File

@ -3,6 +3,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.waku.core :as waku]
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
[status-im.transport.filters.core :as transport.filters] [status-im.transport.filters.core :as transport.filters]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
@ -76,7 +77,7 @@
(fx/defn send-contact-request (fx/defn send-contact-request
[{:keys [db] :as cofx} {:keys [public-key] :as contact}] [{:keys [db] :as cofx} {:keys [public-key] :as contact}]
(let [{:keys [name profile-image]} (own-info db)] (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] :params [public-key name profile-image]
:on-success #(log/debug "contact request sent" public-key)}]})) :on-success #(log/debug "contact request sent" public-key)}]}))

View File

@ -2,6 +2,7 @@
(:require [goog.object :as object] (:require [goog.object :as object]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.data-store.messages :as messages] [status-im.data-store.messages :as messages]
[status-im.waku.core :as waku]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
@ -114,13 +115,13 @@
(dissoc :chatType :members))) (dissoc :chatType :members)))
(fx/defn save-chat [cofx {:keys [chat-id] :as chat}] (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)] :params [(->rpc chat)]
:on-success #(log/debug "saved chat" chat-id "successfuly") :on-success #(log/debug "saved chat" chat-id "successfuly")
:on-failure #(log/error "failed to save chat" chat-id %)}]}) :on-failure #(log/error "failed to save chat" chat-id %)}]})
(fx/defn fetch-chats-rpc [cofx {:keys [on-success]}] (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 [] :params []
:on-success #(on-success (map <-rpc %)) :on-success #(on-success (map <-rpc %))
:on-failure #(log/error "failed to fetch chats" 0 -1 %)}]}) :on-failure #(log/error "failed to fetch chats" 0 -1 %)}]})

View File

@ -2,6 +2,7 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.waku.core :as waku]
[status-im.data-store.chats :as data-store.chats] [status-im.data-store.chats :as data-store.chats]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@ -46,20 +47,20 @@
(fx/defn fetch-contacts-rpc (fx/defn fetch-contacts-rpc
[cofx on-success] [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 [] :params []
:on-success #(on-success (map <-rpc %)) :on-success #(on-success (map <-rpc %))
:on-failure #(log/error "failed to fetch contacts" %)}]}) :on-failure #(log/error "failed to fetch contacts" %)}]})
(fx/defn save-contact (fx/defn save-contact
[cofx {:keys [public-key] :as 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)] :params [(->rpc contact)]
:on-success #(log/debug "saved contact" public-key "successfuly") :on-success #(log/debug "saved contact" public-key "successfuly")
:on-failure #(log/error "failed to save contact" public-key %)}]}) :on-failure #(log/error "failed to save contact" public-key %)}]})
(fx/defn block [cofx contact on-success] (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)] :params [(->rpc contact)]
:on-success on-success :on-success on-success
:on-failure #(log/error "failed to block contact" % contact)}]}) :on-failure #(log/error "failed to block contact" % contact)}]})

View File

@ -5,6 +5,7 @@
[clojure.string :as string] [clojure.string :as string]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.waku.core :as waku]
[status-im.utils.types :as utils.types] [status-im.utils.types :as utils.types]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
@ -46,72 +47,59 @@
:outgoing (boolean (:outgoingStatus message))) :outgoing (boolean (:outgoingStatus message)))
(dissoc :ensName :chatId :text :rtl :responseTo :sticker :lineCount :parsedText))) (dissoc :ensName :chatId :text :rtl :responseTo :sticker :lineCount :parsedText)))
(defn update-outgoing-status-rpc [message-id status] (defn update-outgoing-status-rpc [waku-enabled? message-id status]
{::json-rpc/call [{:method (json-rpc/call-ext-method "updateMessageOutgoingStatus") {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "updateMessageOutgoingStatus")
:params [message-id status] :params [message-id status]
:on-success #(log/debug "updated message outgoing stauts" 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 %)}]}) :on-failure #(log/error "failed to update message outgoing status" message-id status %)}]})
(defn save-system-messages-rpc [messages] (defn messages-by-chat-id-rpc [waku-enabled?
(json-rpc/call {:method (json-rpc/call-ext-method "addSystemMessages") chat-id
: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
cursor cursor
limit limit
on-success on-success
on-failure] 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] :params [chat-id cursor limit]
:on-success (fn [result] :on-success (fn [result]
(on-success (update result :messages #(map <-rpc %)))) (on-success (update result :messages #(map <-rpc %))))
:on-failure on-failure}]}) :on-failure on-failure}]})
(defn mark-seen-rpc [chat-id ids] (defn mark-seen-rpc [waku-enabled? chat-id ids]
{::json-rpc/call [{:method (json-rpc/call-ext-method "markMessagesSeen") {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "markMessagesSeen")
:params [chat-id ids] :params [chat-id ids]
:on-success #(log/debug "successfully marked as seen") :on-success #(log/debug "successfully marked as seen")
:on-failure #(log/error "failed to get messages" %)}]}) :on-failure #(log/error "failed to get messages" %)}]})
(defn delete-message-rpc [id] (defn delete-message-rpc [waku-enabled? id]
{::json-rpc/call [{:method (json-rpc/call-ext-method "deleteMessage") {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "deleteMessage")
:params [id] :params [id]
:on-success #(log/debug "successfully deleted message" id) :on-success #(log/debug "successfully deleted message" id)
:on-failure #(log/error "failed to delete message" % id)}]}) :on-failure #(log/error "failed to delete message" % id)}]})
(defn delete-messages-from-rpc [author] (defn delete-messages-from-rpc [waku-enabled? author]
{::json-rpc/call [{:method (json-rpc/call-ext-method "deleteMessagesFrom") {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "deleteMessagesFrom")
:params [author] :params [author]
:on-success #(log/debug "successfully deleted messages from" author) :on-success #(log/debug "successfully deleted messages from" author)
:on-failure #(log/error "failed to delete messages from" % author)}]}) :on-failure #(log/error "failed to delete messages from" % author)}]})
(defn delete-messages-by-chat-id-rpc [chat-id] (defn delete-messages-by-chat-id-rpc [waku-enabled? chat-id]
{::json-rpc/call [{:method (json-rpc/call-ext-method "deleteMessagesByChatID") {::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "deleteMessagesByChatID")
:params [chat-id] :params [chat-id]
:on-success #(log/debug "successfully deleted messages by chat-id" 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)}]}) :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] (fx/defn delete-message [cofx id]
(delete-message-rpc id)) (delete-message-rpc (waku/enabled? cofx) id))
(fx/defn delete-messages-from [cofx author] (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] (fx/defn mark-messages-seen [cofx chat-id ids]
(mark-seen-rpc chat-id ids)) (mark-seen-rpc (waku/enabled? cofx) chat-id ids))
(fx/defn update-outgoing-status [cofx message-id status] (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] (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))

View File

@ -291,31 +291,3 @@
(fx/merge cofx (fx/merge cofx
(set-username-candidate (get-in db [:ens/registration :username] "")) (set-username-candidate (get-in db [:ens/registration :username] ""))
(navigation/navigate-to-cofx :ens-search {}))) (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)}]}))

View File

@ -178,8 +178,8 @@
(call-method (update arg :number-of-retries dec))) (call-method (update arg :number-of-retries dec)))
on-error)) on-error))
(defn call-ext-method [method] (defn call-ext-method [waku-enabled? method]
(if config/waku-enabled? (if waku-enabled?
(str "wakuext_" method) (str "wakuext_" method)
(str "shhext_" method))) (str "shhext_" method)))

View File

@ -30,6 +30,7 @@
[status-im.i18n :as i18n] [status-im.i18n :as i18n]
[status-im.init.core :as init] [status-im.init.core :as init]
[status-im.log-level.core :as log-level] [status-im.log-level.core :as log-level]
status-im.waku.core
[status-im.mailserver.core :as mailserver] [status-im.mailserver.core :as mailserver]
[status-im.mailserver.constants :as mailserver.constants] [status-im.mailserver.constants :as mailserver.constants]
[status-im.mailserver.topics :as mailserver.topics] [status-im.mailserver.topics :as mailserver.topics]

View File

@ -14,6 +14,7 @@
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
[status-im.utils.pairing :as pairing.utils] [status-im.utils.pairing :as pairing.utils]
[status-im.waku.core :as waku]
[status-im.chat.models :as models.chat] [status-im.chat.models :as models.chat]
[status-im.chat.models.message :as models.message] [status-im.chat.models.message :as models.message]
[status-im.contact.core :as models.contact] [status-im.contact.core :as models.contact]
@ -31,7 +32,7 @@
(fx/defn remove-member (fx/defn remove-member
"Format group update message and sign membership" "Format group update message and sign membership"
[{:keys [db] :as cofx} chat-id member] [{: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] :params [nil chat-id member]
:on-success #(re-frame/dispatch [::chat-updated %])}]}) :on-success #(re-frame/dispatch [::chat-updated %])}]})
@ -74,33 +75,33 @@
(fx/defn join-chat (fx/defn join-chat
[cofx chat-id] [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] :params [chat-id]
:on-success #(re-frame/dispatch [::chat-updated %])}]}) :on-success #(re-frame/dispatch [::chat-updated %])}]})
(fx/defn create (fx/defn create
[{:keys [db] :as cofx} group-name] [{:keys [db] :as cofx} group-name]
(let [selected-contacts (:group/selected-contacts db)] (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)] :params [nil group-name (into [] selected-contacts)]
:on-success #(re-frame/dispatch [::chat-updated %])}]})) :on-success #(re-frame/dispatch [::chat-updated %])}]}))
(fx/defn make-admin (fx/defn make-admin
[{:keys [db] :as cofx} chat-id member] [{: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]] :params [nil chat-id [member]]
:on-success #(re-frame/dispatch [::chat-updated %])}]}) :on-success #(re-frame/dispatch [::chat-updated %])}]})
(fx/defn add-members (fx/defn add-members
"Add members to a group chat" "Add members to a group chat"
[{{:keys [current-chat-id selected-participants]} :db :as cofx}] [{{: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] :params [nil current-chat-id selected-participants]
:on-success #(re-frame/dispatch [::chat-updated %])}]}) :on-success #(re-frame/dispatch [::chat-updated %])}]})
(fx/defn remove (fx/defn remove
"Remove & leave chat" "Remove & leave chat"
[{:keys [db] :as cofx} chat-id] [{: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] :params [nil chat-id]
:on-success #(re-frame/dispatch [::chat-updated %])}]}) :on-success #(re-frame/dispatch [::chat-updated %])}]})
@ -123,7 +124,7 @@
(let [new-name (get-in cofx [:db :group-chat-profile/profile :name]) (let [new-name (get-in cofx [:db :group-chat-profile/profile :name])
current-chat-id (:current-chat-id db)] current-chat-id (:current-chat-id db)]
(when (valid-name? new-name) (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] :params [nil current-chat-id new-name]
:on-success #(re-frame/dispatch [::chat-updated %])}]}))) :on-success #(re-frame/dispatch [::chat-updated %])}]})))

View File

@ -4,6 +4,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.data-store.mailservers :as data-store.mailservers] [status-im.data-store.mailservers :as data-store.mailservers]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.waku.core :as waku]
[status-im.node.core :as node] [status-im.node.core :as node]
[status-im.i18n :as i18n] [status-im.i18n :as i18n]
[status-im.mailserver.constants :as constants] [status-im.mailserver.constants :as constants]
@ -87,9 +88,9 @@
;; We now wait for a confirmation from the mailserver before marking the message ;; We now wait for a confirmation from the mailserver before marking the message
;; as sent. ;; as sent.
(defn update-mailservers! [enodes] (defn update-mailservers! [waku-enabled? enodes]
(json-rpc/call (json-rpc/call
{:method (json-rpc/call-ext-method "updateMailservers") {:method (json-rpc/call-ext-method waku-enabled? "updateMailservers")
:params [enodes] :params [enodes]
:on-success #(log/debug "mailserver: update-mailservers success" %) :on-success #(log/debug "mailserver: update-mailservers success" %)
:on-error #(log/error "mailserver: update-mailservers error" %)})) :on-error #(log/error "mailserver: update-mailservers error" %)}))
@ -117,8 +118,9 @@
(re-frame/reg-fx (re-frame/reg-fx
:mailserver/update-mailservers :mailserver/update-mailservers
(fn [enodes] (fn [[waku-enabled? enodes]]
(update-mailservers! enodes))) (println "HERE" waku-enabled? enodes)
(update-mailservers! waku-enabled? enodes)))
(defn decrease-limit [] (defn decrease-limit []
(max constants/min-limit (/ @limit 2))) (max constants/min-limit (/ @limit 2)))
@ -144,9 +146,9 @@
(reset! limit (decrease-limit)) (reset! limit (decrease-limit))
(reset! success-counter 0))) (reset! success-counter 0)))
(defn mark-trusted-peer! [enode] (defn mark-trusted-peer! [waku-enabled? enode]
(json-rpc/call (json-rpc/call
{:method (if config/waku-enabled? {:method (if waku-enabled?
"waku_markTrustedPeer" "waku_markTrustedPeer"
"shh_markTrustedPeer") "shh_markTrustedPeer")
:params [enode] :params [enode]
@ -157,7 +159,8 @@
(re-frame/reg-fx (re-frame/reg-fx
:mailserver/mark-trusted-peer :mailserver/mark-trusted-peer
mark-trusted-peer!) (fn [[waku-enabled? enode]]
(mark-trusted-peer! waku-enabled? enode)))
(fx/defn generate-mailserver-symkey (fx/defn generate-mailserver-symkey
[{:keys [db] :as cofx} {:keys [password id] :as mailserver}] [{:keys [db] :as cofx} {:keys [password id] :as mailserver}]
@ -166,7 +169,8 @@
:generating-sym-key?] :generating-sym-key?]
true) true)
:shh/generate-sym-key-from-password :shh/generate-sym-key-from-password
[{:password password [(waku/enabled? cofx)
{:password password
:on-success :on-success
(fn [_ sym-key-id] (fn [_ sym-key-id]
(re-frame/dispatch (re-frame/dispatch
@ -189,7 +193,7 @@
(fetch-current db)] (fetch-current db)]
(fx/merge cofx (fx/merge cofx
{:db (update-mailserver-state db :added) {: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?) (when-not (or sym-key-id generating-sym-key?)
(generate-mailserver-symkey mailserver))))) (generate-mailserver-symkey mailserver)))))
@ -206,7 +210,7 @@
;; Any message sent before this takes effect will not be marked as sent ;; 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 ;; probably we should improve the UX so that is more transparent to the
;; user ;; user
:mailserver/update-mailservers [address]} :mailserver/update-mailservers [(waku/enabled? cofx) [address]]}
(when-not (or sym-key-id generating-sym-key?) (when-not (or sym-key-id generating-sym-key?)
(generate-mailserver-symkey mailserver))))) (generate-mailserver-symkey mailserver)))))
@ -345,7 +349,8 @@
request-id)})))) request-id)}))))
(defn request-messages! (defn request-messages!
[{:keys [sym-key-id address]} [waku-enabled?
{:keys [sym-key-id address]}
{:keys [topics cursor to from force-to?] :as request}] {:keys [topics cursor to from force-to?] :as request}]
;; Add some room to from, unless we break day boundaries so that ;; Add some room to from, unless we break day boundaries so that
;; messages that have been received after the last request are also fetched ;; messages that have been received after the last request are also fetched
@ -361,7 +366,7 @@
" cursor " cursor " cursor " cursor
" limit " actual-limit) " limit " actual-limit)
(json-rpc/call (json-rpc/call
{:method (json-rpc/call-ext-method "requestMessages") {:method (json-rpc/call-ext-method waku-enabled? "requestMessages")
:params [(cond-> {:topics topics :params [(cond-> {:topics topics
:mailServerPeer address :mailServerPeer address
:symKeyID sym-key-id :symKeyID sym-key-id
@ -387,8 +392,8 @@
(re-frame/reg-fx (re-frame/reg-fx
:mailserver/request-messages :mailserver/request-messages
(fn [{:keys [mailserver request]}] (fn [{:keys [mailserver request waku-enabled?]}]
(request-messages! mailserver request))) (request-messages! waku-enabled? mailserver request)))
(defn get-mailserver-when-ready (defn get-mailserver-when-ready
"return the mailserver if the mailserver is ready" "return the mailserver if the mailserver is ready"
@ -460,7 +465,8 @@
:mailserver/pending-requests (count requests) :mailserver/pending-requests (count requests)
:mailserver/current-request request :mailserver/current-request request
:mailserver/request-to request-to) :mailserver/request-to request-to)
:mailserver/request-messages {:mailserver mailserver :mailserver/request-messages {:waku-enabled? (waku/enabled? cofx)
:mailserver mailserver
:request request}} :request request}}
{:db (dissoc db {:db (dissoc db
:mailserver/pending-requests :mailserver/pending-requests
@ -783,7 +789,8 @@
(when-let [mailserver (get-mailserver-when-ready cofx)] (when-let [mailserver (get-mailserver-when-ready cofx)]
(let [request-with-cursor (assoc request :cursor cursor)] (let [request-with-cursor (assoc request :cursor cursor)]
{:db (assoc db :mailserver/current-request request-with-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}})) :request request-with-cursor}}))
(let [{:keys [gap chat-id]} request] (let [{:keys [gap chat-id]} request]
(fx/merge (fx/merge
@ -927,7 +934,8 @@
(not current-request) (not current-request)
(-> (assoc-in [:db :mailserver/current-request] first-request) (-> (assoc-in [:db :mailserver/current-request] first-request)
(assoc :mailserver/request-messages (assoc :mailserver/request-messages
{:mailserver mailserver {:waku-enabled? (waku/enabled? cofx)
:mailserver mailserver
:request first-request}))))) :request first-request})))))
(fx/defn resend-request (fx/defn resend-request
@ -969,7 +977,8 @@
{:db (update-in db [:mailserver/current-request :attempts] inc) {:db (update-in db [:mailserver/current-request :attempts] inc)
:mailserver/decrease-limit [] :mailserver/decrease-limit []
:mailserver/request-messages :mailserver/request-messages
{:mailserver mailserver {:waku-enabled? (waku/enabled? cofx)
:mailserver mailserver
:request (assoc request :limit (decrease-limit))}}) :request (assoc request :limit (decrease-limit))}})
:else :else

View File

@ -261,7 +261,7 @@
;;so here we set it at 1 already so that it passes the check once it has ;;so here we set it at 1 already so that it passes the check once it has
;;been initialized ;;been initialized
:filters/initialized 1) :filters/initialized 1)
:filters/load-filters []} :filters/load-filters [[(:waku-enabled multiaccount) []]]}
(finish-keycard-setup) (finish-keycard-setup)
(protocol/initialize-protocol {:mailservers [] (protocol/initialize-protocol {:mailservers []
:mailserver-ranges {} :mailserver-ranges {}

View File

@ -7,10 +7,10 @@
[status-im.utils.types :as types] [status-im.utils.types :as types]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn send-multiaccount-update [{:keys [db]}] (fx/defn send-multiaccount-update [{:keys [db] :as cofx}]
(let [multiaccount (:multiaccount db) (let [multiaccount (:multiaccount db)
{:keys [name preferred-name photo-path address]} multiaccount] {: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] :params [(or preferred-name name) photo-path]
:on-success #(log/debug "sent contact update")}]})) :on-success #(log/debug "sent contact update")}]}))

View File

@ -1,6 +1,7 @@
(ns status-im.multiaccounts.update.publisher (ns status-im.multiaccounts.update.publisher
(:require [taoensso.timbre :as log] (:require [taoensso.timbre :as log]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.waku.core :as waku]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.multiaccounts.update.core :as multiaccounts] [status-im.multiaccounts.update.core :as multiaccounts]
@ -11,7 +12,7 @@
;; Publish updates every 48 hours ;; Publish updates every 48 hours
(def publish-updates-interval (* 48 60 60 1000)) (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]) (let [my-public-key (get-in db [:multiaccount :public-key])
peers-count (:peers-count db) peers-count (:peers-count db)
last-updated (get-in last-updated (get-in
@ -25,7 +26,7 @@
{:keys [name preferred-name photo-path address]} multiaccount] {:keys [name preferred-name photo-path address]} multiaccount]
(log/debug "sending contact updates") (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] :params [(or preferred-name name) photo-path]
:on-failure #(do :on-failure #(do
(log/warn "failed to send contact updates") (log/warn "failed to send contact updates")

View File

@ -95,6 +95,7 @@
current-fleet (get-current-fleet db) current-fleet (get-current-fleet db)
rendezvous-nodes (pick-nodes 3 (vals (:rendezvous current-fleet))) rendezvous-nodes (pick-nodes 3 (vals (:rendezvous current-fleet)))
{:keys [installation-id log-level {:keys [installation-id log-level
waku-enabled waku-bloom-filter-mode
custom-bootnodes custom-bootnodes-enabled?]} multiaccount custom-bootnodes custom-bootnodes-enabled?]} multiaccount
use-custom-bootnodes (get custom-bootnodes-enabled? current-network)] use-custom-bootnodes (get custom-bootnodes-enabled? current-network)]
(cond-> (get-in networks [current-network :config]) (cond-> (get-in networks [current-network :config])
@ -122,8 +123,9 @@
:PermissionsConfig {:Enabled true} :PermissionsConfig {:Enabled true}
:MailserversConfig {:Enabled true} :MailserversConfig {:Enabled true}
:EnableNTPSync true :EnableNTPSync true
(if config/waku-enabled? :WakuConfig :WhisperConfig) (if waku-enabled :WakuConfig :WhisperConfig)
{:Enabled true {:Enabled true
:BloomFilterMode waku-bloom-filter-mode
:LightClient true :LightClient true
:MinimumPoW 0.001} :MinimumPoW 0.001}
:ShhextConfig :ShhextConfig

View File

@ -1,7 +1,7 @@
(ns status-im.pairing.core (ns status-im.pairing.core (:require [clojure.string :as string]
(:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.chat.models :as models.chat] [status-im.chat.models :as models.chat]
[status-im.waku.core :as waku]
[status-im.contact.core :as contact] [status-im.contact.core :as contact]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@ -18,26 +18,26 @@
[status-im.utils.platform :as utils.platform] [status-im.utils.platform :as utils.platform]
[status-im.utils.types :as types])) [status-im.utils.types :as types]))
(defn enable-installation-rpc [installation-id on-success on-failure] (defn enable-installation-rpc [waku-enabled? installation-id on-success on-failure]
(json-rpc/call {:method (json-rpc/call-ext-method "enableInstallation") (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "enableInstallation")
:params [installation-id] :params [installation-id]
:on-success on-success :on-success on-success
:on-failure on-failure})) :on-failure on-failure}))
(defn disable-installation-rpc [installation-id on-success on-failure] (defn disable-installation-rpc [waku-enabled? installation-id on-success on-failure]
(json-rpc/call {:method (json-rpc/call-ext-method "disableInstallation") (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "disableInstallation")
:params [installation-id] :params [installation-id]
:on-success on-success :on-success on-success
:on-failure on-failure})) :on-failure on-failure}))
(defn set-installation-metadata-rpc [installation-id metadata on-success on-failure] (defn set-installation-metadata-rpc [waku-enabled? installation-id metadata on-success on-failure]
(json-rpc/call {:method (json-rpc/call-ext-method "setInstallationMetadata") (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "setInstallationMetadata")
:params [installation-id metadata] :params [installation-id metadata]
:on-success on-success :on-success on-success
:on-failure on-failure})) :on-failure on-failure}))
(defn get-our-installations-rpc [on-success on-failure] (defn get-our-installations-rpc [waku-enabled? on-success on-failure]
(json-rpc/call {:method (json-rpc/call-ext-method "getOurInstallations") (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "getOurInstallations")
:params [] :params []
:on-success on-success :on-success on-success
:on-failure on-failure})) :on-failure on-failure}))
@ -65,7 +65,7 @@
(defn send-pair-installation (defn send-pair-installation
[cofx] [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 [] :params []
:on-success #(log/info "sent pair installation message")}]}) :on-success #(log/info "sent pair installation message")}]})
@ -91,11 +91,13 @@
"Set the name of the device" "Set the name of the device"
[{:keys [db] :as cofx} installation-name] [{:keys [db] :as cofx} installation-name]
(let [our-installation-id (get-in db [:multiaccount :installation-id])] (let [our-installation-id (get-in db [:multiaccount :installation-id])]
{:pairing/set-installation-metadata [[our-installation-id {:name installation-name {:pairing/set-installation-metadata [(waku/enabled? cofx)
:deviceType utils.platform/os}]]})) our-installation-id
{:name installation-name
:deviceType utils.platform/os}]}))
(fx/defn init [cofx] (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] (defn handle-bundles-added [{:keys [db] :as cofx} bundle]
(let [installation-id (:installationID bundle)] (let [installation-id (:installationID bundle)]
@ -139,57 +141,64 @@
[result] [result]
(re-frame/dispatch [:pairing.callback/get-our-installations-success result])) (re-frame/dispatch [:pairing.callback/get-our-installations-success result]))
(defn enable-installation! [installation-id] (defn enable-installation! [waku-enabled? installation-id]
(enable-installation-rpc installation-id (enable-installation-rpc
waku-enabled?
installation-id
(partial handle-enable-installation-response-success installation-id) (partial handle-enable-installation-response-success installation-id)
nil)) nil))
(defn disable-installation! [installation-id] (defn disable-installation! [waku-enabled? installation-id]
(disable-installation-rpc installation-id (disable-installation-rpc
waku-enabled?
installation-id
(partial handle-disable-installation-response-success installation-id) (partial handle-disable-installation-response-success installation-id)
nil)) nil))
(defn set-installation-metadata! [installation-id metadata] (defn set-installation-metadata! [waku-enabled? installation-id metadata]
(set-installation-metadata-rpc installation-id (set-installation-metadata-rpc
waku-enabled?
installation-id
metadata metadata
(partial handle-set-installation-metadata-response-success installation-id metadata) (partial handle-set-installation-metadata-response-success installation-id metadata)
nil)) nil))
(defn get-our-installations [] (defn get-our-installations [waku-enabled?]
(get-our-installations-rpc handle-get-our-installations-response-success nil)) (get-our-installations-rpc waku-enabled? handle-get-our-installations-response-success nil))
(defn enable-fx [cofx installation-id] (defn enable-fx [cofx installation-id]
(if (< (count (filter :enabled? (vals (get-in cofx [:db :pairing/installations])))) (inc config/max-installations)) (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) {:utils/show-popup {:title (i18n/label :t/pairing-maximum-number-reached-title)
:content (i18n/label :t/pairing-maximum-number-reached-content)}})) :content (i18n/label :t/pairing-maximum-number-reached-content)}}))
(defn disable-fx [_ installation-id] (defn disable-fx [cofx installation-id]
{:pairing/disable-installation installation-id}) {:pairing/disable-installation [(waku/enabled? cofx) installation-id]})
(re-frame/reg-fx (re-frame/reg-fx
:pairing/enable-installation :pairing/enable-installation
enable-installation!) (fn [[waku-enabled? installation-id]]
(enable-installation! waku-enabled? installation-id)))
(re-frame/reg-fx (re-frame/reg-fx
:pairing/disable-installation :pairing/disable-installation
disable-installation!) (fn [[waku-enabled? installation-id]]
(disable-installation! waku-enabled? installation-id)))
(re-frame/reg-fx (re-frame/reg-fx
:pairing/set-installation-metadata :pairing/set-installation-metadata
(fn [pairs] (fn [[waku-enabled? installation-id metadata]]
(doseq [[installation-id metadata] pairs] (set-installation-metadata! waku-enabled? installation-id metadata)))
(set-installation-metadata! installation-id metadata))))
(re-frame/reg-fx (re-frame/reg-fx
:pairing/get-our-installations :pairing/get-our-installations
get-our-installations) get-our-installations)
(defn send-installation-messages [{:keys [db]}] (defn send-installation-messages [{:keys [db] :as cofx}]
(let [multiaccount (:multiaccount db) (let [multiaccount (:multiaccount db)
{:keys [name preferred-name photo-path]} multiaccount] {: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] :params [(or preferred-name name) photo-path]
:on-success #(log/debug "successfully synced devices")}]})) :on-success #(log/debug "successfully synced devices")}]}))

View File

@ -3,6 +3,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.waku.core :as waku]
[status-im.ethereum.abi-spec :as abi-spec] [status-im.ethereum.abi-spec :as abi-spec]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
@ -213,7 +214,7 @@
(fx/defn send-transaction-message (fx/defn send-transaction-message
{:events [::send-transaction-message]} {:events [::send-transaction-message]}
[cofx chat-id value contract transaction-hash signature] [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 :params [chat-id value contract transaction-hash
(:result (types/json->clj signature))] (:result (types/json->clj signature))]
:on-success :on-success
@ -222,7 +223,7 @@
(fx/defn send-accept-request-transaction-message (fx/defn send-accept-request-transaction-message
{:events [::send-accept-transaction-message]} {:events [::send-accept-transaction-message]}
[cofx message-id transaction-hash signature] [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 :params [transaction-hash message-id
(:result (types/json->clj signature))] (:result (types/json->clj signature))]
:on-success :on-success

View File

@ -487,6 +487,18 @@
(or (get multiaccount :log-level) (or (get multiaccount :log-level)
config/log-level-status-go))) 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 (re-frame/reg-sub
:dapps-address :dapps-address
:<- [:multiaccount] :<- [:multiaccount]

View File

@ -3,6 +3,7 @@
(:require (:require
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.waku.core :as waku]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.mailserver.core :as mailserver] [status-im.mailserver.core :as mailserver]
[status-im.transport.message.core :as message] [status-im.transport.message.core :as message]
@ -40,7 +41,7 @@
initializiation is completed, otherwise we might receive messages/topics initializiation is completed, otherwise we might receive messages/topics
when the state has not been properly initialized." when the state has not been properly initialized."
[cofx] [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 :on-success #(do
(log/debug "messenger initialized") (log/debug "messenger initialized")
(re-frame/dispatch [::init-whisper])) (re-frame/dispatch [::init-whisper]))

View File

@ -5,6 +5,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[clojure.string :as string] [clojure.string :as string]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[status-im.waku.core :as waku]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.utils.config :as config] [status-im.utils.config :as config]
@ -17,26 +18,26 @@
(defn is-public-key? [k] (defn is-public-key? [k]
(string/starts-with? k "0x")) (string/starts-with? k "0x"))
(defn load-filters-rpc [chats on-success on-failure] (defn load-filters-rpc [waku-enabled? chats on-success on-failure]
(json-rpc/call {:method (json-rpc/call-ext-method "loadFilters") (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "loadFilters")
:params [chats] :params [chats]
:on-success on-success :on-success on-success
:on-failure on-failure})) :on-failure on-failure}))
(defn remove-filters-rpc [chats on-success on-failure] (defn remove-filters-rpc [waku-enabled? chats on-success on-failure]
(json-rpc/call {:method (json-rpc/call-ext-method "removeFilters") (json-rpc/call {:method (json-rpc/call-ext-method waku-enabled? "removeFilters")
:params [chats] :params [chats]
:on-success on-success :on-success on-success
:on-failure on-failure})) :on-failure on-failure}))
;; fx functions ;; fx functions
(defn load-filter-fx [filters] (defn load-filter-fx [waku-enabled? filters]
{:filters/load-filters filters}) {:filters/load-filters [[waku-enabled? filters]]})
(defn remove-filter-fx [filters] (defn remove-filter-fx [waku-enabled? filters]
(when (seq filters) (when (seq filters)
{:filters/remove-filters filters})) {:filters/remove-filters [waku-enabled? filters]}))
;; dispatches ;; dispatches
@ -249,37 +250,37 @@
(fx/defn load-filters (fx/defn load-filters
"Load all contacts and chats as filters" "Load all contacts and chats as filters"
[{:keys [db]}] [{:keys [db] :as cofx}]
(log/debug "loading filters") (log/debug "loading filters")
(let [chats (vals (:chats db)) (let [chats (vals (:chats db))
contacts (vals (:contacts/contacts db)) contacts (vals (:contacts/contacts db))
filters (concat filters (concat
(chats->filter-requests chats) (chats->filter-requests chats)
(contacts->filter-requests contacts))] (contacts->filter-requests contacts))]
(load-filter-fx filters))) (load-filter-fx (waku/enabled? cofx) filters)))
;; Load functions: utility function to load filters ;; Load functions: utility function to load filters
(fx/defn load-chat (fx/defn load-chat
"Check if a filter already exists for that chat, otherw load the filter" "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) (when (and (filters-initialized? db)
(not (chat-loaded? db chat-id))) (not (chat-loaded? db chat-id)))
(let [chat (get-in db [:chats 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 (fx/defn load-contact
"Check if we already have a filter for that contact, otherwise load the filter "Check if we already have a filter for that contact, otherwise load the filter
if the contact has been added" if the contact has been added"
[{:keys [db]} contact] [{:keys [db] :as cofx} contact]
(when-not (chat-loaded? db (:public-key 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 (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" "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) (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 (fx/defn load-members
"Load multiple members" "Load multiple members"
@ -310,6 +311,7 @@
;; we exclude the negotiated filters as those are not to be removed ;; we exclude the negotiated filters as those are not to be removed
;; otherwise we might miss messages ;; otherwise we might miss messages
(remove-filter-fx (remove-filter-fx
(waku/enabled? cofx)
(non-negotiated-filters-for-chat-id db chat-id)))))) (non-negotiated-filters-for-chat-id db chat-id))))))
;; reg-fx ;; reg-fx
@ -336,17 +338,21 @@
;; we should recreate it. ;; we should recreate it.
(re-frame/reg-fx (re-frame/reg-fx
:filters/remove-filters :filters/remove-filters
(fn [filters] (fn [[waku-enabled? filters]]
(log/debug "removing filters" filters) (log/debug "removing filters" filters)
(remove-filters-rpc (remove-filters-rpc
waku-enabled?
(map ->remove-filter-request filters) (map ->remove-filter-request filters)
#(filters-removed! filters) #(filters-removed! filters)
#(log/error "remove-filters: failed error" %)))) #(log/error "remove-filters: failed error" %))))
(re-frame/reg-fx (re-frame/reg-fx
:filters/load-filters :filters/load-filters
(fn [filters] (fn [raw-filters]
(let [waku-enabled? (first (first raw-filters))
all-filters (mapcat second raw-filters)]
(load-filters-rpc (load-filters-rpc
filters waku-enabled?
all-filters
#(filters-added! (map responses->filters %)) #(filters-added! (map responses->filters %))
#(log/error "load-filters: failed error" %)))) #(log/error "load-filters: failed error" %)))))

View File

@ -6,7 +6,7 @@
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn send-chat-message [_ {:keys [chat-id (fx/defn send-chat-message [cofx {:keys [chat-id
text text
response-to response-to
ens-name ens-name
@ -14,7 +14,9 @@
sticker sticker
content-type] content-type]
:as message}] :as message}]
{::json-rpc/call [{:method (json-rpc/call-ext-method "sendChatMessage") {::json-rpc/call [{:method (json-rpc/call-ext-method
(get-in cofx [:db :multiaccount :waku-enabled])
"sendChatMessage")
:params [{:chatId chat-id :params [{:chatId chat-id
:text text :text text
:responseTo response-to :responseTo response-to

View File

@ -8,8 +8,8 @@
[status-im.ethereum.json-rpc :as json-rpc])) [status-im.ethereum.json-rpc :as json-rpc]))
(defn generate-sym-key-from-password (defn generate-sym-key-from-password
[{:keys [password on-success on-error]}] [waku-enabled? {:keys [password on-success on-error]}]
(json-rpc/call {:method (if config/waku-enabled? (json-rpc/call {:method (if waku-enabled?
"waku_generateSymKeyFromPassword" "waku_generateSymKeyFromPassword"
"shh_generateSymKeyFromPassword") "shh_generateSymKeyFromPassword")
:params [password] :params [password]
@ -17,8 +17,8 @@
:on-error on-error})) :on-error on-error}))
(defn get-sym-key (defn get-sym-key
[{:keys [sym-key-id on-success on-error]}] [waku-enabled? {:keys [sym-key-id on-success on-error]}]
(json-rpc/call {:method (if config/waku-enabled? (json-rpc/call {:method (if waku-enabled?
"waku_getSymKey" "waku_getSymKey"
"shh_getSymKey") "shh_getSymKey")
:params [sym-key-id] :params [sym-key-id]
@ -30,12 +30,14 @@
(re-frame/reg-fx (re-frame/reg-fx
:shh/generate-sym-key-from-password :shh/generate-sym-key-from-password
(fn [args] (fn [[waku-enabled? {:keys [password on-success]}]]
(doseq [{:keys [password on-success]} args] (generate-sym-key-from-password
(generate-sym-key-from-password {:password password waku-enabled?
{:password password
:on-success (fn [sym-key-id] :on-success (fn [sym-key-id]
(get-sym-key {:sym-key-id sym-key-id (get-sym-key waku-enabled?
{:sym-key-id sym-key-id
:on-success (fn [sym-key] :on-success (fn [sym-key]
(on-success sym-key sym-key-id)) (on-success sym-key sym-key-id))
:on-error log-error})) :on-error log-error}))
:on-error log-error})))) :on-error log-error})))

View File

@ -6,8 +6,12 @@
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.ui.components.topbar :as topbar])) [status-im.ui.components.topbar :as topbar]))
(defn- normal-mode-settings-data [network-name current-log-level (defn- normal-mode-settings-data [{:keys [network-name
current-fleet dev-mode?] current-log-level
waku-enabled
waku-bloom-filter-mode
current-fleet
dev-mode?]}]
[{:type :small [{:type :small
:title :t/network :title :t/network
:accessibility-label :network-button :accessibility-label :network-button
@ -45,6 +49,36 @@
:on-press :on-press
#(re-frame/dispatch [:navigate-to :bootnodes-settings]) #(re-frame/dispatch [:navigate-to :bootnodes-settings])
:accessories [:chevron]} :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 #_{:type :small
:title :t/dev-mode :title :t/dev-mode
:accessibility-label :dev-mode-settings-switch :accessibility-label :dev-mode-settings-switch
@ -82,28 +116,34 @@
:disabled false}]]} :disabled false}]]}
[react/view {:height 24}]]) [react/view {:height 24}]])
(defn- flat-list-data [network-name current-log-level current-fleet (defn- flat-list-data [{:keys [dev-mode?
dev-mode? chaos-mode?] chaos-mode?]
:as options}]
(if dev-mode? (if dev-mode?
(into (into
(normal-mode-settings-data (normal-mode-settings-data options)
network-name current-log-level current-fleet dev-mode?)
(dev-mode-settings-data chaos-mode?)) (dev-mode-settings-data chaos-mode?))
;; else ;; else
(normal-mode-settings-data (normal-mode-settings-data options)))
network-name current-log-level current-fleet dev-mode?)))
(views/defview advanced-settings [] (views/defview advanced-settings []
(views/letsubs [{:keys [chaos-mode?]} [:multiaccount] (views/letsubs [{:keys [chaos-mode?]} [:multiaccount]
network-name [:network-name] 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-log-level [:log-level/current-log-level]
current-fleet [:fleets/current-fleet]] current-fleet [:fleets/current-fleet]]
[react/view {:flex 1 :background-color colors/white} [react/view {:flex 1 :background-color colors/white}
[topbar/topbar {:title :t/advanced}] [topbar/topbar {:title :t/advanced}]
[list/flat-list [list/flat-list
{:data (flat-list-data {:data (flat-list-data
network-name current-log-level {:network-name network-name
current-fleet false chaos-mode?) :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)) :key-fn (fn [_ i] (str i))
:render-fn list/flat-list-generic-render-fn}]])) :render-fn list/flat-list-generic-render-fn}]]))

View File

@ -17,7 +17,6 @@
:status-im.ens.core/verify-names :status-im.ens.core/verify-names
:shh/send-direct-message :shh/send-direct-message
:shh/remove-filter :shh/remove-filter
:shh/generate-sym-key-from-password
:transport/confirm-messages-processed :transport/confirm-messages-processed
:group-chats/extract-membership-signature :group-chats/extract-membership-signature
:utils/dispatch-later :utils/dispatch-later

View File

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

View File

@ -3,6 +3,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.waku.core :as waku]
[status-im.chat.models.message :as chat.message] [status-im.chat.models.message :as chat.message]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.eip55 :as eip55] [status-im.ethereum.eip55 :as eip55]
@ -407,7 +408,7 @@
[to-norm amount-hex])})})) [to-norm amount-hex])})}))
{:db db {:db db
::json-rpc/call ::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) :params [(:current-chat-id db)
from-address from-address
amount amount
@ -426,7 +427,7 @@
{:db (-> db {:db (-> db
(update-in [:chat-ui-props identity] dissoc :input-bottom-sheet) (update-in [:chat-ui-props identity] dissoc :input-bottom-sheet)
(dissoc db :wallet/prepare-transaction)) (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) :params [(:public-key to)
amount amount
(when-not (= symbol :ETH) (when-not (= symbol :ETH)

View File

@ -625,7 +625,7 @@
(is (= "mailserver-password" (is (= "mailserver-password"
(-> (mailserver/connect-to-mailserver {:db db}) (-> (mailserver/connect-to-mailserver {:db db})
:shh/generate-sym-key-from-password :shh/generate-sym-key-from-password
first second
:password)))) :password))))
(let [mailserver-with-sym-key-db (assoc-in db (let [mailserver-with-sym-key-db (assoc-in db
[:mailserver/mailservers :eth.staging "mailserverid" :sym-key-id] [:mailserver/mailservers :eth.staging "mailserverid" :sym-key-id]

View File

@ -24,7 +24,7 @@
"b" {:chat-id chat-id :negotiated? true}}}} "b" {:chat-id chat-id :negotiated? true}}}}
chat-id)] chat-id)]
(is fx) (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 "the user is still in some group chats"
(testing "we joined, and group chat is active it does not remove filters" (testing "we joined, and group chat is active it does not remove filters"
(let [fx (transport.filters/stop-listening {:db {:multiaccount {:public-key me} (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 {:chat-id member-1 :filter-id "a"}}}}
member-1)] member-1)]
(is fx) (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 "we have a 1-to-1 chat with the user"
(testing "it does not remove filter" (testing "it does not remove filter"
(let [fx (transport.filters/stop-listening {:db {:chats (let [fx (transport.filters/stop-listening {:db {:chats
@ -98,19 +98,19 @@
(deftest load-member (deftest load-member
(testing "it returns fx for a member" (testing "it returns fx for a member"
(is (= {:filters/load-filters [{:ChatID "0xchat-id-2" (is (= {:filters/load-filters [[nil [{:ChatID "0xchat-id-2"
:OneToOne true :OneToOne true
:Identity "chat-id-2"}]} :Identity "chat-id-2"}]]]}
(transport.filters/load-member {:db {}} "0xchat-id-2")))) (transport.filters/load-member {:db {}} "0xchat-id-2"))))
(testing "merging fx" (testing "merging fx"
(is (= (is (=
{:db {} {:db {}
:filters/load-filters [{:ChatID "0xchat-id-1" :filters/load-filters [[nil [{:ChatID "0xchat-id-1"
:OneToOne true :OneToOne true
:Identity "chat-id-1"} :Identity "chat-id-1"}]]
{:ChatID "0xchat-id-2" [nil [{:ChatID "0xchat-id-2"
:OneToOne true :OneToOne true
:Identity "chat-id-2"}]} :Identity "chat-id-2"}]]]}
(apply fx/merge {:db {}} (apply fx/merge {:db {}}
(map transport.filters/load-member ["0xchat-id-1" "0xchat-id-2"])))))) (map transport.filters/load-member ["0xchat-id-1" "0xchat-id-2"]))))))

View File

@ -1096,5 +1096,7 @@
"add-seed-account": "Add account with a seed phrase", "add-seed-account": "Add account with a seed phrase",
"account-exists-title": "Account already exists", "account-exists-title": "Account already exists",
"add-private-key-account": "Add account from private key", "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"
} }