diff --git a/src/components/contacts/country-whitelist.ts b/src/components/contacts/country-whitelist.ts new file mode 100644 index 0000000000..41d6650cd6 --- /dev/null +++ b/src/components/contacts/country-whitelist.ts @@ -0,0 +1,37 @@ +import {type CountryCode} from '#/lib/international-telephone-codes' +import {IS_DEV} from '#/env' +import {useGeolocation} from '#/geolocation' + +const FIND_CONTACTS_FEATURE_COUNTRY_WHITELIST = [ + 'US', + 'GB', + 'JP', + 'CA', + 'DE', + 'FR', + 'ES', + 'BR', + 'KR', + 'NL', + 'AU', + 'SE', + 'IT', +] satisfies CountryCode[] as string[] + +export function isFindContactsFeatureEnabled(countryCode: string): boolean { + return FIND_CONTACTS_FEATURE_COUNTRY_WHITELIST.includes( + countryCode.toUpperCase(), + ) +} + +export function useIsFindContactsFeatureEnabledBasedOnGeolocation() { + const location = useGeolocation() + + if (IS_DEV) return true + + // they can try, by they'll need a phone number + // from one of the whitelisted countries + if (!location.countryCode) return true + + return isFindContactsFeatureEnabled(location.countryCode) +} diff --git a/src/components/contacts/screens/PhoneInput.tsx b/src/components/contacts/screens/PhoneInput.tsx index 83e533b1de..1c5db5fe18 100644 --- a/src/components/contacts/screens/PhoneInput.tsx +++ b/src/components/contacts/screens/PhoneInput.tsx @@ -21,6 +21,7 @@ import {InlineLinkText} from '#/components/Link' import {Loader} from '#/components/Loader' import {Text} from '#/components/Typography' import {useGeolocation} from '#/geolocation' +import {isFindContactsFeatureEnabled} from '../country-whitelist' import { getCountryCodeFromPastedNumber, processPhoneNumber, @@ -87,7 +88,10 @@ export function PhoneInput({ }, }) + const isFeatureEnabled = isFindContactsFeatureEnabled(countryCode) + const onSubmitNumber = () => { + if (!isFeatureEnabled) return const result = processPhoneNumber(phoneNumber, countryCode) if (result.valid) { setPhoneNumber(result.formatted) @@ -150,7 +154,7 @@ export function PhoneInput({ /> - + + {!isFeatureEnabled && ( + + + Support for this feature in your country has not been enabled yet! + Please check back later. + + + )} {error && {error}} {formatError && {formatError}} @@ -248,7 +260,7 @@ function LegalDisclaimer() { ) } -function ErrorText({children}: {children: string}) { +function ErrorText({children}: {children: React.ReactNode}) { const t = useTheme() return ( @@ -208,7 +211,7 @@ export function SettingsScreen({}: Props) { Content and media - {isNative && ( + {isNative && findContactsEnabled && (