From d623cc8444fd72d28a60cc09b2d535a86bcfe20e Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 22 Jul 2024 14:57:45 +0200 Subject: [PATCH] Only show the Wallet Connect requests for the logged in user (#20815) Co-authored-by: Lungu Cristian --- .../contexts/wallet/wallet_connect/core.cljs | 16 ++++++++++++++++ .../contexts/wallet/wallet_connect/events.cljs | 12 ++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/status_im/contexts/wallet/wallet_connect/core.cljs b/src/status_im/contexts/wallet/wallet_connect/core.cljs index 0bf0ffb1cc..e8a0196dfc 100644 --- a/src/status_im/contexts/wallet/wallet_connect/core.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/core.cljs @@ -127,3 +127,19 @@ :url (get-in session [:peer :metadata :url]) :accounts (get-in session [:namespaces :eip155 :accounts]) :disconnected false}) + +(defn filter-operable-accounts + [accounts] + (filter #(and (:operable? %) + (not (:watch-only? %))) + accounts)) + +(defn filter-sessions-for-account-addresses + [account-addresses sessions] + (filter (fn [{:keys [accounts]}] + (some (fn [account] + (some (fn [account-address] + (clojure.string/includes? account account-address)) + account-addresses)) + accounts)) + sessions)) diff --git a/src/status_im/contexts/wallet/wallet_connect/events.cljs b/src/status_im/contexts/wallet/wallet_connect/events.cljs index d69f7a20ac..3e54f1d156 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events.cljs @@ -55,9 +55,7 @@ (log/info "Received Wallet Connect session proposal: " {:id (:id proposal)}) (let [accounts (get-in db [:wallet :accounts]) current-viewing-address (get-in db [:wallet :current-viewing-account-address]) - available-accounts (filter #(and (:operable? %) - (not (:watch-only? %))) - (vals accounts)) + available-accounts (wallet-connect-core/filter-operable-accounts (vals accounts)) networks (wallet-connect-core/get-networks-by-mode db) session-networks (wallet-connect-core/proposal-networks-intersection proposal networks) @@ -204,9 +202,15 @@ :wallet-connect/fetch-active-sessions-success (fn [{:keys [db now]} [sessions]] (let [persisted-sessions (:wallet-connect/sessions db) + account-addresses (->> (get-in db [:wallet :accounts]) + vals + wallet-connect-core/filter-operable-accounts + (map :address)) sessions (->> (js->clj sessions :keywordize-keys true) vals - (map wallet-connect-core/sdk-session->db-session)) + (map wallet-connect-core/sdk-session->db-session) + (wallet-connect-core/filter-sessions-for-account-addresses + account-addresses)) expired-sessions (remove (fn [{:keys [expiry]}] (> expiry (/ now 1000)))