Cleanup todos, add comments

This commit is contained in:
Eric Bailey
2025-12-04 11:50:02 -06:00
parent 6c2665eec0
commit 9bc71bc3e6
14 changed files with 46 additions and 20 deletions
@@ -323,7 +323,6 @@ function AccessSection() {
<DeviceLocationRequestDialog <DeviceLocationRequestDialog
control={locationControl} control={locationControl}
onLocationAcquired={props => { onLocationAcquired={props => {
// TODO test this
const access = computeAgeAssuranceRegionAccess( const access = computeAgeAssuranceRegionAccess(
props.geolocation, props.geolocation,
) )
+5 -2
View File
@@ -163,7 +163,7 @@ export function createServerStateQueryKey({did}: {did: string}) {
export async function getServerState({agent}: {agent: AtpAgent}) { export async function getServerState({agent}: {agent: AtpAgent}) {
if (debug.enabled && debug.serverState) if (debug.enabled && debug.serverState)
return debug.resolve(debug.serverState) return debug.resolve(debug.serverState)
const geolocation = device.get(['mergedGeolocation']) // TODO can I improve this, dislike reading from storage const geolocation = device.get(['mergedGeolocation'])
if (!geolocation || !geolocation.countryCode) { if (!geolocation || !geolocation.countryCode) {
logger.error(`getServerState: missing geolocation countryCode`) logger.error(`getServerState: missing geolocation countryCode`)
return return
@@ -273,6 +273,7 @@ export function useServerStateQuery() {
*/ */
useEffect(() => { useEffect(() => {
return focusManager.subscribe(() => { return focusManager.subscribe(() => {
// logged out
if (!did) return if (!did) return
const isFocused = focusManager.isFocused() const isFocused = focusManager.isFocused()
@@ -290,6 +291,7 @@ export function useServerStateQuery() {
}), }),
) )
// only refetch when needed
if (isAssured || !isAArequired) return if (isAssured || !isAArequired) return
refetch() refetch()
@@ -417,7 +419,8 @@ export function useOtherRequiredDataQuery() {
* Helper to prefetch all age assurance data. * Helper to prefetch all age assurance data.
*/ */
export function prefetchAgeAssuranceData({agent}: {agent: AtpAgent}) { export function prefetchAgeAssuranceData({agent}: {agent: AtpAgent}) {
return Promise.all([ return Promise.allSettled([
// config fetch initiated at the top of the App.platform.tsx files, awaited here
configPrefetchPromise, configPrefetchPromise,
prefetchServerState({agent}), prefetchServerState({agent}),
prefetchOtherRequiredData({agent}), prefetchOtherRequiredData({agent}),
+6 -2
View File
@@ -14,8 +14,6 @@ import {
AgeAssuranceStatus, AgeAssuranceStatus,
} from '#/ageAssurance/types' } from '#/ageAssurance/types'
export {logger} from '#/ageAssurance/logger'
// TODO just import from file
export { export {
prefetchConfig as prefetchAgeAssuranceConfig, prefetchConfig as prefetchAgeAssuranceConfig,
prefetchAgeAssuranceData, prefetchAgeAssuranceData,
@@ -23,6 +21,7 @@ export {
usePatchOtherRequiredData as usePatchAgeAssuranceOtherRequiredData, usePatchOtherRequiredData as usePatchAgeAssuranceOtherRequiredData,
usePatchServerState as usePatchAgeAssuranceServerState, usePatchServerState as usePatchAgeAssuranceServerState,
} from '#/ageAssurance/data' } from '#/ageAssurance/data'
export {logger} from '#/ageAssurance/logger'
const AgeAssuranceStateContext = createContext<{ const AgeAssuranceStateContext = createContext<{
Access: typeof AgeAssuranceAccess Access: typeof AgeAssuranceAccess
@@ -38,6 +37,11 @@ const AgeAssuranceStateContext = createContext<{
}, },
}) })
/**
* THE MAIN AGE ASSURANCE CONTEXT HOOK
*
* Prefer this to using any of the lower-level data-provider hooks.
*/
export function useAgeAssurance() { export function useAgeAssurance() {
return useContext(AgeAssuranceStateContext) return useContext(AgeAssuranceStateContext)
} }
+6
View File
@@ -20,11 +20,17 @@ export function useAgeAssuranceState(): AgeAssuranceState {
const {config, state, data} = useAgeAssuranceDataContext() const {config, state, data} = useAgeAssuranceDataContext()
return useMemo(() => { return useMemo(() => {
/**
* This is where we control logged-out moderation prefs. It's all
* downstream of AA now.
*/
if (!hasSession) if (!hasSession)
return { return {
status: AgeAssuranceStatus.Unknown, status: AgeAssuranceStatus.Unknown,
access: AgeAssuranceAccess.Safe, access: AgeAssuranceAccess.Safe,
} }
// should never happen, but need to guard
if (!config) { if (!config) {
logger.warn('useAgeAssuranceState: missing config') logger.warn('useAgeAssuranceState: missing config')
return { return {
@@ -96,7 +96,6 @@ function Inner({style}: ViewStyleProp & {}) {
<DeviceLocationRequestDialog <DeviceLocationRequestDialog
control={locationControl} control={locationControl}
onLocationAcquired={props => { onLocationAcquired={props => {
// TODO test this
const access = computeAgeAssuranceRegionAccess( const access = computeAgeAssuranceRegionAccess(
props.geolocation, props.geolocation,
) )
@@ -63,7 +63,7 @@ export function AgeAssuranceRedirectDialog() {
const {_} = useLingui() const {_} = useLingui()
const control = useAgeAssuranceRedirectDialogControl() const control = useAgeAssuranceRedirectDialogControl()
// TODO for testing // for testing
// Dialog.useAutoOpen(control.control, 3e3) // Dialog.useAutoOpen(control.control, 3e3)
return ( return (
@@ -105,7 +105,6 @@ export function Inner({}: {optimisticState?: AgeAssuranceRedirectDialogState}) {
if (!agent.session) return if (!agent.session) return
if (unmounted.current) return if (unmounted.current) return
// TODO test
const data = await refetchAgeAssuranceServerState({agent}) const data = await refetchAgeAssuranceServerState({agent})
if (data?.state.status !== 'assured') { if (data?.state.status !== 'assured') {
+10 -4
View File
@@ -74,17 +74,23 @@ export function BirthDateSettingsDialog({
</Dialog.ScrollableInner> </Dialog.ScrollableInner>
) : ( ) : (
<Dialog.ScrollableInner <Dialog.ScrollableInner
label={_(msg`My Birthday`)} label={_(msg`You recently changed your birthday`)}
style={web({maxWidth: 400})}> style={web({maxWidth: 400})}>
<View style={[a.gap_sm]}> <View style={[a.gap_sm]}>
<Text style={[a.text_xl, a.font_semi_bold]}> <Text
style={[
a.text_xl,
a.font_semi_bold,
a.leading_snug,
{paddingRight: 32},
]}>
<Trans>You recently changed your birthday</Trans> <Trans>You recently changed your birthday</Trans>
</Text> </Text>
<Text <Text
style={[a.text_md, a.leading_snug, t.atoms.text_contrast_medium]}> style={[a.text_md, a.leading_snug, t.atoms.text_contrast_medium]}>
<Trans> <Trans>
There is a limit to how often you can change your birth date. There is a limit to how often you can change your birthday. You
You may need to wait a day or two before updating it again. may need to wait a day or two before updating it again.
</Trans> </Trans>
</Text> </Text>
</View> </View>
+1 -1
View File
@@ -2,7 +2,7 @@ import * as aaDebug from '#/ageAssurance/debug'
import {IS_DEV} from '#/env' import {IS_DEV} from '#/env'
import {type Geolocation} from '#/geolocation/types' import {type Geolocation} from '#/geolocation/types'
const localEnabled = true const localEnabled = false
export const enabled = IS_DEV && (localEnabled || aaDebug.geolocation) export const enabled = IS_DEV && (localEnabled || aaDebug.geolocation)
export const geolocation: Geolocation = aaDebug.geolocation ?? { export const geolocation: Geolocation = aaDebug.geolocation ?? {
countryCode: 'AU', countryCode: 'AU',
+1 -1
View File
@@ -36,7 +36,7 @@ export function useAccountSwitcher() {
// So we change the URL ourselves. The navigator will pick it up on remount. // So we change the URL ourselves. The navigator will pick it up on remount.
history.pushState(null, '', '/') history.pushState(null, '', '/')
} }
await resumeSession(account) await resumeSession(account, true)
logEvent('account:loggedIn', {logContext, withPassword: false}) logEvent('account:loggedIn', {logContext, withPassword: false})
Toast.show(_(msg`Signed in as @${account.handle}`)) Toast.show(_(msg`Signed in as @${account.handle}`))
} else { } else {
-2
View File
@@ -13,10 +13,8 @@ export enum LogContext {
FeedFeedback = 'feed-feedback', FeedFeedback = 'feed-feedback',
PostSource = 'post-source', PostSource = 'post-source',
AgeAssurance = 'age-assurance', AgeAssurance = 'age-assurance',
AgeAssuranceV2 = 'age-assurance-v2',
PolicyUpdate = 'policy-update', PolicyUpdate = 'policy-update',
Geolocation = 'geolocation', Geolocation = 'geolocation',
GeolocationV2 = 'geolocation-v2',
/** /**
* METRIC IS FOR INTERNAL USE ONLY, don't create any other loggers using this * METRIC IS FOR INTERNAL USE ONLY, don't create any other loggers using this
+1 -1
View File
@@ -45,7 +45,7 @@ export const ChooseAccountForm = ({
} }
try { try {
setPendingDid(account.did) setPendingDid(account.did)
await resumeSession(account) await resumeSession(account, true)
logEvent('account:loggedIn', { logEvent('account:loggedIn', {
logContext: 'ChooseAccountForm', logContext: 'ChooseAccountForm',
withPassword: false, withPassword: false,
+4
View File
@@ -74,6 +74,10 @@ export function usePreferencesQuery() {
}, },
select: useCallback( select: useCallback(
(data: UsePreferencesQueryResponse) => { (data: UsePreferencesQueryResponse) => {
/**
* Prefs are all downstream of age assurance now. For logged-out
* users, we override moderation prefs based on AA state.
*/
if (aa.state.access !== aa.Access.Full) { if (aa.state.access !== aa.Access.Full) {
data = { data = {
...data, ...data,
+6 -1
View File
@@ -185,6 +185,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
if (prevState.currentAgentState.did) { if (prevState.currentAgentState.did) {
clearAgeAssuranceDataForDid({did: prevState.currentAgentState.did}) clearAgeAssuranceDataForDid({did: prevState.currentAgentState.did})
} }
// reset onboarding flow on logout
onboardingDispatch({type: 'skip'}) onboardingDispatch({type: 'skip'})
}, },
[store, cancelPendingTask, onboardingDispatch], [store, cancelPendingTask, onboardingDispatch],
@@ -206,13 +207,14 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
) )
addSessionDebugLog({type: 'method:end', method: 'logout'}) addSessionDebugLog({type: 'method:end', method: 'logout'})
clearAgeAssuranceData() clearAgeAssuranceData()
// reset onboarding flow on logout
onboardingDispatch({type: 'skip'}) onboardingDispatch({type: 'skip'})
}, },
[store, cancelPendingTask, onboardingDispatch], [store, cancelPendingTask, onboardingDispatch],
) )
const resumeSession = React.useCallback<SessionApiContext['resumeSession']>( const resumeSession = React.useCallback<SessionApiContext['resumeSession']>(
async storedAccount => { async (storedAccount, isSwitchingAccounts = false) => {
addSessionDebugLog({ addSessionDebugLog({
type: 'method:start', type: 'method:start',
method: 'resumeSession', method: 'resumeSession',
@@ -233,7 +235,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
newAccount: account, newAccount: account,
}) })
addSessionDebugLog({type: 'method:end', method: 'resumeSession', account}) addSessionDebugLog({type: 'method:end', method: 'resumeSession', account})
if (isSwitchingAccounts) {
// reset onboarding flow on switch account
onboardingDispatch({type: 'skip'}) onboardingDispatch({type: 'skip'})
}
}, },
[store, onAgentSessionChange, cancelPendingTask, onboardingDispatch], [store, onAgentSessionChange, cancelPendingTask, onboardingDispatch],
) )
+4 -1
View File
@@ -38,7 +38,10 @@ export type SessionApiContext = {
logoutEveryAccount: ( logoutEveryAccount: (
logContext: LogEvents['account:loggedOut']['logContext'], logContext: LogEvents['account:loggedOut']['logContext'],
) => void ) => void
resumeSession: (account: SessionAccount) => Promise<void> resumeSession: (
account: SessionAccount,
isSwitchingAccounts?: boolean,
) => Promise<void>
removeAccount: (account: SessionAccount) => void removeAccount: (account: SessionAccount) => void
/** /**
* Calls `getSession` and updates select fields on the current account and * Calls `getSession` and updates select fields on the current account and