diff --git a/mobile-app/app/api/linking.ts b/mobile-app/app/api/linking.ts new file mode 100644 index 0000000000..d9805ec310 --- /dev/null +++ b/mobile-app/app/api/linking.ts @@ -0,0 +1,14 @@ +import { Platform } from 'react-native' +import * as Linking from 'expo-linking' +import * as WebBrowser from 'expo-web-browser' + +export async function openURL (url: string): Promise { + if (Platform.OS !== 'android') { + const supported = await Linking.canOpenURL(url) + if (supported) { + await Linking.openURL(url) + return + } + } + await WebBrowser.openBrowserAsync(url) +} diff --git a/mobile-app/app/components/OceanInterface/OceanInterface.tsx b/mobile-app/app/components/OceanInterface/OceanInterface.tsx index 9ae9a9817b..95f5e2965a 100644 --- a/mobile-app/app/components/OceanInterface/OceanInterface.tsx +++ b/mobile-app/app/components/OceanInterface/OceanInterface.tsx @@ -13,9 +13,10 @@ import { firstTransactionSelector, ocean, OceanTransaction } from '@store/ocean' import { tailwind } from '@tailwind' import { translate } from '@translations' import React, { useCallback, useEffect, useRef, useState } from 'react' -import { Animated, Linking, TouchableOpacity, View } from 'react-native' +import { Animated, TouchableOpacity, View } from 'react-native' import { useDispatch, useSelector } from 'react-redux' import { ThemedActivityIndicator, ThemedIcon, ThemedText } from '../themed' +import { openURL } from '@api/linking' const MAX_AUTO_RETRY = 1 const MAX_TIMEOUT = 300000 @@ -24,10 +25,7 @@ const INTERVAL_TIME = 5000 async function gotoExplorer (txUrl: string): Promise { // TODO(thedoublejay) explorer URL // TODO (future improvement): this page should support in mempool, to be confirm - const supported = await Linking.canOpenURL(txUrl) - if (supported) { - await Linking.openURL(txUrl) - } + await openURL(txUrl) } async function broadcastTransaction (tx: CTransactionSegWit, client: WhaleApiClient, retries: number = 0): Promise { diff --git a/mobile-app/app/screens/AppNavigator/screens/Settings/screens/AboutScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Settings/screens/AboutScreen.tsx index ac91c4395f..50b352033a 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Settings/screens/AboutScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Settings/screens/AboutScreen.tsx @@ -1,12 +1,13 @@ import { MaterialCommunityIcons } from '@expo/vector-icons' import { nativeApplicationVersion } from 'expo-application' import React from 'react' -import { Linking, TouchableOpacity, View } from 'react-native' +import { TouchableOpacity, View } from 'react-native' import { AppIcon } from '@components/icons/AppIcon' import { ThemedIcon, ThemedScrollView, ThemedText, ThemedTouchableOpacity } from '@components/themed' import { tailwind } from '@tailwind' import { translate } from '@translations' import { useNavigation } from '@react-navigation/native' +import { openURL } from '@api/linking' interface AboutScreenLinks { testID: string @@ -169,13 +170,6 @@ export function AboutScreen (): JSX.Element { ) } -async function openURL (url: string): Promise { - const supported = await Linking.canOpenURL(url) - if (supported) { - await Linking.openURL(url) - } -} - function LinkItemRow ({ title, subtitle, diff --git a/mobile-app/app/screens/AppNavigator/screens/Settings/screens/CommunityScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Settings/screens/CommunityScreen.tsx index d83c37ce3e..69d2c9392f 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Settings/screens/CommunityScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Settings/screens/CommunityScreen.tsx @@ -1,7 +1,6 @@ import { MaterialCommunityIcons } from '@expo/vector-icons' import * as React from 'react' -import { useCallback } from 'react' -import { Linking, View } from 'react-native' +import { View } from 'react-native' import { ThemedFlatList, ThemedIcon, @@ -12,6 +11,7 @@ import { } from '@components/themed' import { tailwind } from '@tailwind' import { translate } from '@translations' +import { openURL } from '@api/linking' export function CommunityScreen (): JSX.Element { return ( @@ -95,12 +95,9 @@ function CommunityItemRow ({ url, icon }: CommunityItem): JSX.Element { - const handlePress = useCallback(async () => { - const supported = await Linking.canOpenURL(url) - if (supported) { - await Linking.openURL(url) - } - }, [url]) + const handlePress = async (): Promise => { + await openURL(url) + } return (