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 61% rename from src/libs/asyncOpenURL/index.website.js rename to src/libs/asyncOpenURL/index.website.ts index e1c491450c18..d503644c1392 100644 --- a/src/libs/asyncOpenURL/index.website.js +++ b/src/libs/asyncOpenURL/index.website.ts @@ -1,13 +1,11 @@ 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. + * @param 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 +20,13 @@ export default function asyncOpenURL(promise, url, shouldSkipCustomSafariLogic) const windowRef = window.open(); promise .then((params) => { + if (!windowRef) { + return; + } windowRef.location = typeof url === 'string' ? url : url(params); }) - .catch(() => windowRef.close()); + .catch(() => windowRef?.close()); } -} +}; + +export default asyncOpenURL; 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;