Refine logic for showing prompt
This commit is contained in:
@@ -12,9 +12,9 @@ import {Text} from '#/components/Typography'
|
|||||||
export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
|
export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {isAgeRestricted} = useAgeAssuranceContext()
|
const {hasInitiated} = useAgeAssuranceContext()
|
||||||
|
|
||||||
return !isAgeRestricted ? null : (
|
return hasInitiated ? null : (
|
||||||
<View style={style}>
|
<View style={style}>
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
@@ -65,7 +65,7 @@ export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
<Trans>Age Asurrance</Trans>
|
<Trans>Age Assurance</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {useGeolocation} from '#/state/geolocation'
|
|||||||
const logger = Logger.create(Logger.Context.AgeAssurance)
|
const logger = Logger.create(Logger.Context.AgeAssurance)
|
||||||
|
|
||||||
type TempAgeAssuranceState = {
|
type TempAgeAssuranceState = {
|
||||||
updatedAt?: string
|
lastInitiatedAt?: string
|
||||||
status: 'unknown' | 'pending' | 'assured'
|
status: 'unknown' | 'pending' | 'assured'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +23,14 @@ export type AgeAssuranceContextType = {
|
|||||||
* The current age assurance status retrieved from the server.
|
* The current age assurance status retrieved from the server.
|
||||||
*/
|
*/
|
||||||
status: TempAgeAssuranceState['status']
|
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 = {
|
export type AgeAssuranceAPIContextType = {
|
||||||
@@ -35,6 +43,8 @@ export type AgeAssuranceAPIContextType = {
|
|||||||
const AgeAssuranceContext = createContext<AgeAssuranceContextType>({
|
const AgeAssuranceContext = createContext<AgeAssuranceContextType>({
|
||||||
isAgeRestricted: false,
|
isAgeRestricted: false,
|
||||||
status: 'unknown',
|
status: 'unknown',
|
||||||
|
lastInitiatedAt: undefined,
|
||||||
|
hasInitiated: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
const AgeAssuranceAPIContext = createContext<AgeAssuranceAPIContextType>({
|
const AgeAssuranceAPIContext = createContext<AgeAssuranceAPIContextType>({
|
||||||
@@ -55,7 +65,7 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
200,
|
200,
|
||||||
(() => ({
|
(() => ({
|
||||||
data: {
|
data: {
|
||||||
updatedAt: undefined,
|
lastInitiatedAt: undefined,
|
||||||
status: 'unknown',
|
status: 'unknown',
|
||||||
} as TempAgeAssuranceState,
|
} as TempAgeAssuranceState,
|
||||||
}))(),
|
}))(),
|
||||||
@@ -72,12 +82,14 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
}, [setAgeAssuranceState])
|
}, [setAgeAssuranceState])
|
||||||
|
|
||||||
const ageAssuranceContext = useMemo<AgeAssuranceContextType>(() => {
|
const ageAssuranceContext = useMemo<AgeAssuranceContextType>(() => {
|
||||||
const {status} = ageAssuranceState
|
const {status, lastInitiatedAt} = ageAssuranceState
|
||||||
const ctx: AgeAssuranceContextType = {
|
const ctx: AgeAssuranceContextType = {
|
||||||
|
status,
|
||||||
|
lastInitiatedAt,
|
||||||
|
hasInitiated: !!lastInitiatedAt,
|
||||||
isAgeRestricted: Boolean(
|
isAgeRestricted: Boolean(
|
||||||
geolocation?.isAgeRestrictedGeo && status !== 'assured',
|
geolocation?.isAgeRestrictedGeo && status !== 'assured',
|
||||||
),
|
),
|
||||||
status,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`context`, ctx)
|
logger.debug(`context`, ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user