From bb71d5ebdbecd417b9d09353e8e1593858a1c08c Mon Sep 17 00:00:00 2001 From: Ajay Sivan Date: Mon, 15 Jul 2024 16:53:39 +0530 Subject: [PATCH] open url refactor --- .../contexts/wallet/sheets/buy_token/view.cljs | 3 ++- src/status_im/navigation/effects.cljs | 11 ++++++++++- src/status_im/navigation/events.cljs | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) 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/navigation/effects.cljs b/src/status_im/navigation/effects.cljs index b0b9079e7a..dfd46ea27e 100644 --- a/src/status_im/navigation/effects.cljs +++ b/src/status_im/navigation/effects.cljs @@ -12,7 +12,16 @@ [status-im.navigation.state :as state] [status-im.navigation.view :as views] [taoensso.timbre :as log] - [utils.re-frame :as rf])) + [utils.re-frame :as rf] + [clojure.string :as string] + [react-native.core :as react] + [utils.url :as url])) + +(rf/reg-fx + :open-url + (fn [url] + (when (not (string/blank? url)) + (.openURL ^js react/linking (url/normalize-url url))))) (defn get-status-nav-color [view-id theme] diff --git a/src/status_im/navigation/events.cljs b/src/status_im/navigation/events.cljs index 50ca682e69..7252c7f1c0 100644 --- a/src/status_im/navigation/events.cljs +++ b/src/status_im/navigation/events.cljs @@ -135,3 +135,7 @@ {:fx [[:effects.share/open config]]}) (rf/reg-event-fx :open-share open-share) + +(rf/reg-event-fx :open-url + (fn [_ [url]] + {:fx [[:open-url url]]}))