From 76cd645a408c3a61feb71208a81f43a4f71190d2 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 5 Sep 2025 10:02:24 -0500 Subject: Provide more precise data for age assurance (#8989) --- src/state/ageAssurance/useInitAgeAssurance.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/state/ageAssurance/useInitAgeAssurance.ts b/src/state/ageAssurance/useInitAgeAssurance.ts index c8aaf70a3..59a0fb79b 100644 --- a/src/state/ageAssurance/useInitAgeAssurance.ts +++ b/src/state/ageAssurance/useInitAgeAssurance.ts @@ -14,7 +14,7 @@ import { import {isNetworkError} from '#/lib/hooks/useCleanError' import {logger} from '#/logger' import {createAgeAssuranceQueryKey} from '#/state/ageAssurance' -import {useGeolocationStatus} from '#/state/geolocation' +import {type DeviceLocation, useGeolocationStatus} from '#/state/geolocation' import {useAgent} from '#/state/session' let APPVIEW = PUBLIC_APPVIEW @@ -33,6 +33,22 @@ let APPVIEW_DID = PUBLIC_APPVIEW_DID // APPVIEW_DID = `` // } +/** + * Creates an ISO country code string from the given geolocation data. + * Examples: `GB` or `GB-ENG` + */ +function createISOCountryCode( + geolocation: Omit & { + countryCode: string + }, +): string { + if (geolocation.regionCode) { + return `${geolocation.countryCode}-${geolocation.regionCode}`.toUpperCase() + } else { + return geolocation.countryCode.toUpperCase() + } +} + export function useInitAgeAssurance() { const qc = useQueryClient() const agent = useAgent() @@ -41,7 +57,9 @@ export function useInitAgeAssurance() { async mutationFn( props: Omit, ) { - if (!geolocation?.countryCode) { + const countryCode = geolocation?.countryCode + const regionCode = geolocation?.regionCode + if (!countryCode) { throw new Error(`Geolocation not available, cannot init age assurance.`) } @@ -65,7 +83,10 @@ export function useInitAgeAssurance() { 2e3, appView.app.bsky.unspecced.initAgeAssurance({ ...props, - countryCode: geolocation?.countryCode?.toUpperCase(), + countryCode: createISOCountryCode({ + countryCode, + regionCode, + }), }), ) -- cgit 1.4.1