Proper handling of disconnection, both from the dapp itself and from the list of connected dapps (#20817)
This commit is contained in:
parent
d623cc8444
commit
08b65cbcb7
|
@ -62,16 +62,17 @@
|
|||
(bean/->js {:id id
|
||||
:namespaces approved-namespaces})))
|
||||
|
||||
(defn disconnect-session
|
||||
[{:keys [web3-wallet reason topic]}]
|
||||
(oops/ocall web3-wallet
|
||||
"disconnectSession"
|
||||
(bean/->js {:topic topic
|
||||
:reason reason})))
|
||||
|
||||
(defn get-active-sessions
|
||||
[web3-wallet]
|
||||
(oops/ocall web3-wallet "getActiveSessions"))
|
||||
|
||||
(defn core-pairing-disconnnect
|
||||
[web3-wallet topic]
|
||||
(oops/ocall web3-wallet
|
||||
"core.pairing.disconnect"
|
||||
(bean/->js {:topic topic})))
|
||||
|
||||
(defn core-pairing-pair
|
||||
[web3-wallet url]
|
||||
(oops/ocall web3-wallet
|
||||
|
|
|
@ -290,6 +290,7 @@
|
|||
(def ^:const wallet-connect-session-request-event "session_request")
|
||||
(def ^:const wallet-connect-session-delete-event "session_delete")
|
||||
(def ^:const wallet-connect-user-rejected-error-key "USER_REJECTED")
|
||||
(def ^:const wallet-connect-user-disconnected-reason-key "USER_DISCONNECTED")
|
||||
|
||||
(def ^:const transaction-pending-type-wallet-connect-transfer "WalletConnectTransfer")
|
||||
|
||||
|
|
|
@ -13,12 +13,11 @@
|
|||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- on-disconnect
|
||||
[wallet-account {:keys [name topic pairing-topic]}]
|
||||
[wallet-account {:keys [name topic]}]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch
|
||||
[:wallet-connect/disconnect-dapp
|
||||
{:topic topic
|
||||
:pairing-topic pairing-topic
|
||||
:on-success (fn []
|
||||
(rf/dispatch [:toasts/upsert
|
||||
{:id :dapp-disconnect-success
|
||||
|
|
|
@ -41,8 +41,10 @@
|
|||
|
||||
(rf/reg-fx
|
||||
:effects.wallet-connect/disconnect
|
||||
(fn [{:keys [web3-wallet topic on-success on-fail]}]
|
||||
(-> (wallet-connect/core-pairing-disconnnect web3-wallet topic)
|
||||
(fn [{:keys [web3-wallet topic reason on-success on-fail]}]
|
||||
(-> (wallet-connect/disconnect-session {:web3-wallet web3-wallet
|
||||
:topic topic
|
||||
:reason reason})
|
||||
(promesa/then on-success)
|
||||
(promesa/catch on-fail))))
|
||||
|
||||
|
|
|
@ -115,14 +115,16 @@
|
|||
|
||||
(rf/reg-event-fx
|
||||
:wallet-connect/disconnect-dapp
|
||||
(fn [{:keys [db]} [{:keys [pairing-topic on-success on-fail]}]]
|
||||
(fn [{:keys [db]} [{:keys [topic on-success on-fail]}]]
|
||||
(let [web3-wallet (get db :wallet-connect/web3-wallet)]
|
||||
{:fx [[:effects.wallet-connect/disconnect
|
||||
{:web3-wallet web3-wallet
|
||||
:topic pairing-topic
|
||||
:topic topic
|
||||
:reason (wallet-connect/get-sdk-error
|
||||
constants/wallet-connect-user-disconnected-reason-key)
|
||||
:on-fail on-fail
|
||||
:on-success (fn []
|
||||
(rf/dispatch [:wallet-connect/disconnect-session pairing-topic])
|
||||
(rf/dispatch [:wallet-connect/disconnect-session topic])
|
||||
(when on-success
|
||||
(on-success)))}]]})))
|
||||
|
||||
|
@ -211,12 +213,14 @@
|
|||
(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)))
|
||||
session-topics (set (map :topic sessions))
|
||||
expired-sessions (filter
|
||||
(fn [{:keys [expiry topic]}]
|
||||
(or (< expiry (/ now 1000))
|
||||
(not (contains? session-topics topic))))
|
||||
persisted-sessions)]
|
||||
{:fx (mapv (fn [{:keys [pairingTopic]}]
|
||||
[:wallet-connect/disconnect-session pairingTopic])
|
||||
{:fx (mapv (fn [{:keys [topic]}]
|
||||
[:dispatch [:wallet-connect/disconnect-session topic]])
|
||||
expired-sessions)
|
||||
:db (assoc db :wallet-connect/sessions sessions)})))
|
||||
|
||||
|
@ -274,15 +278,15 @@
|
|||
|
||||
(rf/reg-event-fx
|
||||
:wallet-connect/disconnect-session
|
||||
(fn [{:keys [db]} [pairing-topic]]
|
||||
(fn [{:keys [db]} [topic]]
|
||||
{:db (update db
|
||||
:wallet-connect/sessions
|
||||
(fn [sessions]
|
||||
(->> sessions
|
||||
(remove #(= (:pairingTopic %) pairing-topic))
|
||||
(remove #(= (:topic %) topic))
|
||||
(into []))))
|
||||
:fx [[:json-rpc/call
|
||||
[{:method "wallet_disconnectWalletConnectSession"
|
||||
:params [pairing-topic]
|
||||
:params [topic]
|
||||
:on-success #(log/info "Wallet Connect session disconnected")
|
||||
:on-error #(log/info "Wallet Connect session persistence failed" %)}]]]}))
|
||||
|
|
Loading…
Reference in New Issue