This commit is contained in:
Eric Bailey
2025-07-09 21:30:43 -05:00
parent a87e0d0769
commit 6f7cf06162
4 changed files with 48 additions and 39 deletions
@@ -11,27 +11,32 @@ import {
} from '#/components/ageAssurance/AgeAssuranceInitDialog'
import {IsAgeRestricted} from '#/components/ageAssurance/IsAgeRestricted'
import {Button, ButtonText} from '#/components/Button'
import type * as Dialog from '#/components/Dialog'
import {Divider} from '#/components/Divider'
import {Text} from '#/components/Typography'
export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
const control = useDialogControl()
const {hasInitiated} = useAgeAssuranceContext()
return (
<IsAgeRestricted.True>
<Inner style={style} />
</IsAgeRestricted.True>
<>
<IsAgeRestricted.True>
{!hasInitiated && <Inner style={style} control={control} />}
<AgeAssuranceInitDialog control={control} />
</IsAgeRestricted.True>
</>
)
}
function Inner({style}: ViewStyleProp & {}) {
function Inner({
style,
control,
}: ViewStyleProp & {control: Dialog.DialogControlProps}) {
const t = useTheme()
const {_} = useLingui()
const {hasInitiated} = useAgeAssuranceContext()
const control = useDialogControl()
return hasInitiated ? null : (
return (
<>
<AgeAssuranceInitDialog control={control} />
<View style={style}>
<View
style={[
@@ -5,6 +5,7 @@ import {useLingui} from '@lingui/react'
import {useQueryClient} from '@tanstack/react-query'
import {retry} from '#/lib/async/retry'
import {wait} from '#/lib/async/wait'
import {isNative} from '#/platform/detection'
import {createAgeAssuranceQueryKey} from '#/state/age-assurance'
import {useAgent} from '#/state/session'
@@ -18,8 +19,8 @@ import {Loader} from '#/components/Loader'
import {Text} from '#/components/Typography'
export type AgeAssuranceRedirectDialogState = {
status: 'success' | 'unknown'
did: string
result: 'success' | 'unknown'
actorDid: string
}
/**
@@ -28,27 +29,27 @@ export type AgeAssuranceRedirectDialogState = {
*/
export function parseAgeAssuranceRedirectDialogState(
state: {
status?: string
did?: string
result?: string
actorDid?: string
} = {},
): AgeAssuranceRedirectDialogState | undefined {
let status: AgeAssuranceRedirectDialogState['status'] = 'unknown'
const did = state.did
let result: AgeAssuranceRedirectDialogState['result'] = 'unknown'
const actorDid = state.actorDid
switch (state.status) {
switch (state.result) {
case 'success':
status = 'success'
result = 'success'
break
case 'unknown':
default:
status = 'unknown'
result = 'unknown'
break
}
if (status && did) {
if (result && actorDid) {
return {
status,
did,
result,
actorDid,
}
}
}
@@ -93,24 +94,27 @@ export function Inner({}: {optimisticState?: AgeAssuranceRedirectDialogState}) {
polling.current = true
retry(
5,
() => true,
async () => {
if (!agent.session) return
if (unmounted.current) return
wait(
3e3,
retry(
5,
() => true,
async () => {
if (!agent.session) return
if (unmounted.current) return
const {data} = await agent.app.bsky.unspecced.getAgeAssuranceState()
const {data} = await agent.app.bsky.unspecced.getAgeAssuranceState()
if (data.status !== 'assured') {
throw new Error(
`Polling for age assurance state did not receive assured status`,
)
}
if (data.status !== 'assured') {
throw new Error(
`Polling for age assurance state did not receive assured status`,
)
}
return data
},
1e3,
return data
},
1e3,
),
)
.then(data => {
if (!data) return
+1 -1
View File
@@ -207,4 +207,4 @@ export const PUBLIC_APPVIEW_DID = 'did:web:api.bsky.app'
export const PUBLIC_STAGING_APPVIEW_DID = 'did:web:api.staging.bsky.dev'
export const DEV_ENV_APPVIEW = `http://localhost:2584` // always the same
export const DEV_ENV_APPVIEW_DID = `did:plc:lmynpbfp7bbyc4pz2xjdtzsh` // get this from `localhost:2581`
export const DEV_ENV_APPVIEW_DID = `did:plc:zkrndrc5vqjfn32cr4qya7c5` // get this from `localhost:2581`
+2 -2
View File
@@ -74,8 +74,8 @@ export function useIntentHandler() {
}
case 'age-assurance': {
const state = parseAgeAssuranceRedirectDialogState({
status: params.get('status') ?? undefined,
did: params.get('did') ?? undefined,
result: params.get('result') ?? undefined,
actorDid: params.get('actorDid') ?? undefined,
})
// TODO maybe handle invalid DID here