Refine logic for showing prompt

This commit is contained in:
Eric Bailey
2025-06-26 11:39:51 -05:00
parent 6a4ee34528
commit 7021e8bab2
2 changed files with 19 additions and 7 deletions
@@ -12,9 +12,9 @@ import {Text} from '#/components/Typography'
export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
const t = useTheme()
const {_} = useLingui()
const {isAgeRestricted} = useAgeAssuranceContext()
const {hasInitiated} = useAgeAssuranceContext()
return !isAgeRestricted ? null : (
return hasInitiated ? null : (
<View style={style}>
<View
style={[
@@ -65,7 +65,7 @@ export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
}),
},
]}>
<Trans>Age Asurrance</Trans>
<Trans>Age Assurance</Trans>
</Text>
</View>
</View>
+16 -4
View File
@@ -9,7 +9,7 @@ import {useGeolocation} from '#/state/geolocation'
const logger = Logger.create(Logger.Context.AgeAssurance)
type TempAgeAssuranceState = {
updatedAt?: string
lastInitiatedAt?: string
status: 'unknown' | 'pending' | 'assured'
}
@@ -23,6 +23,14 @@ export type AgeAssuranceContextType = {
* The current age assurance status retrieved from the server.
*/
status: TempAgeAssuranceState['status']
/**
* The last time the age assurance state was attempted by the user.
*/
lastInitiatedAt: string | undefined
/**
* Whether the user has initiated an age assurance check.
*/
hasInitiated: boolean
}
export type AgeAssuranceAPIContextType = {
@@ -35,6 +43,8 @@ export type AgeAssuranceAPIContextType = {
const AgeAssuranceContext = createContext<AgeAssuranceContextType>({
isAgeRestricted: false,
status: 'unknown',
lastInitiatedAt: undefined,
hasInitiated: false,
})
const AgeAssuranceAPIContext = createContext<AgeAssuranceAPIContextType>({
@@ -55,7 +65,7 @@ export function Provider({children}: {children: React.ReactNode}) {
200,
(() => ({
data: {
updatedAt: undefined,
lastInitiatedAt: undefined,
status: 'unknown',
} as TempAgeAssuranceState,
}))(),
@@ -72,12 +82,14 @@ export function Provider({children}: {children: React.ReactNode}) {
}, [setAgeAssuranceState])
const ageAssuranceContext = useMemo<AgeAssuranceContextType>(() => {
const {status} = ageAssuranceState
const {status, lastInitiatedAt} = ageAssuranceState
const ctx: AgeAssuranceContextType = {
status,
lastInitiatedAt,
hasInitiated: !!lastInitiatedAt,
isAgeRestricted: Boolean(
geolocation?.isAgeRestrictedGeo && status !== 'assured',
),
status,
}
logger.debug(`context`, ctx)