Skip to content

Commit

Permalink
fix: addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
clauxx committed May 8, 2024
1 parent c409af8 commit 4e2f105
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
22 changes: 10 additions & 12 deletions src/status_im/contexts/wallet/wallet_connect/effects.cljs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
(ns status-im.contexts.wallet.wallet-connect.effects
(:require [re-frame.core :as rf]
[status-im.contexts.wallet.wallet-connect.utils :as wallet-connect.utils]
[taoensso.timbre :as log]))
(:require [promesa.core :as promesa]
[re-frame.core :as rf]
[status-im.contexts.wallet.wallet-connect.utils :as wallet-connect.utils]))

(rf/reg-fx
:effects.wallet-connect/init
(fn [{:keys [on-success on-fail]}]
(-> (wallet-connect.utils/init)
(.then on-success)
(.catch on-fail))))
(promesa/then on-success)
(promesa/catch on-fail))))

(rf/reg-fx
:effects.wallet-connect/register-event-listener
Expand All @@ -25,19 +25,17 @@
(fn [{:keys [web3-wallet url on-success on-fail]}]
(-> (.. web3-wallet -core -pairing)
(.pair (clj->js {:uri url}))
(.then on-success)
(.catch on-fail))))
(promesa/then on-success)
(promesa/catch on-fail))))

(rf/reg-fx
:effects.wallet-connect/approve-session
(fn [{:keys [web3-wallet proposal supported-namespaces]}]
(fn [{:keys [web3-wallet proposal supported-namespaces on-success on-fail]}]
(let [{:keys [params id]} proposal
approved-namespaces (wallet-connect.utils/build-approved-namespaces params
supported-namespaces)]
(-> (.approveSession web3-wallet
(clj->js {:id id
:namespaces approved-namespaces}))
(.then #(log/info "Wallet Connect session approved"))
(.catch #(log/error "Wallet Connect session approve failed"
{:error %
:event :effects.wallet-connect/approve-session}))))))
(promesa/then on-success)
(promesa/catch on-fail)))))
20 changes: 19 additions & 1 deletion src/status_im/contexts/wallet/wallet_connect/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
(fn [{:keys [db]} [proposal]]
{:db (assoc db :wallet-connect/current-proposal proposal)}))

(rf/reg-event-fx
:wallet-connect/reset-current-session
(fn [{:keys [db]}]
{:db (dissoc db :wallet-connect/current-proposal)}))

(rf/reg-event-fx
:wallet-connect/pair
(fn [{:keys [db]} [url]]
Expand All @@ -57,6 +62,11 @@
web3-wallet (get db :wallet-connect/web3-wallet)
current-proposal (get db :wallet-connect/current-proposal)
accounts (get-in db [:wallet :accounts])
;; NOTE: for now using the first account, but should be using the account selected by the
;; user on the connection screen. The default would depend on where the connection started
;; from:
;; - global scanner -> first account in list
;; - wallet account dapps -> account that is selected
address (-> accounts keys first)
formatted-address (wallet-connect.utils/format-address (first crosschain-ids)
address)
Expand All @@ -68,4 +78,12 @@
{:fx [[:effects.wallet-connect/approve-session
{:web3-wallet web3-wallet
:proposal current-proposal
:supported-namespaces supported-namespaces}]]})))
:supported-namespaces supported-namespaces
:on-success (fn []
(log/debug "Wallet Connect session approved")
(rf/dispatch [:wallet-connect/reset-current-session]))
:on-fail (fn [error]
(log/error "Wallet Connect session approval failed"
{:error error
:event :wallet-connect/approve-session})
(rf/dispatch [:wallet-connect/reset-current-session]))}]]})))

0 comments on commit 4e2f105

Please sign in to comment.