From 0993936da3130ec3928df7c619a05374bd8a0a4c Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Wed, 6 Sep 2023 17:10:31 +0200 Subject: [PATCH 1/5] Add AsyncOpenURL type --- src/libs/asyncOpenURL/types.ts | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/libs/asyncOpenURL/types.ts diff --git a/src/libs/asyncOpenURL/types.ts b/src/libs/asyncOpenURL/types.ts new file mode 100644 index 000000000000..bf24756b0cc2 --- /dev/null +++ b/src/libs/asyncOpenURL/types.ts @@ -0,0 +1,3 @@ +type AsyncOpenURL = (promise: Promise, url: string | ((params: T) => string), shouldSkipCustomSafariLogic?: boolean) => void; + +export default AsyncOpenURL; From 26292e08f19c4ad00834411e3af57505d5e4979b Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Wed, 6 Sep 2023 17:10:54 +0200 Subject: [PATCH 2/5] Migrate asyncOpenURL to typescript --- src/libs/asyncOpenURL/{index.js => index.ts} | 7 +++++-- .../{index.website.js => index.website.ts} | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) rename src/libs/asyncOpenURL/{index.js => index.ts} (60%) rename src/libs/asyncOpenURL/{index.website.js => index.website.ts} (58%) diff --git a/src/libs/asyncOpenURL/index.js b/src/libs/asyncOpenURL/index.ts similarity index 60% rename from src/libs/asyncOpenURL/index.js rename to src/libs/asyncOpenURL/index.ts index e69777c5483c..5307049ee923 100644 --- a/src/libs/asyncOpenURL/index.js +++ b/src/libs/asyncOpenURL/index.ts @@ -1,6 +1,7 @@ import {Linking} from 'react-native'; +import AsyncOpenURL from './types'; -export default function asyncOpenURL(promise, url) { +const asyncOpenURL: AsyncOpenURL = (promise, url) => { if (!url) { return; } @@ -8,4 +9,6 @@ export default function asyncOpenURL(promise, url) { promise.then((params) => { Linking.openURL(typeof url === 'string' ? url : url(params)); }); -} +}; + +export default asyncOpenURL; diff --git a/src/libs/asyncOpenURL/index.website.js b/src/libs/asyncOpenURL/index.website.ts similarity index 58% rename from src/libs/asyncOpenURL/index.website.js rename to src/libs/asyncOpenURL/index.website.ts index e1c491450c18..371cdd21cc7a 100644 --- a/src/libs/asyncOpenURL/index.website.js +++ b/src/libs/asyncOpenURL/index.website.ts @@ -1,13 +1,10 @@ import {Linking} from 'react-native'; +import AsyncOpenURL from './types'; /** * Prevents Safari from blocking pop-up window when opened within async call. - * - * @param {Promise} promise - * @param {string} url - * @param {Boolean} shouldSkipCustomSafariLogic When true, we will use `Linking.openURL` even if the browser is Safari. */ -export default function asyncOpenURL(promise, url, shouldSkipCustomSafariLogic) { +const asyncOpenURL: AsyncOpenURL = (promise, url, shouldSkipCustomSafariLogic) => { if (!url) { return; } @@ -22,8 +19,13 @@ export default function asyncOpenURL(promise, url, shouldSkipCustomSafariLogic) const windowRef = window.open(); promise .then((params) => { - windowRef.location = typeof url === 'string' ? url : url(params); + if (!windowRef) { + return; + } + windowRef.location.href = typeof url === 'string' ? url : url(params); }) - .catch(() => windowRef.close()); + .catch(() => windowRef?.close()); } -} +}; + +export default asyncOpenURL; From 50c4673b477709ff6927c45503829073f356a875 Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Thu, 7 Sep 2023 10:19:40 +0200 Subject: [PATCH 3/5] Add add param description --- src/libs/asyncOpenURL/index.website.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/asyncOpenURL/index.website.ts b/src/libs/asyncOpenURL/index.website.ts index 371cdd21cc7a..8da4c6456273 100644 --- a/src/libs/asyncOpenURL/index.website.ts +++ b/src/libs/asyncOpenURL/index.website.ts @@ -3,6 +3,7 @@ import AsyncOpenURL from './types'; /** * Prevents Safari from blocking pop-up window when opened within async call. + * * @param shouldSkipCustomSafariLogic When true, we will use `Linking.openURL` even if the browser is Safari. */ const asyncOpenURL: AsyncOpenURL = (promise, url, shouldSkipCustomSafariLogic) => { if (!url) { From d4093443ec7f769eddf9b0a14f8bb6ed3b838452 Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Wed, 13 Sep 2023 16:47:13 +0200 Subject: [PATCH 4/5] Revert --- src/libs/asyncOpenURL/index.website.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/asyncOpenURL/index.website.ts b/src/libs/asyncOpenURL/index.website.ts index 8da4c6456273..ddbdfc84bc4d 100644 --- a/src/libs/asyncOpenURL/index.website.ts +++ b/src/libs/asyncOpenURL/index.website.ts @@ -23,7 +23,7 @@ const asyncOpenURL: AsyncOpenURL = (promise, url, shouldSkipCustomSafariLogic) = if (!windowRef) { return; } - windowRef.location.href = typeof url === 'string' ? url : url(params); + windowRef.location = typeof url === 'string' ? url : url(params); }) .catch(() => windowRef?.close()); } From 39fe27981b5b8a662f2feff7876bf9e21d9957ad Mon Sep 17 00:00:00 2001 From: Kamil Owczarz <91068263+kowczarz@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:42:12 +0200 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Nikki Wines --- src/libs/asyncOpenURL/index.website.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/asyncOpenURL/index.website.ts b/src/libs/asyncOpenURL/index.website.ts index ddbdfc84bc4d..d503644c1392 100644 --- a/src/libs/asyncOpenURL/index.website.ts +++ b/src/libs/asyncOpenURL/index.website.ts @@ -3,7 +3,7 @@ import AsyncOpenURL from './types'; /** * Prevents Safari from blocking pop-up window when opened within async call. - * * @param shouldSkipCustomSafariLogic When true, we will use `Linking.openURL` even if the browser is Safari. + * @param shouldSkipCustomSafariLogic When true, we will use `Linking.openURL` even if the browser is Safari. */ const asyncOpenURL: AsyncOpenURL = (promise, url, shouldSkipCustomSafariLogic) => { if (!url) {