From 9b5be84c5a6eb5b1e8bb7428dc13e60185eaa07b Mon Sep 17 00:00:00 2001 From: Spence Pope Date: Mon, 11 May 2026 08:27:24 -0400 Subject: [PATCH] Add region notice to age assurance card (#10439) --- .../ageAssurance/AgeAssuranceAccountCard.tsx | 163 ++++++++++++------ 1 file changed, 111 insertions(+), 52 deletions(-) diff --git a/src/components/ageAssurance/AgeAssuranceAccountCard.tsx b/src/components/ageAssurance/AgeAssuranceAccountCard.tsx index 09dc1e976e..4885ce3a1e 100644 --- a/src/components/ageAssurance/AgeAssuranceAccountCard.tsx +++ b/src/components/ageAssurance/AgeAssuranceAccountCard.tsx @@ -1,9 +1,8 @@ import {View} from 'react-native' -import {msg} from '@lingui/core/macro' -import {useLingui} from '@lingui/react' -import {Trans} from '@lingui/react/macro' +import {Trans, useLingui} from '@lingui/react/macro' import {dateDiff, useGetTimeAgo} from '#/lib/hooks/useTimeAgo' +import {regionName} from '#/locale/helpers' import {atoms as a, useBreakpoints, useTheme, type ViewStyleProp} from '#/alf' import {Admonition} from '#/components/Admonition' import {AgeAssuranceAppealDialog} from '#/components/ageAssurance/AgeAssuranceAppealDialog' @@ -25,7 +24,38 @@ import {useAgeAssurance} from '#/ageAssurance' import {useComputeAgeAssuranceRegionAccess} from '#/ageAssurance/useComputeAgeAssuranceRegionAccess' import {useAnalytics} from '#/analytics' import {IS_NATIVE} from '#/env' -import {useDeviceGeolocationApi} from '#/geolocation' +import { + type Geolocation, + useDeviceGeolocationApi, + useGeolocation, +} from '#/geolocation' +import {USRegionNameToRegionCode} from '#/geolocation/util' +import {device, useStorage} from '#/storage' + +const USRegionCodeToRegionName: {[regionCode: string]: string} = + Object.fromEntries( + Object.entries(USRegionNameToRegionCode).map(([name, code]) => [ + code, + name, + ]), + ) + +function formatRegion( + geolocation: Geolocation, + appLang: string, +): string | undefined { + const {countryCode, regionCode} = geolocation + if (!countryCode) return undefined + const country = regionName(countryCode, appLang) + // If `regionName` couldn't resolve a real name and fell through to the raw + // code, we'd rather show nothing than a bare ISO code in the prose. + if (country === countryCode) return undefined + if (regionCode && countryCode === 'US') { + const state = USRegionCodeToRegionName[regionCode] + if (state) return `${state}, ${country}` + } + return country +} export function AgeAssuranceAccountCard({style}: ViewStyleProp & {}) { const aa = useAgeAssurance() @@ -42,15 +72,12 @@ export function AgeAssuranceAccountCard({style}: ViewStyleProp & {}) { function Inner({style}: ViewStyleProp & {}) { const t = useTheme() - const {_, i18n} = useLingui() + const {t: l, i18n} = useLingui() const ax = useAnalytics() const control = useDialogControl() const appealControl = Dialog.useDialogControl() - const locationControl = Dialog.useDialogControl() const getTimeAgo = useGetTimeAgo() const {gtPhone} = useBreakpoints() - const {setDeviceGeolocation} = useDeviceGeolocationApi() - const computeAgeAssuranceRegionAccess = useComputeAgeAssuranceRegionAccess() const copy = useAgeAssuranceCopy() const aa = useAgeAssurance() @@ -97,7 +124,7 @@ function Inner({style}: ViewStyleProp & {}) { if one is available in your region. If you have questions or concerns,{' '} { appealControl.open() })}> @@ -107,47 +134,7 @@ function Inner({style}: ViewStyleProp & {}) { )} - {IS_NATIVE && ( - <> - - - Is your location not accurate?{' '} - { - locationControl.open() - })}> - Tap here to confirm your location. - {' '} - - - - { - const access = computeAgeAssuranceRegionAccess( - props.geolocation, - ) - if (access !== aa.Access.Full) { - props.disableDialogAction() - props.setDialogError( - _( - msg`We're sorry, but based on your device's location, you are currently located in a region that requires age assurance.`, - ), - ) - } else { - props.closeDialog(() => { - // set this after close! - setDeviceGeolocation(props.geolocation) - Toast.show(_(msg`Thanks! You're all set.`), { - type: 'success', - }) - }) - } - }} - /> - - )} + {isBlocked ? ( @@ -156,7 +143,7 @@ function Inner({style}: ViewStyleProp & {}) { You are currently unable to access Bluesky's Age Assurance flow. Please{' '} { appealControl.open() ax.metric('ageAssurance:appealDialogOpen', {}) @@ -182,7 +169,7 @@ function Inner({style}: ViewStyleProp & {}) { : [a.gap_md], ]}>