From 0456562abf116290fd05bd9029d35ae2996cd5c4 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 2 Jul 2026 11:07:18 -0500 Subject: [PATCH] Pipe through deviceSignals for logical handling --- .../components/NoAccessScreen.tsx | 23 +++++++++---------- src/ageAssurance/index.tsx | 9 +++++--- src/ageAssurance/state.ts | 1 + src/ageAssurance/types.ts | 1 + src/ageAssurance/useVerificationFlow.ts | 23 ++++++++----------- src/ageAssurance/util.ts | 4 ++++ .../ageAssurance/AgeAssuranceAccountCard.tsx | 23 +++++++++---------- 7 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/ageAssurance/components/NoAccessScreen.tsx b/src/ageAssurance/components/NoAccessScreen.tsx index b4b183d630..a9e8ce9eec 100644 --- a/src/ageAssurance/components/NoAccessScreen.tsx +++ b/src/ageAssurance/components/NoAccessScreen.tsx @@ -384,13 +384,8 @@ function AccessSection() { const diff = lastInitiatedAt ? dateDiff(lastInitiatedAt, new Date(), 'down') : null - const { - onPressVerify, - openKwsDialog, - isVerifyingDevice, - allowsDeviceVerification, - verifyCta, - } = useAgeAssuranceVerificationFlow({initDialogControl: control}) + const {onPressVerify, openInitDialog, isVerifying, verifyCta} = + useAgeAssuranceVerificationFlow({initDialogControl: control}) return ( <> @@ -420,14 +415,18 @@ function AccessSection() { - {allowsDeviceVerification ? ( + {aa.flags.allowsDeviceVerification ? ( @@ -437,7 +436,7 @@ function AccessSection() { { - openKwsDialog() + openInitDialog() })}> you can use our trusted partner, KWS diff --git a/src/ageAssurance/index.tsx b/src/ageAssurance/index.tsx index dc1c9bd3f3..1bfc58c3fc 100644 --- a/src/ageAssurance/index.tsx +++ b/src/ageAssurance/index.tsx @@ -56,6 +56,7 @@ const AgeAssuranceStateContext = createContext<{ isOverRegionMinAccessAge: false, isOverAppMinAccessAge: false, allowsDeviceVerification: false, + hasSharedDeviceSignals: false, }, }) @@ -81,7 +82,7 @@ export function Provider({children}: {children: React.ReactNode}) { function InnerProvider({children}: {children: React.ReactNode}) { const agent = useAgent() const state = useAgeAssuranceState() - const {metadata} = useAgeAssuranceServerDataContext() + const {metadata, deviceSignals} = useAgeAssuranceServerDataContext() const regionConfig = useAgeAssuranceRegionConfigWithFallback() const getAndRegisterPushToken = useGetAndRegisterPushToken() @@ -91,6 +92,7 @@ function InnerProvider({children}: {children: React.ReactNode}) { state: s, regionConfig, metadata, + deviceSignals, }) if (flags.isAgeRestricted) { void getAndRegisterPushToken({ @@ -105,7 +107,7 @@ function InnerProvider({children}: {children: React.ReactNode}) { }) } }, - [agent, getAndRegisterPushToken, regionConfig, metadata], + [agent, getAndRegisterPushToken, regionConfig, metadata, deviceSignals], ) useOnAgeAssuranceAccessUpdate(handleAccessUpdate) @@ -120,11 +122,12 @@ function InnerProvider({children}: {children: React.ReactNode}) { state, regionConfig, metadata, + deviceSignals, }), } logger.debug(`useAgeAssurance`, res) return res - }, [state, metadata, regionConfig])}> + }, [state, metadata, regionConfig, deviceSignals])}> {children} ) diff --git a/src/ageAssurance/state.ts b/src/ageAssurance/state.ts index 457ff8275a..eb3ca0c7dc 100644 --- a/src/ageAssurance/state.ts +++ b/src/ageAssurance/state.ts @@ -188,6 +188,7 @@ export function unsafeGetAndComputeAgeAssurance({did}: {did: string}) { state: computed, regionConfig: region, metadata, + deviceSignals, }), } } diff --git a/src/ageAssurance/types.ts b/src/ageAssurance/types.ts index 1c4784da84..5dcabeb268 100644 --- a/src/ageAssurance/types.ts +++ b/src/ageAssurance/types.ts @@ -56,6 +56,7 @@ export type AgeAssuranceFlags = { isOverRegionMinAccessAge: boolean isOverAppMinAccessAge: boolean allowsDeviceVerification: boolean + hasSharedDeviceSignals: boolean } export function parseStatusFromString(raw: string) { diff --git a/src/ageAssurance/useVerificationFlow.ts b/src/ageAssurance/useVerificationFlow.ts index 04473db710..77e48efb00 100644 --- a/src/ageAssurance/useVerificationFlow.ts +++ b/src/ageAssurance/useVerificationFlow.ts @@ -28,12 +28,10 @@ import {useAnalytics} from '#/analytics' * prompts the OS age API, persists a sufficient result (region-bound), and * toasts the outcome; otherwise (or on any missing/failed device response) it * opens the KWS dialog. - * - `openKwsDialog`: opens the KWS dialog directly (for the inline "use KWS" + * - `openInitDialog`: opens the KWS dialog directly (for the inline "use KWS" * link), emitting the same metric as the fallback path. - * - `isVerifyingDevice`: true while the OS age prompt is up, for a button + * - `isVerifying`: true while the OS age prompt is up, for a button * loading state. - * - `allowsDeviceVerification`: whether this region + device supports the - * on-device flow, for CTA/copy branching. * - `verifyCta`: the localized button label for the current mode. */ export function useAgeAssuranceVerificationFlow({ @@ -54,9 +52,9 @@ export function useAgeAssuranceVerificationFlow({ ? l`Verify again` : l`Verify now` - const [isVerifyingDevice, setIsVerifyingDevice] = useState(false) + const [isVerifying, setIsVerifying] = useState(false) - const openKwsDialog = useCallback(() => { + const openInitDialog = useCallback(() => { initDialogControl.open() ax.metric('ageAssurance:initDialogOpen', { hasInitiatedPreviously: hasInitiated, @@ -84,12 +82,12 @@ export function useAgeAssuranceVerificationFlow({ */ if (allowsDeviceVerification) { // Show a loading state while the OS age prompt is up. - setIsVerifyingDevice(true) + setIsVerifying(true) let signals: AgeRange.AgeRangeResponse | undefined try { signals = await getDeviceSignals() } finally { - setIsVerifyingDevice(false) + setIsVerifying(false) } if (signals) { const {assuredAge} = getAgeAssuranceDataFromDeviceSignals( @@ -140,11 +138,11 @@ export function useAgeAssuranceVerificationFlow({ ) } - openKwsDialog() + openInitDialog() }, [ region, currentAccount?.did, - openKwsDialog, + openInitDialog, allowsDeviceVerification, aa, l, @@ -152,9 +150,8 @@ export function useAgeAssuranceVerificationFlow({ return { onPressVerify, - openKwsDialog, - isVerifyingDevice, - allowsDeviceVerification, + openInitDialog, + isVerifying, verifyCta, } } diff --git a/src/ageAssurance/util.ts b/src/ageAssurance/util.ts index 1cd33ef6d7..062eaced9a 100644 --- a/src/ageAssurance/util.ts +++ b/src/ageAssurance/util.ts @@ -266,10 +266,12 @@ export function computeAgeAssuranceFlags({ state, regionConfig, metadata, + deviceSignals, }: { state: AgeAssuranceState regionConfig: AppBskyAgeassuranceDefs.ConfigRegion metadata?: AgeAssuranceMetadata + deviceSignals?: AgeRange.AgeRangeResponse }): AgeAssuranceFlags { const isAgeRestricted = state.access !== AgeAssuranceAccess.Full const chatDisabled = isAgeRestricted @@ -287,6 +289,7 @@ export function computeAgeAssuranceFlags({ state.access !== AgeAssuranceAccess.Full || isDeclaredUnderAdultAge const allowsDeviceVerification = DEVICE_SIGNALS_SUPPORTED && regionAllowsDeviceVerification(regionConfig) + const hasSharedDeviceSignals = deviceSignals?.lowerBound !== undefined return { isAgeRestricted, @@ -298,6 +301,7 @@ export function computeAgeAssuranceFlags({ isOverRegionMinAccessAge, isOverAppMinAccessAge, allowsDeviceVerification, + hasSharedDeviceSignals, } } diff --git a/src/components/ageAssurance/AgeAssuranceAccountCard.tsx b/src/components/ageAssurance/AgeAssuranceAccountCard.tsx index 52bdf0c4d3..67702383f5 100644 --- a/src/components/ageAssurance/AgeAssuranceAccountCard.tsx +++ b/src/components/ageAssurance/AgeAssuranceAccountCard.tsx @@ -63,13 +63,8 @@ function Inner({style}: ViewStyleProp & {}) { const diff = lastInitiatedAt ? dateDiff(lastInitiatedAt, new Date(), 'down') : null - const { - onPressVerify, - openKwsDialog, - isVerifyingDevice, - allowsDeviceVerification, - verifyCta, - } = useAgeAssuranceVerificationFlow({initDialogControl: control}) + const {onPressVerify, openInitDialog, isVerifying, verifyCta} = + useAgeAssuranceVerificationFlow({initDialogControl: control}) return ( <> @@ -150,14 +145,18 @@ function Inner({style}: ViewStyleProp & {}) { - {allowsDeviceVerification ? ( + {aa.flags.allowsDeviceVerification ? ( @@ -167,7 +166,7 @@ function Inner({style}: ViewStyleProp & {}) { { - openKwsDialog() + openInitDialog() })}> you can use our trusted partner, KWS