Only show the Wallet Connect requests for the logged in user (#20815)

Co-authored-by: Lungu Cristian <lungucristian95@gmail.com>
This commit is contained in:
Alexander 2024-07-22 14:57:45 +02:00 committed by GitHub
parent 4b7c906df2
commit d623cc8444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

View File

@ -127,3 +127,19 @@
:url (get-in session [:peer :metadata :url]) :url (get-in session [:peer :metadata :url])
:accounts (get-in session [:namespaces :eip155 :accounts]) :accounts (get-in session [:namespaces :eip155 :accounts])
:disconnected false}) :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))

View File

@ -55,9 +55,7 @@
(log/info "Received Wallet Connect session proposal: " {:id (:id proposal)}) (log/info "Received Wallet Connect session proposal: " {:id (:id proposal)})
(let [accounts (get-in db [:wallet :accounts]) (let [accounts (get-in db [:wallet :accounts])
current-viewing-address (get-in db [:wallet :current-viewing-account-address]) current-viewing-address (get-in db [:wallet :current-viewing-account-address])
available-accounts (filter #(and (:operable? %) available-accounts (wallet-connect-core/filter-operable-accounts (vals accounts))
(not (:watch-only? %)))
(vals accounts))
networks (wallet-connect-core/get-networks-by-mode db) networks (wallet-connect-core/get-networks-by-mode db)
session-networks (wallet-connect-core/proposal-networks-intersection proposal session-networks (wallet-connect-core/proposal-networks-intersection proposal
networks) networks)
@ -204,9 +202,15 @@
:wallet-connect/fetch-active-sessions-success :wallet-connect/fetch-active-sessions-success
(fn [{:keys [db now]} [sessions]] (fn [{:keys [db now]} [sessions]]
(let [persisted-sessions (:wallet-connect/sessions db) (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) sessions (->> (js->clj sessions :keywordize-keys true)
vals 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 expired-sessions (remove
(fn [{:keys [expiry]}] (fn [{:keys [expiry]}]
(> expiry (/ now 1000))) (> expiry (/ now 1000)))