Skip to content

Commit 76cd645

Browse files
Provide more precise data for age assurance (#8989)
1 parent 124cfb5 commit 76cd645

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/state/ageAssurance/useInitAgeAssurance.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import {isNetworkError} from '#/lib/hooks/useCleanError'
1515
import {logger} from '#/logger'
1616
import {createAgeAssuranceQueryKey} from '#/state/ageAssurance'
17-
import {useGeolocationStatus} from '#/state/geolocation'
17+
import {type DeviceLocation, useGeolocationStatus} from '#/state/geolocation'
1818
import {useAgent} from '#/state/session'
1919

2020
let APPVIEW = PUBLIC_APPVIEW
@@ -33,6 +33,22 @@ let APPVIEW_DID = PUBLIC_APPVIEW_DID
3333
// APPVIEW_DID = ``
3434
// }
3535

36+
/**
37+
* Creates an ISO country code string from the given geolocation data.
38+
* Examples: `GB` or `GB-ENG`
39+
*/
40+
function createISOCountryCode(
41+
geolocation: Omit<DeviceLocation, 'countryCode'> & {
42+
countryCode: string
43+
},
44+
): string {
45+
if (geolocation.regionCode) {
46+
return `${geolocation.countryCode}-${geolocation.regionCode}`.toUpperCase()
47+
} else {
48+
return geolocation.countryCode.toUpperCase()
49+
}
50+
}
51+
3652
export function useInitAgeAssurance() {
3753
const qc = useQueryClient()
3854
const agent = useAgent()
@@ -41,7 +57,9 @@ export function useInitAgeAssurance() {
4157
async mutationFn(
4258
props: Omit<AppBskyUnspeccedInitAgeAssurance.InputSchema, 'countryCode'>,
4359
) {
44-
if (!geolocation?.countryCode) {
60+
const countryCode = geolocation?.countryCode
61+
const regionCode = geolocation?.regionCode
62+
if (!countryCode) {
4563
throw new Error(`Geolocation not available, cannot init age assurance.`)
4664
}
4765

@@ -65,7 +83,10 @@ export function useInitAgeAssurance() {
6583
2e3,
6684
appView.app.bsky.unspecced.initAgeAssurance({
6785
...props,
68-
countryCode: geolocation?.countryCode?.toUpperCase(),
86+
countryCode: createISOCountryCode({
87+
countryCode,
88+
regionCode,
89+
}),
6990
}),
7091
)
7192

0 commit comments

Comments
 (0)