@@ -14,7 +14,7 @@ import {
14
14
import { isNetworkError } from '#/lib/hooks/useCleanError'
15
15
import { logger } from '#/logger'
16
16
import { createAgeAssuranceQueryKey } from '#/state/ageAssurance'
17
- import { useGeolocationStatus } from '#/state/geolocation'
17
+ import { type DeviceLocation , useGeolocationStatus } from '#/state/geolocation'
18
18
import { useAgent } from '#/state/session'
19
19
20
20
let APPVIEW = PUBLIC_APPVIEW
@@ -33,6 +33,22 @@ let APPVIEW_DID = PUBLIC_APPVIEW_DID
33
33
// APPVIEW_DID = ``
34
34
// }
35
35
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
+
36
52
export function useInitAgeAssurance ( ) {
37
53
const qc = useQueryClient ( )
38
54
const agent = useAgent ( )
@@ -41,7 +57,9 @@ export function useInitAgeAssurance() {
41
57
async mutationFn (
42
58
props : Omit < AppBskyUnspeccedInitAgeAssurance . InputSchema , 'countryCode' > ,
43
59
) {
44
- if ( ! geolocation ?. countryCode ) {
60
+ const countryCode = geolocation ?. countryCode
61
+ const regionCode = geolocation ?. regionCode
62
+ if ( ! countryCode ) {
45
63
throw new Error ( `Geolocation not available, cannot init age assurance.` )
46
64
}
47
65
@@ -65,7 +83,10 @@ export function useInitAgeAssurance() {
65
83
2e3 ,
66
84
appView . app . bsky . unspecced . initAgeAssurance ( {
67
85
...props ,
68
- countryCode : geolocation ?. countryCode ?. toUpperCase ( ) ,
86
+ countryCode : createISOCountryCode ( {
87
+ countryCode,
88
+ regionCode,
89
+ } ) ,
69
90
} ) ,
70
91
)
71
92
0 commit comments