Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#21853] fix: check deeplink pending request after wallet connect loaded #21873

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/react_native/wallet_connect.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@
event
#(-> (bean/->clj %)
handler)))

(defn unregister-handler
[{:keys [web3-wallet event handler]}]
(oops/ocall web3-wallet
"off"
event
#(-> (bean/->clj %)
handler)))
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
1 change: 1 addition & 0 deletions src/status_im/contexts/profile/logout/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
{:db (assoc db :profile/logging-out? true)
;; We need to disable notifications before starting the logout process
:fx [[:dispatch [:profile.logout/disable-notifications]]
[:dispatch [:wallet-connect/unregister-event-listeners]]
[:dispatch-later
{:ms 100
:dispatch [:profile.logout/reset-state]}]]}))
39 changes: 35 additions & 4 deletions src/status_im/contexts/wallet/wallet_connect/events/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
(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]]]}))
[:dispatch [:wallet-connect/get-sessions]]
[:dispatch [:wallet-connect/pair-with-pending-deeplink]]]}))

(rf/reg-event-fx
:wallet-connect/reload-on-network-change
Expand All @@ -40,22 +41,52 @@
(log/info "Re-Initialising WalletConnect SDK due to network change")
{:fx [[:dispatch [:wallet-connect/init]]]}))))

(defn- on-session-proposal
[data]
(rf/dispatch [:wallet-connect/on-session-proposal data]))

(defn- on-session-request
[data]
(rf/dispatch [:wallet-connect/on-session-request data]))

(defn- on-session-delete
[data]
(rf/dispatch [:wallet-connect/on-session-delete data]))


(rf/reg-event-fx
:wallet-connect/register-event-listeners
(fn [{:keys [db]}]
(let [web3-wallet (get db :wallet-connect/web3-wallet)]
{:fx [[:effects.wallet-connect/register-event-listener
[web3-wallet
constants/wallet-connect-session-proposal-event
#(rf/dispatch [:wallet-connect/on-session-proposal %])]]
on-session-proposal]]
[:effects.wallet-connect/register-event-listener
[web3-wallet
constants/wallet-connect-session-request-event
#(rf/dispatch [:wallet-connect/on-session-request %])]]
on-session-request]]
[:effects.wallet-connect/register-event-listener
[web3-wallet
constants/wallet-connect-session-delete-event
#(rf/dispatch [:wallet-connect/on-session-delete %])]]]})))
on-session-delete]]]})))

(rf/reg-event-fx
:wallet-connect/unregister-event-listeners
(fn [{:keys [db]}]
(let [web3-wallet (get db :wallet-connect/web3-wallet)]
{:fx [[:effects.wallet-connect/unregister-event-listener
[web3-wallet
constants/wallet-connect-session-proposal-event
on-session-proposal]]
[:effects.wallet-connect/unregister-event-listener
[web3-wallet
constants/wallet-connect-session-request-event
on-session-request]]
[:effects.wallet-connect/unregister-event-listener
[web3-wallet
constants/wallet-connect-session-delete-event
on-session-delete]]]})))

(rf/reg-event-fx
:wallet-connect/on-init-fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
:event wc-event
:handler handler})))

(rf/reg-fx
:effects.wallet-connect/unregister-event-listener
(fn [[web3-wallet wc-event handler]]
(wallet-connect/unregister-handler
{:web3-wallet web3-wallet
:event wc-event
:handler handler})))

(rf/reg-fx
:effects.wallet-connect/pair
(fn [{:keys [web3-wallet url on-success on-fail]}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
: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
{: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
(fn [{:keys [db]} [scanned-text]]
Expand Down