Skip to content

Commit

Permalink
[#21853] fix: isolate the usage of pending deeplink url
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghafouri committed Jan 3, 2025
1 parent 62c396d commit 1c22eb2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/status_im/common/universal_links.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@
(rf/defn handle-wallet-connect
[_ uri]
(log/info "universal-links: handle-wallet-connect" uri)
{:dispatch-later {:ms 1500
:dispatch [:wallet-connect/on-scan-connection uri]}})
{:dispatch [:wallet-connect/process-deeplink uri]})

(defn dispatch-url
"Dispatch url so we can get access to re-frame/db"
Expand Down
10 changes: 4 additions & 6 deletions src/status_im/contexts/wallet/wallet_connect/events/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@
:wallet-connect/on-init-success
(fn [{:keys [db]} [web3-wallet]]
(log/info "WalletConnect SDK initialisation successful")
(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]])]})))
{:db (assoc db :wallet-connect/web3-wallet web3-wallet)
:fx [[:dispatch [:wallet-connect/register-event-listeners]]
[:dispatch [:wallet-connect/get-sessions]]
[:dispatch [:wallet-connect/pair-with-pending-deeplink]]]}))

(rf/reg-event-fx
:wallet-connect/reload-on-network-change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,28 @@

(rf/reg-event-fx
: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")}]]})))

(rf/reg-event-fx
:wallet-connect/process-deeplink
(fn [{:keys [db]} [url]]
(let [web3-wallet (get db :wallet-connect/web3-wallet)]
(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)}))))
{:fx [[:dispatch [:wallet-connect/on-scan-connection url]]]}
{:db (assoc db :wallet-connect/pending-url url)}))))

(rf/reg-event-fx
:wallet-connect/pair-with-pending-deeplink
(fn [{:keys [db]}]
(when-let [pending-url (get db :wallet-connect/pending-url)]
{:db (dissoc db :wallet-connect/pending-url)
:fx [[:dispatch [:wallet-connect/on-scan-connection pending-url]]]})))

(rf/reg-event-fx
:wallet-connect/on-scan-connection
Expand Down

0 comments on commit 1c22eb2

Please sign in to comment.