···01import {type AppBskyAgeassuranceBegin, AtpAgent} from '@atproto/api'
2import {useMutation} from '@tanstack/react-query'
3···8 PUBLIC_APPVIEW_DID,
9} from '#/lib/constants'
10import {isNetworkError} from '#/lib/hooks/useCleanError'
11-import {logger} from '#/logger'
12import {useAgent} from '#/state/session'
13import {usePatchAgeAssuranceServerState} from '#/ageAssurance'
014import {BLUESKY_PROXY_DID} from '#/env'
15import {useGeolocation} from '#/geolocation'
16···29 'countryCode' | 'regionCode'
30 >,
31 ) {
32- const countryCode = geolocation?.countryCode
33- const regionCode = geolocation?.regionCode
34 if (!countryCode) {
35 throw new Error(`Geolocation not available, cannot init age assurance.`)
36 }
···47 appView.sessionManager.session.accessJwt = token
48 appView.sessionManager.session.refreshJwt = ''
49000000000050 /*
51 * 2s wait is good actually. Email sending takes a hot sec and this helps
52 * ensure the email is ready for the user once they open their inbox.
···55 2e3,
56 appView.app.bsky.ageassurance.begin({
57 ...props,
58- countryCode: countryCode.toUpperCase(),
59- regionCode: regionCode ? regionCode.toUpperCase() : undefined,
60 }),
61 )
62
···1+import {Platform} from 'react-native'
2import {type AppBskyAgeassuranceBegin, AtpAgent} from '@atproto/api'
3import {useMutation} from '@tanstack/react-query'
4···9 PUBLIC_APPVIEW_DID,
10} from '#/lib/constants'
11import {isNetworkError} from '#/lib/hooks/useCleanError'
012import {useAgent} from '#/state/session'
13import {usePatchAgeAssuranceServerState} from '#/ageAssurance'
14+import {logger} from '#/ageAssurance/logger'
15import {BLUESKY_PROXY_DID} from '#/env'
16import {useGeolocation} from '#/geolocation'
17···30 'countryCode' | 'regionCode'
31 >,
32 ) {
33+ const countryCode = geolocation?.countryCode?.toUpperCase()
34+ const regionCode = geolocation?.regionCode?.toUpperCase()
35 if (!countryCode) {
36 throw new Error(`Geolocation not available, cannot init age assurance.`)
37 }
···48 appView.sessionManager.session.accessJwt = token
49 appView.sessionManager.session.refreshJwt = ''
5051+ logger.metric(
52+ 'ageAssurance:api:begin',
53+ {
54+ platform: Platform.OS,
55+ countryCode,
56+ regionCode,
57+ },
58+ {statsig: false},
59+ )
60+61 /*
62 * 2s wait is good actually. Email sending takes a hot sec and this helps
63 * ensure the email is ready for the user once they open their inbox.
···66 2e3,
67 appView.app.bsky.ageassurance.begin({
68 ...props,
69+ countryCode,
70+ regionCode,
71 }),
72 )
73
+18-4
src/geolocation/util.ts
···1import {type LocationGeocodedAddress} from 'expo-location'
203import {logger} from '#/geolocation/logger'
4import {type Geolocation} from '#/geolocation/types'
5···75 location: LocationGeocodedAddress,
76): Geolocation {
77 let {isoCountryCode, region} = location
07879- if (region) {
80- if (isoCountryCode === 'US') {
81- region = USRegionNameToRegionCode[region] ?? region
00000000000082 }
83 }
8485 return {
86 countryCode: isoCountryCode ?? undefined,
87- regionCode: region ?? undefined,
88 }
89}
90
···1import {type LocationGeocodedAddress} from 'expo-location'
23+import {isAndroid} from '#/platform/detection'
4import {logger} from '#/geolocation/logger'
5import {type Geolocation} from '#/geolocation/types'
6···76 location: LocationGeocodedAddress,
77): Geolocation {
78 let {isoCountryCode, region} = location
79+ let regionCode: string | undefined = region ?? undefined
8081+ /*
82+ * Android doesn't give us ISO 3166-2 short codes. We need these for US
83+ */
84+ if (isAndroid) {
85+ if (region && isoCountryCode === 'US') {
86+ /*
87+ * We need short codes for US states. If we can't remap it, just drop it
88+ * entirely for now.
89+ */
90+ regionCode = USRegionNameToRegionCode[region] ?? undefined
91+ } else {
92+ /*
93+ * Outside the US, we don't need regionCodes for now, so just drop it.
94+ */
95+ regionCode = undefined
96 }
97 }
9899 return {
100 countryCode: isoCountryCode ?? undefined,
101+ regionCode,
102 }
103}
104