WC: Last account that established connection is not selected when connecting through global scanner #20801 (#20913)
* WC: Last account that established connection is not selected when connecting through global scanner * WC: Last account that established connection is not selected when connecting through global scanner * Fixes
This commit is contained in:
parent
7cad13c3c7
commit
3363152160
|
@ -1,5 +1,6 @@
|
||||||
(ns status-im.contexts.wallet.wallet-connect.events.session-proposals
|
(ns status-im.contexts.wallet.wallet-connect.events.session-proposals
|
||||||
(:require [re-frame.core :as rf]
|
(:require [clojure.string :as string]
|
||||||
|
[re-frame.core :as rf]
|
||||||
[react-native.wallet-connect :as wallet-connect]
|
[react-native.wallet-connect :as wallet-connect]
|
||||||
[status-im.contexts.wallet.wallet-connect.utils.data-store :as
|
[status-im.contexts.wallet.wallet-connect.utils.data-store :as
|
||||||
data-store]
|
data-store]
|
||||||
|
@ -59,21 +60,30 @@
|
||||||
:wallet-connect/on-session-proposal
|
:wallet-connect/on-session-proposal
|
||||||
(fn [{:keys [db]} [proposal]]
|
(fn [{:keys [db]} [proposal]]
|
||||||
(log/info "Received Wallet Connect session proposal: " proposal)
|
(log/info "Received Wallet Connect session proposal: " 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 (sessions/filter-operable-accounts (vals accounts))
|
sessions (get db :wallet-connect/sessions)
|
||||||
networks (networks/get-networks-by-mode db)
|
available-accounts (sessions/filter-operable-accounts (vals accounts))
|
||||||
session-networks (networks/proposal-networks-intersection proposal networks)
|
latest-connected-account-address (sessions/latest-connected-account-address sessions)
|
||||||
required-networks-supported? (networks/required-networks-supported? proposal networks)]
|
networks (networks/get-networks-by-mode db)
|
||||||
|
session-networks (networks/proposal-networks-intersection proposal networks)
|
||||||
|
required-networks-supported? (networks/required-networks-supported? proposal networks)]
|
||||||
(if (and (not-empty session-networks) required-networks-supported?)
|
(if (and (not-empty session-networks) required-networks-supported?)
|
||||||
{:db (update db
|
{:db (update db
|
||||||
:wallet-connect/current-proposal assoc
|
:wallet-connect/current-proposal assoc
|
||||||
:request proposal
|
:request proposal
|
||||||
:session-networks session-networks
|
:session-networks session-networks
|
||||||
:address (or current-viewing-address
|
:address (cond
|
||||||
(-> available-accounts
|
(not (string/blank? current-viewing-address))
|
||||||
first
|
current-viewing-address
|
||||||
:address)))
|
|
||||||
|
(not (string/blank?
|
||||||
|
latest-connected-account-address))
|
||||||
|
latest-connected-account-address
|
||||||
|
|
||||||
|
:else (-> available-accounts
|
||||||
|
first
|
||||||
|
:address)))
|
||||||
:fx [[:dispatch [:open-modal :screen/wallet.wallet-connect-session-proposal]]]}
|
:fx [[:dispatch [:open-modal :screen/wallet.wallet-connect-session-proposal]]]}
|
||||||
{:fx [[:dispatch [:wallet-connect/show-session-networks-unsupported-toast proposal]]
|
{:fx [[:dispatch [:wallet-connect/show-session-networks-unsupported-toast proposal]]
|
||||||
[:dispatch [:wallet-connect/reject-session-proposal proposal]]]}))))
|
[:dispatch [:wallet-connect/reject-session-proposal proposal]]]}))))
|
||||||
|
|
|
@ -31,3 +31,14 @@
|
||||||
account-addresses))
|
account-addresses))
|
||||||
accounts))
|
accounts))
|
||||||
sessions))
|
sessions))
|
||||||
|
|
||||||
|
(defn latest-connected-account-address
|
||||||
|
[sessions]
|
||||||
|
(let [all-accounts (->> sessions
|
||||||
|
(sort-by :expiry >)
|
||||||
|
first
|
||||||
|
:accounts)]
|
||||||
|
(-> all-accounts
|
||||||
|
first
|
||||||
|
(string/split #":")
|
||||||
|
last)))
|
||||||
|
|
Loading…
Reference in New Issue