Skip to content

Commit

Permalink
[#21853] fix: check deeplink pending request after wallet connect loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghafouri committed Jan 9, 2025
1 parent 7709634 commit 573f547
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
9 changes: 6 additions & 3 deletions src/status_im/contexts/wallet/wallet_connect/events/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
:wallet-connect/on-init-success
(fn [{:keys [db]} [web3-wallet]]
(log/info "WalletConnect SDK initialisation successful")
{:db (assoc db :wallet-connect/web3-wallet web3-wallet)
:fx [[:dispatch [:wallet-connect/register-event-listeners]]
[:dispatch [:wallet-connect/get-sessions]]]}))
(let [waiting-pair-url (get db :wallet-connect/waiting-pair-url)]
{:db (assoc db :wallet-connect/web3-wallet web3-wallet)
:fx [[:dispatch [:wallet-connect/register-event-listeners]]
[:dispatch [:wallet-connect/get-sessions]]
(when waiting-pair-url
[:dispatch [:wallet-connect/pair waiting-pair-url]])]})))

(rf/reg-event-fx
:wallet-connect/reload-on-network-change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
:wallet-connect/pair
(fn [{:keys [db]} [url]]
(let [web3-wallet (get db :wallet-connect/web3-wallet)]
{:fx [[:effects.wallet-connect/pair
{:web3-wallet web3-wallet
:url url
:on-fail #(log/error "Failed to pair with dApp" {:error %})
:on-success #(log/info "dApp paired successfully")}]]})))
(if web3-wallet
{:db (dissoc db :wallet-connect/waiting-pair-url)
:fx [[:effects.wallet-connect/pair
{:web3-wallet web3-wallet
:url url
:on-fail #(log/error "Failed to pair with dApp" {:error %})
:on-success #(log/info "dApp paired successfully")}]]}
{:db (assoc db :wallet-connect/waiting-pair-url url)}))))

(rf/reg-event-fx
:wallet-connect/on-scan-connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,23 @@
(get-in db [:wallet-connect/current-request :event]))]
(let [method (data-store/get-request-method event)
web3-wallet (get db :wallet-connect/web3-wallet)]
{:db (assoc-in db [:wallet-connect/current-request :response-sent?] true)
:fx [[:effects.wallet-connect/respond-session-request
{:web3-wallet web3-wallet
:topic topic
:id id
:result result
:error error
:on-error (fn [error]
(log/error "Failed to send Wallet Connect response"
{:error error
:method method
:event :wallet-connect/send-response
:wallet-connect-event event}))
:on-success (fn []
(rf/dispatch [:wallet-connect/redirect-to-dapp])
(log/info "Successfully sent Wallet Connect response to dApp"))}]]}))))
(when web3-wallet
{:db (assoc-in db [:wallet-connect/current-request :response-sent?] true)
:fx [[:effects.wallet-connect/respond-session-request
{:web3-wallet web3-wallet
:topic topic
:id id
:result result
:error error
:on-error (fn [error]
(log/error "Failed to send Wallet Connect response"
{:error error
:method method
:event :wallet-connect/send-response
:wallet-connect-event event}))
:on-success (fn []
(rf/dispatch [:wallet-connect/redirect-to-dapp])
(log/info "Successfully sent Wallet Connect response to dApp"))}]]})))))

(rf/reg-event-fx
:wallet-connect/redirect-to-dapp
Expand Down

0 comments on commit 573f547

Please sign in to comment.