Clarify naming
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
|||||||
type AppBskyAgeassuranceGetState,
|
type AppBskyAgeassuranceGetState,
|
||||||
AtpAgent,
|
AtpAgent,
|
||||||
type ChatBskyActorDeclaration,
|
type ChatBskyActorDeclaration,
|
||||||
getAgeAssuranceRegionConfig,
|
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {createAsyncStoragePersister} from '@tanstack/query-async-storage-persister'
|
import {createAsyncStoragePersister} from '@tanstack/query-async-storage-persister'
|
||||||
import {focusManager, QueryClient, useQuery} from '@tanstack/react-query'
|
import {focusManager, QueryClient, useQuery} from '@tanstack/react-query'
|
||||||
@@ -32,6 +31,7 @@ import {
|
|||||||
} from '#/ageAssurance/types'
|
} from '#/ageAssurance/types'
|
||||||
import {
|
import {
|
||||||
createRegionKey,
|
createRegionKey,
|
||||||
|
getAgeAssuranceRegionConfigForGeolocation,
|
||||||
getBirthdateStringFromAge,
|
getBirthdateStringFromAge,
|
||||||
isLegacyBirthdateBug,
|
isLegacyBirthdateBug,
|
||||||
} from '#/ageAssurance/util'
|
} from '#/ageAssurance/util'
|
||||||
@@ -317,10 +317,7 @@ export function useServerStateQuery() {
|
|||||||
const isAArequired = Boolean(
|
const isAArequired = Boolean(
|
||||||
config &&
|
config &&
|
||||||
geolocation &&
|
geolocation &&
|
||||||
!!getAgeAssuranceRegionConfig(config, {
|
getAgeAssuranceRegionConfigForGeolocation(config, geolocation),
|
||||||
countryCode: geolocation?.countryCode ?? '',
|
|
||||||
regionCode: geolocation?.regionCode,
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// only refetch when needed
|
// only refetch when needed
|
||||||
@@ -626,10 +623,7 @@ export function useDeviceSignalsQuery() {
|
|||||||
* geolocation matches no AA region there's no device grant to surface.
|
* geolocation matches no AA region there's no device grant to surface.
|
||||||
*/
|
*/
|
||||||
const regionConfig = config
|
const regionConfig = config
|
||||||
? getAgeAssuranceRegionConfig(config, {
|
? getAgeAssuranceRegionConfigForGeolocation(config, geolocation)
|
||||||
countryCode: geolocation.countryCode ?? '',
|
|
||||||
regionCode: geolocation.regionCode,
|
|
||||||
})
|
|
||||||
: undefined
|
: undefined
|
||||||
const regionKey = regionConfig ? createRegionKey(regionConfig) : undefined
|
const regionKey = regionConfig ? createRegionKey(regionConfig) : undefined
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import type * as AgeRange from 'expo-age-range'
|
|||||||
import {
|
import {
|
||||||
type AppBskyAgeassuranceDefs,
|
type AppBskyAgeassuranceDefs,
|
||||||
computeAgeAssuranceRegionAccess,
|
computeAgeAssuranceRegionAccess,
|
||||||
getAgeAssuranceRegionConfig,
|
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
|
|
||||||
import {getAge} from '#/lib/strings/time'
|
import {getAge} from '#/lib/strings/time'
|
||||||
@@ -27,6 +26,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
computeAgeAssuranceFlags,
|
computeAgeAssuranceFlags,
|
||||||
getAgeAssuranceDataFromDeviceSignals,
|
getAgeAssuranceDataFromDeviceSignals,
|
||||||
|
getAgeAssuranceRegionConfigForGeolocation,
|
||||||
getAgeAssuranceRegionConfigWithFallback,
|
getAgeAssuranceRegionConfigWithFallback,
|
||||||
} from '#/ageAssurance/util'
|
} from '#/ageAssurance/util'
|
||||||
import {type Geolocation, useGeolocation} from '#/geolocation'
|
import {type Geolocation, useGeolocation} from '#/geolocation'
|
||||||
@@ -159,10 +159,10 @@ export function unsafeGetAndComputeAgeAssurance({did}: {did: string}) {
|
|||||||
* skip the lookup rather than keying off FALLBACK_REGION_CONFIG. This keeps
|
* skip the lookup rather than keying off FALLBACK_REGION_CONFIG. This keeps
|
||||||
* the read key symmetric with the write (see `setDeviceSignalsForRegion`).
|
* the read key symmetric with the write (see `setDeviceSignalsForRegion`).
|
||||||
*/
|
*/
|
||||||
const deviceRegion = getAgeAssuranceRegionConfig(config, {
|
const deviceRegion = getAgeAssuranceRegionConfigForGeolocation(
|
||||||
countryCode: geolocation.countryCode ?? '',
|
config,
|
||||||
regionCode: geolocation.regionCode,
|
geolocation,
|
||||||
})
|
)
|
||||||
const deviceSignals = deviceRegion
|
const deviceSignals = deviceRegion
|
||||||
? getDeviceSignalsFromCacheForRegion({did, region: deviceRegion})
|
? getDeviceSignalsFromCacheForRegion({did, region: deviceRegion})
|
||||||
: undefined
|
: undefined
|
||||||
|
|||||||
+27
-12
@@ -25,23 +25,41 @@ import {
|
|||||||
import {type Geolocation, useGeolocation} from '#/geolocation'
|
import {type Geolocation, useGeolocation} from '#/geolocation'
|
||||||
import {USRegionNameToRegionCode} from '#/geolocation/util'
|
import {USRegionNameToRegionCode} from '#/geolocation/util'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a geolocation to its matched age assurance region config, or
|
||||||
|
* undefined when the geolocation matches no AA region.
|
||||||
|
*
|
||||||
|
* This is the single source of truth for geolocation -> region resolution.
|
||||||
|
* Device signals are written and read back under a key derived from the
|
||||||
|
* matched region (see `createRegionKey`), so every site that resolves a region
|
||||||
|
* for that purpose MUST go through this helper - independent re-implementations
|
||||||
|
* risk desyncing the write and read keys and silently losing grants.
|
||||||
|
*/
|
||||||
|
export function getAgeAssuranceRegionConfigForGeolocation(
|
||||||
|
config: AppBskyAgeassuranceDefs.Config,
|
||||||
|
geolocation: Geolocation,
|
||||||
|
): AppBskyAgeassuranceDefs.ConfigRegion | undefined {
|
||||||
|
return getAgeAssuranceRegionConfig(config, {
|
||||||
|
countryCode: geolocation.countryCode ?? '',
|
||||||
|
regionCode: geolocation.regionCode,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get age assurance region config based on geolocation, with fallback to
|
* Get age assurance region config based on geolocation, with fallback to
|
||||||
* app defaults if no region config is found.
|
* app defaults if no region config is found.
|
||||||
*
|
*
|
||||||
* See {@link getAgeAssuranceRegionConfig} for the generic option, which can
|
* See {@link getAgeAssuranceRegionConfigForGeolocation} for the generic option,
|
||||||
* return undefined if the geolocation does not match any AA region.
|
* which can return undefined if the geolocation does not match any AA region.
|
||||||
*/
|
*/
|
||||||
export function getAgeAssuranceRegionConfigWithFallback(
|
export function getAgeAssuranceRegionConfigWithFallback(
|
||||||
config: AppBskyAgeassuranceDefs.Config,
|
config: AppBskyAgeassuranceDefs.Config,
|
||||||
geolocation: Geolocation,
|
geolocation: Geolocation,
|
||||||
): AppBskyAgeassuranceDefs.ConfigRegion {
|
): AppBskyAgeassuranceDefs.ConfigRegion {
|
||||||
const region = getAgeAssuranceRegionConfig(config, {
|
return (
|
||||||
countryCode: geolocation.countryCode ?? '',
|
getAgeAssuranceRegionConfigForGeolocation(config, geolocation) ||
|
||||||
regionCode: geolocation.regionCode,
|
FALLBACK_REGION_CONFIG
|
||||||
})
|
)
|
||||||
|
|
||||||
return region || FALLBACK_REGION_CONFIG
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,10 +243,7 @@ export function useAgeAssuranceRegionConfig() {
|
|||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (!config) return
|
if (!config) return
|
||||||
// use generic helper, we want to potentially return undefined
|
// use generic helper, we want to potentially return undefined
|
||||||
return getAgeAssuranceRegionConfig(config, {
|
return getAgeAssuranceRegionConfigForGeolocation(config, geolocation)
|
||||||
countryCode: geolocation.countryCode ?? '',
|
|
||||||
regionCode: geolocation.regionCode,
|
|
||||||
})
|
|
||||||
}, [config, geolocation])
|
}, [config, geolocation])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user