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.
This commit is contained in:
Sean Hagstrom 2024-09-20 16:48:58 +01:00 committed by GitHub
parent a1404385d1
commit 0f20f07363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 6 deletions

View File

@ -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)]])

View File

@ -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

View File

@ -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

View File

@ -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]))))))

View File

@ -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)))))