Bluesky app fork with some witchin' additions 💫

[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

authored by Eric Bailey and committed by GitHub 8d5b1c83 37a73b17

Changed files
+39 -9
src
ageAssurance
geolocation
logger
+16 -5
src/ageAssurance/useBeginAgeAssurance.ts
··· 1 + import {Platform} from 'react-native' 1 2 import {type AppBskyAgeassuranceBegin, AtpAgent} from '@atproto/api' 2 3 import {useMutation} from '@tanstack/react-query' 3 4 ··· 8 9 PUBLIC_APPVIEW_DID, 9 10 } from '#/lib/constants' 10 11 import {isNetworkError} from '#/lib/hooks/useCleanError' 11 - import {logger} from '#/logger' 12 12 import {useAgent} from '#/state/session' 13 13 import {usePatchAgeAssuranceServerState} from '#/ageAssurance' 14 + import {logger} from '#/ageAssurance/logger' 14 15 import {BLUESKY_PROXY_DID} from '#/env' 15 16 import {useGeolocation} from '#/geolocation' 16 17 ··· 29 30 'countryCode' | 'regionCode' 30 31 >, 31 32 ) { 32 - const countryCode = geolocation?.countryCode 33 - const regionCode = geolocation?.regionCode 33 + const countryCode = geolocation?.countryCode?.toUpperCase() 34 + const regionCode = geolocation?.regionCode?.toUpperCase() 34 35 if (!countryCode) { 35 36 throw new Error(`Geolocation not available, cannot init age assurance.`) 36 37 } ··· 47 48 appView.sessionManager.session.accessJwt = token 48 49 appView.sessionManager.session.refreshJwt = '' 49 50 51 + logger.metric( 52 + 'ageAssurance:api:begin', 53 + { 54 + platform: Platform.OS, 55 + countryCode, 56 + regionCode, 57 + }, 58 + {statsig: false}, 59 + ) 60 + 50 61 /* 51 62 * 2s wait is good actually. Email sending takes a hot sec and this helps 52 63 * ensure the email is ready for the user once they open their inbox. ··· 55 66 2e3, 56 67 appView.app.bsky.ageassurance.begin({ 57 68 ...props, 58 - countryCode: countryCode.toUpperCase(), 59 - regionCode: regionCode ? regionCode.toUpperCase() : undefined, 69 + countryCode, 70 + regionCode, 60 71 }), 61 72 ) 62 73
+18 -4
src/geolocation/util.ts
··· 1 1 import {type LocationGeocodedAddress} from 'expo-location' 2 2 3 + import {isAndroid} from '#/platform/detection' 3 4 import {logger} from '#/geolocation/logger' 4 5 import {type Geolocation} from '#/geolocation/types' 5 6 ··· 75 76 location: LocationGeocodedAddress, 76 77 ): Geolocation { 77 78 let {isoCountryCode, region} = location 79 + let regionCode: string | undefined = region ?? undefined 78 80 79 - if (region) { 80 - if (isoCountryCode === 'US') { 81 - region = USRegionNameToRegionCode[region] ?? region 81 + /* 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 82 96 } 83 97 } 84 98 85 99 return { 86 100 countryCode: isoCountryCode ?? undefined, 87 - regionCode: region ?? undefined, 101 + regionCode, 88 102 } 89 103 } 90 104
+5
src/logger/metrics.ts
··· 598 598 hasInitiatedPreviously: boolean 599 599 } 600 600 'ageAssurance:initDialogSubmit': {} 601 + 'ageAssurance:api:begin': { 602 + platform: string 603 + countryCode: string 604 + regionCode?: string 605 + } 601 606 'ageAssurance:initDialogError': { 602 607 code: string 603 608 }