[AAv2] Drop regionCode if we can't get a short code on Android (#9542)
* Drop regionCode if we can't get a short code on Android
* Add a debug metric
(cherry picked from commit 8d5b1c83cc)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import {Platform} from 'react-native'
|
||||||
import {type AppBskyAgeassuranceBegin, AtpAgent} from '@atproto/api'
|
import {type AppBskyAgeassuranceBegin, AtpAgent} from '@atproto/api'
|
||||||
import {useMutation} from '@tanstack/react-query'
|
import {useMutation} from '@tanstack/react-query'
|
||||||
|
|
||||||
@@ -8,9 +9,9 @@ import {
|
|||||||
PUBLIC_APPVIEW_DID,
|
PUBLIC_APPVIEW_DID,
|
||||||
} from '#/lib/constants'
|
} from '#/lib/constants'
|
||||||
import {isNetworkError} from '#/lib/hooks/useCleanError'
|
import {isNetworkError} from '#/lib/hooks/useCleanError'
|
||||||
import {logger} from '#/logger'
|
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
import {usePatchAgeAssuranceServerState} from '#/ageAssurance'
|
import {usePatchAgeAssuranceServerState} from '#/ageAssurance'
|
||||||
|
import {logger} from '#/ageAssurance/logger'
|
||||||
import {BLUESKY_PROXY_DID} from '#/env'
|
import {BLUESKY_PROXY_DID} from '#/env'
|
||||||
import {useGeolocation} from '#/geolocation'
|
import {useGeolocation} from '#/geolocation'
|
||||||
|
|
||||||
@@ -29,8 +30,8 @@ export function useBeginAgeAssurance() {
|
|||||||
'countryCode' | 'regionCode'
|
'countryCode' | 'regionCode'
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
const countryCode = geolocation?.countryCode
|
const countryCode = geolocation?.countryCode?.toUpperCase()
|
||||||
const regionCode = geolocation?.regionCode
|
const regionCode = geolocation?.regionCode?.toUpperCase()
|
||||||
if (!countryCode) {
|
if (!countryCode) {
|
||||||
throw new Error(`Geolocation not available, cannot init age assurance.`)
|
throw new Error(`Geolocation not available, cannot init age assurance.`)
|
||||||
}
|
}
|
||||||
@@ -47,6 +48,16 @@ export function useBeginAgeAssurance() {
|
|||||||
appView.sessionManager.session.accessJwt = token
|
appView.sessionManager.session.accessJwt = token
|
||||||
appView.sessionManager.session.refreshJwt = ''
|
appView.sessionManager.session.refreshJwt = ''
|
||||||
|
|
||||||
|
logger.metric(
|
||||||
|
'ageAssurance:api:begin',
|
||||||
|
{
|
||||||
|
platform: Platform.OS,
|
||||||
|
countryCode,
|
||||||
|
regionCode,
|
||||||
|
},
|
||||||
|
{statsig: false},
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 2s wait is good actually. Email sending takes a hot sec and this helps
|
* 2s wait is good actually. Email sending takes a hot sec and this helps
|
||||||
* ensure the email is ready for the user once they open their inbox.
|
* ensure the email is ready for the user once they open their inbox.
|
||||||
@@ -55,8 +66,8 @@ export function useBeginAgeAssurance() {
|
|||||||
2e3,
|
2e3,
|
||||||
appView.app.bsky.ageassurance.begin({
|
appView.app.bsky.ageassurance.begin({
|
||||||
...props,
|
...props,
|
||||||
countryCode: countryCode.toUpperCase(),
|
countryCode,
|
||||||
regionCode: regionCode ? regionCode.toUpperCase() : undefined,
|
regionCode,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+18
-4
@@ -1,5 +1,6 @@
|
|||||||
import {type LocationGeocodedAddress} from 'expo-location'
|
import {type LocationGeocodedAddress} from 'expo-location'
|
||||||
|
|
||||||
|
import {isAndroid} from '#/platform/detection'
|
||||||
import {logger} from '#/geolocation/logger'
|
import {logger} from '#/geolocation/logger'
|
||||||
import {type Geolocation} from '#/geolocation/types'
|
import {type Geolocation} from '#/geolocation/types'
|
||||||
|
|
||||||
@@ -75,16 +76,29 @@ export function normalizeDeviceLocation(
|
|||||||
location: LocationGeocodedAddress,
|
location: LocationGeocodedAddress,
|
||||||
): Geolocation {
|
): Geolocation {
|
||||||
let {isoCountryCode, region} = location
|
let {isoCountryCode, region} = location
|
||||||
|
let regionCode: string | undefined = region ?? undefined
|
||||||
|
|
||||||
if (region) {
|
/*
|
||||||
if (isoCountryCode === 'US') {
|
* Android doesn't give us ISO 3166-2 short codes. We need these for US
|
||||||
region = USRegionNameToRegionCode[region] ?? region
|
*/
|
||||||
|
if (isAndroid) {
|
||||||
|
if (region && isoCountryCode === 'US') {
|
||||||
|
/*
|
||||||
|
* We need short codes for US states. If we can't remap it, just drop it
|
||||||
|
* entirely for now.
|
||||||
|
*/
|
||||||
|
regionCode = USRegionNameToRegionCode[region] ?? undefined
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Outside the US, we don't need regionCodes for now, so just drop it.
|
||||||
|
*/
|
||||||
|
regionCode = undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
countryCode: isoCountryCode ?? undefined,
|
countryCode: isoCountryCode ?? undefined,
|
||||||
regionCode: region ?? undefined,
|
regionCode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -598,6 +598,11 @@ export type MetricEvents = {
|
|||||||
hasInitiatedPreviously: boolean
|
hasInitiatedPreviously: boolean
|
||||||
}
|
}
|
||||||
'ageAssurance:initDialogSubmit': {}
|
'ageAssurance:initDialogSubmit': {}
|
||||||
|
'ageAssurance:api:begin': {
|
||||||
|
platform: string
|
||||||
|
countryCode: string
|
||||||
|
regionCode?: string
|
||||||
|
}
|
||||||
'ageAssurance:initDialogError': {
|
'ageAssurance:initDialogError': {
|
||||||
code: string
|
code: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user