diff --git a/src/components/ageAssurance/AgeAssuranceAccountCard.tsx b/src/components/ageAssurance/AgeAssuranceAccountCard.tsx index 3eae2424fc..1a229be1aa 100644 --- a/src/components/ageAssurance/AgeAssuranceAccountCard.tsx +++ b/src/components/ageAssurance/AgeAssuranceAccountCard.tsx @@ -40,6 +40,7 @@ function Inner({style}: ViewStyleProp & {}) { const copy = useAgeAssuranceCopy() const {assurance} = useAgeInfo() const isBlocked = assurance.status === 'blocked' + const hasInitiated = !!assurance.lastInitiatedAt const timeAgo = assurance.lastInitiatedAt ? getTimeAgo(assurance.lastInitiatedAt, new Date()) : null @@ -118,10 +119,10 @@ function Inner({style}: ViewStyleProp & {}) { label={_(msg`Verify now`)} size="small" variant="solid" - color={assurance.hasInitiated ? 'secondary' : 'primary'} + color={hasInitiated ? 'secondary' : 'primary'} onPress={() => control.open()}> - {assurance.hasInitiated ? ( + {hasInitiated ? ( Verify again ) : ( Verify now diff --git a/src/components/ageAssurance/AgeRestrictedScreen.tsx b/src/components/ageAssurance/AgeRestrictedScreen.tsx index 5a7b28a7c5..44077f1313 100644 --- a/src/components/ageAssurance/AgeRestrictedScreen.tsx +++ b/src/components/ageAssurance/AgeRestrictedScreen.tsx @@ -26,7 +26,6 @@ export function AgeRestrictedScreen({ const copy = useAgeAssuranceCopy() const {isLoaded, assurance} = useAgeInfo() - if (assurance.isExempt) return children if (!isLoaded) { return ( diff --git a/src/state/age-assurance/index.tsx b/src/state/age-assurance/index.tsx index 9e6db44396..24eff8142f 100644 --- a/src/state/age-assurance/index.tsx +++ b/src/state/age-assurance/index.tsx @@ -27,9 +27,7 @@ const AgeAssuranceContext = createContext({ status: 'unknown', isLoaded: false, isAgeRestricted: false, - isExempt: false, lastInitiatedAt: undefined, - hasInitiated: false, }) const AgeAssuranceAPIContext = createContext({ // @ts-ignore @@ -99,12 +97,10 @@ export function Provider({children}: {children: React.ReactNode}) { const enabled = __DEV__ || gate('age_assurance') const {status, lastInitiatedAt} = data || DEFAULT_AGE_ASSURANCE_STATE const ctx: AgeAssuranceContextType = { - status, isLoaded: isFetched, + status, lastInitiatedAt, - hasInitiated: !!lastInitiatedAt, - isExempt: !isAgeRestrictedGeo || !enabled, - isAgeRestricted: Boolean(isAgeRestrictedGeo && status !== 'assured'), + isAgeRestricted: isAgeRestrictedGeo && status !== 'assured' && enabled, } logger.debug(`context`, ctx) diff --git a/src/state/age-assurance/types.ts b/src/state/age-assurance/types.ts index 04af7cef4c..182411a29d 100644 --- a/src/state/age-assurance/types.ts +++ b/src/state/age-assurance/types.ts @@ -3,25 +3,19 @@ import {type QueryObserverBaseResult} from '@tanstack/react-query' export type AgeAssuranceContextType = { isLoaded: boolean + /** + * The server-reported status of the user's age verification process. + */ status: AppBskyUnspeccedDefs.AgeAssuranceState['status'] - /** - * Whether the current user is age-restricted based on their geolocation and - * age assurance state retrieved from the server. - */ - isAgeRestricted: boolean - /** - * Whether the user is exempt from age assurance checks, e.g., due to - * them not being in a region that requires age assurance. - */ - isExempt: boolean /** * The last time the age assurance state was attempted by the user. */ lastInitiatedAt: string | undefined /** - * Whether the user has initiated an age assurance check. + * Whether the current user is age-restricted based on their geolocation and + * age assurance state retrieved from the server. */ - hasInitiated: boolean + isAgeRestricted: boolean } export type AgeAssuranceAPIContextType = { diff --git a/src/state/age-assurance/useMaybeApplyAgeRestrictedModerationPrefs.ts b/src/state/age-assurance/useMaybeApplyAgeRestrictedModerationPrefs.ts index 00a2ac369b..be2fca31dd 100644 --- a/src/state/age-assurance/useMaybeApplyAgeRestrictedModerationPrefs.ts +++ b/src/state/age-assurance/useMaybeApplyAgeRestrictedModerationPrefs.ts @@ -1,12 +1,9 @@ import {useCallback} from 'react' import {type ModerationPrefs} from '@atproto/api' -// import {Logger} from '#/logger' import {useAgeAssuranceContext} from '#/state/age-assurance' import {AGE_RESTRICTED_MODERATION_PREFS} from '#/state/age-assurance/const' -// const logger = Logger.create(Logger.Context.AgeAssurance) - /** * Hook to conditionally apply age-restricted moderation preferences, if * needed. If not needed, the mod prefs passed to the callback will be used. @@ -15,26 +12,10 @@ export function useMaybeApplyAgeRestrictedModerationPrefs() { const state = useAgeAssuranceContext() return useCallback( (prev: ModerationPrefs) => { - const isDefinitelyAgeRestricted = state.isLoaded && state.isAgeRestricted - const notSureYet = !state.isLoaded && state.isAgeRestricted - - if (state.isExempt) { - // logger.debug('useMaybeApplyAgeRestrictedModerationPrefs: exempt', state) - return prev - } - - if (notSureYet || isDefinitelyAgeRestricted) { - // logger.debug( - // 'useMaybeApplyAgeRestrictedModerationPrefs: overridden', - // state, - // ) + if (state.isAgeRestricted) { return AGE_RESTRICTED_MODERATION_PREFS } - // logger.debug( - // 'useMaybeApplyAgeRestrictedModerationPrefs: not overridden', - // state, - // ) return prev }, [state],