diff --git a/src/ageAssurance/components/NoAccessScreen.tsx b/src/ageAssurance/components/NoAccessScreen.tsx index 6c7c36a412..0becba529c 100644 --- a/src/ageAssurance/components/NoAccessScreen.tsx +++ b/src/ageAssurance/components/NoAccessScreen.tsx @@ -323,7 +323,6 @@ function AccessSection() { { - // TODO test this const access = computeAgeAssuranceRegionAccess( props.geolocation, ) diff --git a/src/ageAssurance/data.tsx b/src/ageAssurance/data.tsx index 1e21669285..e60c495e8f 100644 --- a/src/ageAssurance/data.tsx +++ b/src/ageAssurance/data.tsx @@ -163,7 +163,7 @@ export function createServerStateQueryKey({did}: {did: string}) { export async function getServerState({agent}: {agent: AtpAgent}) { if (debug.enabled && 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) { logger.error(`getServerState: missing geolocation countryCode`) return @@ -273,6 +273,7 @@ export function useServerStateQuery() { */ useEffect(() => { return focusManager.subscribe(() => { + // logged out if (!did) return const isFocused = focusManager.isFocused() @@ -290,6 +291,7 @@ export function useServerStateQuery() { }), ) + // only refetch when needed if (isAssured || !isAArequired) return refetch() @@ -417,7 +419,8 @@ export function useOtherRequiredDataQuery() { * Helper to prefetch all age assurance data. */ 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, prefetchServerState({agent}), prefetchOtherRequiredData({agent}), diff --git a/src/ageAssurance/index.tsx b/src/ageAssurance/index.tsx index 23d3a30586..1c815a755b 100644 --- a/src/ageAssurance/index.tsx +++ b/src/ageAssurance/index.tsx @@ -14,8 +14,6 @@ import { AgeAssuranceStatus, } from '#/ageAssurance/types' -export {logger} from '#/ageAssurance/logger' -// TODO just import from file export { prefetchConfig as prefetchAgeAssuranceConfig, prefetchAgeAssuranceData, @@ -23,6 +21,7 @@ export { usePatchOtherRequiredData as usePatchAgeAssuranceOtherRequiredData, usePatchServerState as usePatchAgeAssuranceServerState, } from '#/ageAssurance/data' +export {logger} from '#/ageAssurance/logger' const AgeAssuranceStateContext = createContext<{ 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() { return useContext(AgeAssuranceStateContext) } diff --git a/src/ageAssurance/state.ts b/src/ageAssurance/state.ts index a88fbca765..cc8b60ac52 100644 --- a/src/ageAssurance/state.ts +++ b/src/ageAssurance/state.ts @@ -20,11 +20,17 @@ export function useAgeAssuranceState(): AgeAssuranceState { const {config, state, data} = useAgeAssuranceDataContext() return useMemo(() => { + /** + * This is where we control logged-out moderation prefs. It's all + * downstream of AA now. + */ if (!hasSession) return { status: AgeAssuranceStatus.Unknown, access: AgeAssuranceAccess.Safe, } + + // should never happen, but need to guard if (!config) { logger.warn('useAgeAssuranceState: missing config') return { diff --git a/src/components/ageAssurance/AgeAssuranceAccountCard.tsx b/src/components/ageAssurance/AgeAssuranceAccountCard.tsx index aff2f09c0c..a75e75d133 100644 --- a/src/components/ageAssurance/AgeAssuranceAccountCard.tsx +++ b/src/components/ageAssurance/AgeAssuranceAccountCard.tsx @@ -96,7 +96,6 @@ function Inner({style}: ViewStyleProp & {}) { { - // TODO test this const access = computeAgeAssuranceRegionAccess( props.geolocation, ) diff --git a/src/components/ageAssurance/AgeAssuranceRedirectDialog.tsx b/src/components/ageAssurance/AgeAssuranceRedirectDialog.tsx index ebc873da14..a28b1aeac9 100644 --- a/src/components/ageAssurance/AgeAssuranceRedirectDialog.tsx +++ b/src/components/ageAssurance/AgeAssuranceRedirectDialog.tsx @@ -63,7 +63,7 @@ export function AgeAssuranceRedirectDialog() { const {_} = useLingui() const control = useAgeAssuranceRedirectDialogControl() - // TODO for testing + // for testing // Dialog.useAutoOpen(control.control, 3e3) return ( @@ -105,7 +105,6 @@ export function Inner({}: {optimisticState?: AgeAssuranceRedirectDialogState}) { if (!agent.session) return if (unmounted.current) return - // TODO test const data = await refetchAgeAssuranceServerState({agent}) if (data?.state.status !== 'assured') { diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx index bf4af528a3..6294efec6d 100644 --- a/src/components/dialogs/BirthDateSettings.tsx +++ b/src/components/dialogs/BirthDateSettings.tsx @@ -74,17 +74,23 @@ export function BirthDateSettingsDialog({ ) : ( - + You recently changed your birthday - There is a limit to how often you can change your birth date. - You may need to wait a day or two before updating it again. + There is a limit to how often you can change your birthday. You + may need to wait a day or two before updating it again. diff --git a/src/geolocation/debug.ts b/src/geolocation/debug.ts index 3fc2bfc16f..58fe05e6f2 100644 --- a/src/geolocation/debug.ts +++ b/src/geolocation/debug.ts @@ -2,7 +2,7 @@ import * as aaDebug from '#/ageAssurance/debug' import {IS_DEV} from '#/env' import {type Geolocation} from '#/geolocation/types' -const localEnabled = true +const localEnabled = false export const enabled = IS_DEV && (localEnabled || aaDebug.geolocation) export const geolocation: Geolocation = aaDebug.geolocation ?? { countryCode: 'AU', diff --git a/src/lib/hooks/useAccountSwitcher.ts b/src/lib/hooks/useAccountSwitcher.ts index c1dbbc793c..b8fe0280dd 100644 --- a/src/lib/hooks/useAccountSwitcher.ts +++ b/src/lib/hooks/useAccountSwitcher.ts @@ -36,7 +36,7 @@ export function useAccountSwitcher() { // So we change the URL ourselves. The navigator will pick it up on remount. history.pushState(null, '', '/') } - await resumeSession(account) + await resumeSession(account, true) logEvent('account:loggedIn', {logContext, withPassword: false}) Toast.show(_(msg`Signed in as @${account.handle}`)) } else { diff --git a/src/logger/types.ts b/src/logger/types.ts index f9b428739e..19e12c5045 100644 --- a/src/logger/types.ts +++ b/src/logger/types.ts @@ -13,10 +13,8 @@ export enum LogContext { FeedFeedback = 'feed-feedback', PostSource = 'post-source', AgeAssurance = 'age-assurance', - AgeAssuranceV2 = 'age-assurance-v2', PolicyUpdate = 'policy-update', Geolocation = 'geolocation', - GeolocationV2 = 'geolocation-v2', /** * METRIC IS FOR INTERNAL USE ONLY, don't create any other loggers using this diff --git a/src/screens/Login/ChooseAccountForm.tsx b/src/screens/Login/ChooseAccountForm.tsx index 9398a7d9ac..95a7738848 100644 --- a/src/screens/Login/ChooseAccountForm.tsx +++ b/src/screens/Login/ChooseAccountForm.tsx @@ -45,7 +45,7 @@ export const ChooseAccountForm = ({ } try { setPendingDid(account.did) - await resumeSession(account) + await resumeSession(account, true) logEvent('account:loggedIn', { logContext: 'ChooseAccountForm', withPassword: false, diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index b457e89e8a..0cf6ab5469 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -74,6 +74,10 @@ export function usePreferencesQuery() { }, select: useCallback( (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) { data = { ...data, diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index b5a6c7f6b7..4d4cb67282 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -185,6 +185,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { if (prevState.currentAgentState.did) { clearAgeAssuranceDataForDid({did: prevState.currentAgentState.did}) } + // reset onboarding flow on logout onboardingDispatch({type: 'skip'}) }, [store, cancelPendingTask, onboardingDispatch], @@ -206,13 +207,14 @@ export function Provider({children}: React.PropsWithChildren<{}>) { ) addSessionDebugLog({type: 'method:end', method: 'logout'}) clearAgeAssuranceData() + // reset onboarding flow on logout onboardingDispatch({type: 'skip'}) }, [store, cancelPendingTask, onboardingDispatch], ) const resumeSession = React.useCallback( - async storedAccount => { + async (storedAccount, isSwitchingAccounts = false) => { addSessionDebugLog({ type: 'method:start', method: 'resumeSession', @@ -233,7 +235,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) { newAccount: account, }) addSessionDebugLog({type: 'method:end', method: 'resumeSession', account}) - onboardingDispatch({type: 'skip'}) + if (isSwitchingAccounts) { + // reset onboarding flow on switch account + onboardingDispatch({type: 'skip'}) + } }, [store, onAgentSessionChange, cancelPendingTask, onboardingDispatch], ) diff --git a/src/state/session/types.ts b/src/state/session/types.ts index 4621b4f04b..2c1da187cb 100644 --- a/src/state/session/types.ts +++ b/src/state/session/types.ts @@ -38,7 +38,10 @@ export type SessionApiContext = { logoutEveryAccount: ( logContext: LogEvents['account:loggedOut']['logContext'], ) => void - resumeSession: (account: SessionAccount) => Promise + resumeSession: ( + account: SessionAccount, + isSwitchingAccounts?: boolean, + ) => Promise removeAccount: (account: SessionAccount) => void /** * Calls `getSession` and updates select fields on the current account and