From 9862abb7ebaac387652b9f3ff263b96198a3679f Mon Sep 17 00:00:00 2001 From: Lungu Cristian Date: Wed, 30 Oct 2024 15:51:26 +0200 Subject: [PATCH] Fix "Failed to get dApps" error when a session expired (#21531) * fix: pass the topic instead of entire session * chore: added logs for future debugging --- .../wallet_connect/events/session_proposals.cljs | 1 + .../wallet/wallet_connect/utils/sessions.cljs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/status_im/contexts/wallet/wallet_connect/events/session_proposals.cljs b/src/status_im/contexts/wallet/wallet_connect/events/session_proposals.cljs index 30ea1e0591..2a35edd3a8 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events/session_proposals.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events/session_proposals.cljs @@ -142,6 +142,7 @@ (rf/reg-event-fx :wallet-connect/approve-session-success (fn [{:keys [db]} [session]] + (log/info "Successfully approved WalletConnect session" session) (let [total-connected-dapps (data-store/get-total-connected-dapps db)] {:fx [[:dispatch [:wallet-connect/on-new-session session]] [:dispatch [:wallet-connect/reset-current-session-proposal]] diff --git a/src/status_im/contexts/wallet/wallet_connect/utils/sessions.cljs b/src/status_im/contexts/wallet/wallet_connect/utils/sessions.cljs index 95f74afa62..07b99ca0aa 100644 --- a/src/status_im/contexts/wallet/wallet_connect/utils/sessions.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/utils/sessions.cljs @@ -54,6 +54,7 @@ (assoc session :accounts (-> sessionJson + transforms/json->clj :namespaces :eip155 :accounts))) @@ -93,10 +94,10 @@ (defn sync-persisted-sessions [active-sessions persisted-sessions] (-> (promesa/all - (for [topic (find-inactive-sessions active-sessions - persisted-sessions)] - (do (log/info "Syncing disconnected session with persistance" topic) - (rpc/wallet-disconnect-persisted-session topic)))) + (for [session (find-inactive-sessions active-sessions + persisted-sessions)] + (do (log/info "Syncing disconnected session with persistance" session) + (rpc/wallet-disconnect-persisted-session (:topic session))))) (promesa/catch (fn [err] (throw (ex-info "Failed to synchronize persisted sessions" {:error err @@ -107,7 +108,11 @@ (promesa/let [persisted-sessions (get-persisted-sessions)] (if online? (promesa/let [active-sessions (get-active-sessions web3-wallet addresses)] - (sync-persisted-sessions active-sessions persisted-sessions) + (log/info "Got active Wallet Connect sessions" (map :topic active-sessions)) + ;; NOTE: handling the error here, so that if persistance fails, it doesn't affect the active + ;; sessions + (-> (sync-persisted-sessions active-sessions persisted-sessions) + (promesa/catch #(log/error %))) active-sessions) persisted-sessions)))