diff options
author | Eric Bailey <git@esb.lol> | 2025-09-05 10:02:24 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-05 10:02:24 -0500 |
commit | 76cd645a408c3a61feb71208a81f43a4f71190d2 (patch) | |
tree | 8d60cb5315cc9dd951cf3445a0e4b06cafaebba7 /src | |
parent | 124cfb57c7f794cb54da09ce05b7101767156e0a (diff) | |
download | voidsky-76cd645a408c3a61feb71208a81f43a4f71190d2.tar.zst |
Provide more precise data for age assurance (#8989)
Diffstat (limited to 'src')
-rw-r--r-- | src/state/ageAssurance/useInitAgeAssurance.ts | 27 |
1 files 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<DeviceLocation, 'countryCode'> & { + 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<AppBskyUnspeccedInitAgeAssurance.InputSchema, 'countryCode'>, ) { - 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, + }), }), ) |