From 0f20f07363552c82ad3e19f004635482cf2b2671 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Fri, 20 Sep 2024 16:48:58 +0100 Subject: [PATCH] chore: dispatch open-url event instead of calling function directly (#21246) This change adds a re-frame event for `:open-url` which will allow UI components to open a url using the re-frame effect `:effects/open-url`. Additionally, some code was refactored to use the `:open-url` event instead of directly opening the urls with the `open-url` function. --- .../contexts/wallet/sheets/account_origin/view.cljs | 5 +++-- src/status_im/contexts/wallet/sheets/buy_token/view.cljs | 3 ++- .../wallet/wallet_connect/events/session_responses.cljs | 2 +- .../wallet_connect/events/session_responses_test.cljs | 2 +- src/status_im/navigation/events.cljs | 6 +++++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/status_im/contexts/wallet/sheets/account_origin/view.cljs b/src/status_im/contexts/wallet/sheets/account_origin/view.cljs index b0626de2ae..0e09367986 100644 --- a/src/status_im/contexts/wallet/sheets/account_origin/view.cljs +++ b/src/status_im/contexts/wallet/sheets/account_origin/view.cljs @@ -5,7 +5,8 @@ [react-native.core :as rn] [status-im.constants :as const] [status-im.contexts.wallet.sheets.account-origin.style :as style] - [utils.i18n :as i18n])) + [utils.i18n :as i18n] + [utils.re-frame :as rf])) (defn- header [text] @@ -41,5 +42,5 @@ :size 24 :icon-left :i/info :container-style style/action-container - :on-press #(rn/open-url const/create-account-link)} + :on-press #(rf/dispatch [:open-url const/create-account-link])} (i18n/label :t/read-more)]]) diff --git a/src/status_im/contexts/wallet/sheets/buy_token/view.cljs b/src/status_im/contexts/wallet/sheets/buy_token/view.cljs index 8ec15f48ea..b5d00f1694 100644 --- a/src/status_im/contexts/wallet/sheets/buy_token/view.cljs +++ b/src/status_im/contexts/wallet/sheets/buy_token/view.cljs @@ -9,7 +9,8 @@ (defn- crypto-on-ramp-item [{:keys [name description fees logo-url site-url recurrent-site-url]} _ _ {:keys [tab]}] (let [open-url (rn/use-callback (fn [] - (rn/open-url (if (= tab :recurrent) recurrent-site-url site-url))) + (rf/dispatch [:open-url + (if (= tab :recurrent) recurrent-site-url site-url)])) [site-url recurrent-site-url tab])] [quo/settings-item {:title name diff --git a/src/status_im/contexts/wallet/wallet_connect/events/session_responses.cljs b/src/status_im/contexts/wallet/wallet_connect/events/session_responses.cljs index 29f4a467f7..31ad394a4b 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events/session_responses.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events/session_responses.cljs @@ -148,7 +148,7 @@ :sessionJson transforms/json->clj data-store/get-dapp-redirect-url))] - {:fx [[:open-url redirect-url]]}))) + {:fx [[:effects/open-url redirect-url]]}))) (rf/reg-event-fx :wallet-connect/dismiss-request-modal diff --git a/src/status_im/contexts/wallet/wallet_connect/events/session_responses_test.cljs b/src/status_im/contexts/wallet/wallet_connect/events/session_responses_test.cljs index e25ecd643b..4c390ed5bc 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events/session_responses_test.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events/session_responses_test.cljs @@ -23,5 +23,5 @@ data-store/get-dapp-redirect-url (fn [_] "native://redirect-url")] - (is (match? {:fx [[:open-url "native://redirect-url"]]} + (is (match? {:fx [[:effects/open-url "native://redirect-url"]]} (dispatch [event-id])))))) diff --git a/src/status_im/navigation/events.cljs b/src/status_im/navigation/events.cljs index 3aff05c62c..55fa4ea746 100644 --- a/src/status_im/navigation/events.cljs +++ b/src/status_im/navigation/events.cljs @@ -146,8 +146,12 @@ (rf/reg-event-fx :open-share open-share) +(rf/reg-event-fx :open-url + (fn [_ [url]] + {:fx [[:effects/open-url url]]})) + (rf/reg-fx - :open-url + :effects/open-url (fn [url] (when (not (string/blank? url)) (.openURL ^js react/linking (url/normalize-url url)))))