From d74edff9b9e2fcfc95ca40ca58d4f8764746f8ca Mon Sep 17 00:00:00 2001 From: Shivek Khurana Date: Thu, 11 Jul 2024 15:20:42 +0530 Subject: [PATCH] =?UTF-8?q?2=EF=B8=8F=E2=83=A3=20Use=20v2=20api=20for=20pe?= =?UTF-8?q?rsisting=20sessions=20(#20648)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 2️⃣ Use v2 api for persisting sessions * 🗑️ Remove traces of REPL and v2 suffix --------- Co-authored-by: Lungu Cristian --- .../wallet/wallet_connect/events.cljs | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/status_im/contexts/wallet/wallet_connect/events.cljs b/src/status_im/contexts/wallet/wallet_connect/events.cljs index e0697c97bc..250776568b 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events.cljs @@ -166,16 +166,10 @@ {:web3-wallet web3-wallet :proposal current-proposal :supported-namespaces supported-namespaces - :on-success (fn [] + :on-success (fn [approved-session] (log/info "Wallet Connect session approved") - (let [metadata (wallet-connect-core/get-session-dapp-metadata - current-proposal)] - (rf/dispatch [:wallet-connect/reset-current-session-proposal]) - (rf/dispatch [:wallet-connect/persist-session - {:id (:id current-proposal) - :dapp-name (:name metadata) - :dapp-url (:url metadata) - :session-info current-proposal}]))) + (rf/dispatch [:wallet-connect/reset-current-session-proposal]) + (rf/dispatch [:wallet-connect/persist-session approved-session])) :on-fail (fn [error] (log/error "Wallet Connect session approval failed" {:error error @@ -210,20 +204,6 @@ {:version version}))}]]]} {:fx [[:dispatch [:wallet-connect/pair scanned-text]]]})))) -(rf/reg-event-fx - :wallet-connect/persist-session - (fn [_ [{:keys [id dapp-name dapp-url session-info]}]] - {:fx [[:json-rpc/call - [{:method "wakuext_addWalletConnectSession" - :params [{:id (str id) - :dappName dapp-name - :dappUrl dapp-url - :info (-> session-info - clj->js - js/JSON.stringify)}] - :on-success #(log/info "Wallet Connect session persisted") - :on-error #(log/info "Wallet Connect session persistence failed" %)}]]]})) - (rf/reg-event-fx :wallet-connect/fetch-persisted-sessions-success (fn [{:keys [db]} [sessions]] @@ -233,6 +213,18 @@ :wallet-connect/fetch-persisted-sessions (fn [_ _] {:fx [[:json-rpc/call - [{:method "wakuext_getWalletConnectSession" + [{:method "wallet_getWalletConnectActiveSessions" + ;; This is the activeSince timestamp to avoid expired sessions + ;; 0 means, return everything + :params [0] :on-success [:wallet-connect/fetch-persisted-sessions-success] - :on-error #(log/info "Wallet Connect fetch persisted sessions failed")}]]]})) + :on-error #(log/info "Wallet Connect fetch persisted sessions failed" %)}]]]})) + +(rf/reg-event-fx + :wallet-connect/persist-session + (fn [_ [session-info]] + {:fx [[:json-rpc/call + [{:method "wallet_addWalletConnectSession" + :params [(js/JSON.stringify session-info)] + :on-success #(log/info "Wallet Connect session persisted") + :on-error #(log/info "Wallet Connect session persistence failed" %)}]]]}))