From cede0957467739fb660f70944dd0fd2f2580e438 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 3 Oct 2017 16:27:09 +0200 Subject: [PATCH] reset shh keys on starting whisper, fix warnings related to outdated shh keys --- src/status_im/components/drawer/view.cljs | 5 ++++- src/status_im/protocol/core.cljs | 9 +++++++-- src/status_im/protocol/handlers.cljs | 6 +++++- src/status_im/protocol/web3/keys.cljs | 3 +++ src/status_im/ui/screens/network_settings/events.cljs | 3 ++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index a1b4faf157..d3260f2c6e 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -27,7 +27,8 @@ [status-im.utils.listview :as lw] [status-im.utils.platform :as platform] [status-im.utils.utils :as utils] - [status-im.utils.money :as money])) + [status-im.utils.money :as money] + [status-im.protocol.core :as protocol])) (defonce drawer-atom (atom nil)) (defn open-drawer! [] (.openDrawer @drawer-atom)) @@ -49,6 +50,8 @@ (defn navigate-to-accounts [] (close-drawer!) (save-profile!) + ;; TODO(rasom): probably not the best place for this call + (protocol/stop-whisper!) (rf/dispatch [:navigate-to :accounts])) (defview profile-picture [] diff --git a/src/status_im/protocol/core.cljs b/src/status_im/protocol/core.cljs index a1af3892c9..3f60151a23 100644 --- a/src/status_im/protocol/core.cljs +++ b/src/status_im/protocol/core.cljs @@ -68,6 +68,12 @@ (def stop-watching-all! f/remove-all-filters!) (def reset-all-pending-messages! d/reset-all-pending-messages!) +(def reset-keys! shh-keys/reset-keys!) + +(defn stop-whisper! [] + (stop-watching-all!) + (reset-all-pending-messages!) + (reset-keys!)) (defn init-whisper! [{:keys [identity groups callback web3 @@ -75,8 +81,7 @@ :as options}] {:pre [(valid? ::options options)]} (debug :init-whisper) - (stop-watching-all!) - (d/reset-all-pending-messages!) + (stop-whisper!) (let [listener-options {:web3 web3 :identity identity :callback callback}] diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index d3e77abce3..d7cdda8473 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.protocol.handlers (:require [status-im.utils.handlers :as u] - [re-frame.core :refer [dispatch after]] + [re-frame.core :refer [dispatch after] :as re-frame] [status-im.utils.handlers :refer [register-handler]] [status-im.data-store.contacts :as contacts] [status-im.data-store.messages :as messages] @@ -22,6 +22,10 @@ [status-im.utils.web3-provider :as w3] [status-im.utils.datetime :as time])) +(re-frame/reg-fx + :stop-whisper + (fn [] (protocol/stop-whisper!))) + (register-handler :initialize-protocol (fn [db [_ current-account-id ethereum-rpc-url]] (let [{:keys [public-key status updates-public-key diff --git a/src/status_im/protocol/web3/keys.cljs b/src/status_im/protocol/web3/keys.cljs index d03b2b0d26..bda8bf620a 100644 --- a/src/status_im/protocol/web3/keys.cljs +++ b/src/status_im/protocol/web3/keys.cljs @@ -19,3 +19,6 @@ (fn [err res] (swap! password->keys assoc password res) (callback res))))) + +(defn reset-keys! [] + (reset! password->keys {})) diff --git a/src/status_im/ui/screens/network_settings/events.cljs b/src/status_im/ui/screens/network_settings/events.cljs index 1daaf79c77..5a7644c85e 100644 --- a/src/status_im/ui/screens/network_settings/events.cljs +++ b/src/status_im/ui/screens/network_settings/events.cljs @@ -31,4 +31,5 @@ :connect-network (fn [cofx [_ network]] (merge (accounts-events/account-update cofx {:network network}) - {:dispatch [:navigate-to-clean :accounts]}))) + {:dispatch [:navigate-to-clean :accounts] + :stop-whisper nil})))