Fixes
This commit is contained in:
@@ -11,27 +11,32 @@ import {
|
|||||||
} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
||||||
import {IsAgeRestricted} from '#/components/ageAssurance/IsAgeRestricted'
|
import {IsAgeRestricted} from '#/components/ageAssurance/IsAgeRestricted'
|
||||||
import {Button, ButtonText} from '#/components/Button'
|
import {Button, ButtonText} from '#/components/Button'
|
||||||
|
import type * as Dialog from '#/components/Dialog'
|
||||||
import {Divider} from '#/components/Divider'
|
import {Divider} from '#/components/Divider'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
|
export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
|
||||||
|
const control = useDialogControl()
|
||||||
|
const {hasInitiated} = useAgeAssuranceContext()
|
||||||
return (
|
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 t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {hasInitiated} = useAgeAssuranceContext()
|
|
||||||
const control = useDialogControl()
|
|
||||||
|
|
||||||
return hasInitiated ? null : (
|
return (
|
||||||
<>
|
<>
|
||||||
<AgeAssuranceInitDialog control={control} />
|
|
||||||
|
|
||||||
<View style={style}>
|
<View style={style}>
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {useLingui} from '@lingui/react'
|
|||||||
import {useQueryClient} from '@tanstack/react-query'
|
import {useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {retry} from '#/lib/async/retry'
|
import {retry} from '#/lib/async/retry'
|
||||||
|
import {wait} from '#/lib/async/wait'
|
||||||
import {isNative} from '#/platform/detection'
|
import {isNative} from '#/platform/detection'
|
||||||
import {createAgeAssuranceQueryKey} from '#/state/age-assurance'
|
import {createAgeAssuranceQueryKey} from '#/state/age-assurance'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
@@ -18,8 +19,8 @@ import {Loader} from '#/components/Loader'
|
|||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export type AgeAssuranceRedirectDialogState = {
|
export type AgeAssuranceRedirectDialogState = {
|
||||||
status: 'success' | 'unknown'
|
result: 'success' | 'unknown'
|
||||||
did: string
|
actorDid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,27 +29,27 @@ export type AgeAssuranceRedirectDialogState = {
|
|||||||
*/
|
*/
|
||||||
export function parseAgeAssuranceRedirectDialogState(
|
export function parseAgeAssuranceRedirectDialogState(
|
||||||
state: {
|
state: {
|
||||||
status?: string
|
result?: string
|
||||||
did?: string
|
actorDid?: string
|
||||||
} = {},
|
} = {},
|
||||||
): AgeAssuranceRedirectDialogState | undefined {
|
): AgeAssuranceRedirectDialogState | undefined {
|
||||||
let status: AgeAssuranceRedirectDialogState['status'] = 'unknown'
|
let result: AgeAssuranceRedirectDialogState['result'] = 'unknown'
|
||||||
const did = state.did
|
const actorDid = state.actorDid
|
||||||
|
|
||||||
switch (state.status) {
|
switch (state.result) {
|
||||||
case 'success':
|
case 'success':
|
||||||
status = 'success'
|
result = 'success'
|
||||||
break
|
break
|
||||||
case 'unknown':
|
case 'unknown':
|
||||||
default:
|
default:
|
||||||
status = 'unknown'
|
result = 'unknown'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status && did) {
|
if (result && actorDid) {
|
||||||
return {
|
return {
|
||||||
status,
|
result,
|
||||||
did,
|
actorDid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,24 +94,27 @@ export function Inner({}: {optimisticState?: AgeAssuranceRedirectDialogState}) {
|
|||||||
|
|
||||||
polling.current = true
|
polling.current = true
|
||||||
|
|
||||||
retry(
|
wait(
|
||||||
5,
|
3e3,
|
||||||
() => true,
|
retry(
|
||||||
async () => {
|
5,
|
||||||
if (!agent.session) return
|
() => true,
|
||||||
if (unmounted.current) return
|
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') {
|
if (data.status !== 'assured') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Polling for age assurance state did not receive assured status`,
|
`Polling for age assurance state did not receive assured status`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
1e3,
|
1e3,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (!data) return
|
if (!data) return
|
||||||
|
|||||||
@@ -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 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 = `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`
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ export function useIntentHandler() {
|
|||||||
}
|
}
|
||||||
case 'age-assurance': {
|
case 'age-assurance': {
|
||||||
const state = parseAgeAssuranceRedirectDialogState({
|
const state = parseAgeAssuranceRedirectDialogState({
|
||||||
status: params.get('status') ?? undefined,
|
result: params.get('result') ?? undefined,
|
||||||
did: params.get('did') ?? undefined,
|
actorDid: params.get('actorDid') ?? undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO maybe handle invalid DID here
|
// TODO maybe handle invalid DID here
|
||||||
|
|||||||
Reference in New Issue
Block a user