···1212import {AgeAssuranceAccess} from '#/ageAssurance/types'
1313import {type Geolocation, useGeolocation} from '#/geolocation'
14141515-const DEFAULT_MIN_AGE = 13
1515+export const MIN_ACCESS_AGE = 13
1616+const FALLBACK_REGION_CONFIG: AppBskyAgeassuranceDefs.ConfigRegion = {
1717+ countryCode: '*',
1818+ regionCode: undefined,
1919+ minAccessAge: MIN_ACCESS_AGE,
2020+ rules: [
2121+ {
2222+ $type: ids.IfDeclaredOverAge,
2323+ age: MIN_ACCESS_AGE,
2424+ access: AgeAssuranceAccess.Full,
2525+ },
2626+ {
2727+ $type: ids.Default,
2828+ access: AgeAssuranceAccess.None,
2929+ },
3030+ ],
3131+}
16321733/**
1834 * Get age assurance region config based on geolocation, with fallback to
···3046 regionCode: geolocation.regionCode,
3147 })
32483333- return (
3434- region || {
3535- countryCode: '*',
3636- regionCode: undefined,
3737- rules: [
3838- {
3939- $type: ids.IfDeclaredOverAge,
4040- age: DEFAULT_MIN_AGE,
4141- access: AgeAssuranceAccess.Full,
4242- },
4343- {
4444- $type: ids.Default,
4545- access: AgeAssuranceAccess.None,
4646- },
4747- ],
4848- }
4949- )
4949+ return region || FALLBACK_REGION_CONFIG
5050}
51515252/**
···6868}
69697070/**
7171+ * Hook to get the age assurance region config based on current geolocation.
7272+ * Falls back to our app defaults if no region config is found.
7373+ */
7474+export function useAgeAssuranceRegionConfigWithFallback() {
7575+ return useAgeAssuranceRegionConfig() || FALLBACK_REGION_CONFIG
7676+}
7777+7878+/**
7179 * Some users may have erroneously set their birth date to the current date
7280 * if one wasn't set on their account. We previously didn't do validation on
7381 * the bday dialog, and it defaulted to the current date. This bug _has_ been
···7886}
79878088/**
8181- * Returns whether the user is under the minimum age required to use the app.
8282- * This applies to all regions.
8989+ * Returns whether the date (converted to an age as a whole integer) is under
9090+ * the provided minimum age.
8391 */
8484-export function isUserUnderMinimumAge(birthDate: string) {
8585- return getAge(new Date(birthDate)) < DEFAULT_MIN_AGE
8686-}
8787-8888-export function isUserUnderAdultAge(birthDate: string) {
8989- return getAge(new Date(birthDate)) < 18
9292+export function isUnderAge(birthDate: string, age: number) {
9393+ return getAge(new Date(birthDate)) < age
9094}
91959296export function getBirthdateStringFromAge(age: number) {