Clean up intent dialog on native
This commit is contained in:
@@ -5,15 +5,17 @@ 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 {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'
|
||||||
import {atoms as a, web} from '#/alf'
|
import {atoms as a, useTheme, web} from '#/alf'
|
||||||
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
|
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
|
||||||
|
import {Button, ButtonText} from '#/components/Button'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
|
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
|
||||||
|
import {CircleInfo_Stroke2_Corner0_Rounded as ErrorIcon} from '#/components/icons/CircleInfo'
|
||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {Admonition} from '../Admonition'
|
|
||||||
|
|
||||||
export type AgeAssuranceRedirectDialogState = {
|
export type AgeAssuranceRedirectDialogState = {
|
||||||
status: 'success' | 'unknown'
|
status: 'success' | 'unknown'
|
||||||
@@ -59,6 +61,8 @@ export function AgeAssuranceRedirectDialog() {
|
|||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const control = useAgeAssuranceRedirectDialogControl()
|
const control = useAgeAssuranceRedirectDialogControl()
|
||||||
|
|
||||||
|
// Dialog.useAutoOpen(control.control, 1e3)
|
||||||
|
|
||||||
// TODO maybe handle invalid DID here
|
// TODO maybe handle invalid DID here
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -75,13 +79,14 @@ export function AgeAssuranceRedirectDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Inner({}: {optimisticState?: AgeAssuranceRedirectDialogState}) {
|
export function Inner({}: {optimisticState?: AgeAssuranceRedirectDialogState}) {
|
||||||
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const qc = useQueryClient()
|
const qc = useQueryClient()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const polling = useRef(false)
|
const polling = useRef(false)
|
||||||
const unmounted = useRef(false)
|
const unmounted = useRef(false)
|
||||||
const control = useAgeAssuranceRedirectDialogControl()
|
const control = useAgeAssuranceRedirectDialogControl()
|
||||||
const [error, setError] = useState<string>('')
|
const [error, setError] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (polling.current) return
|
if (polling.current) return
|
||||||
@@ -119,21 +124,17 @@ export function Inner({}: {optimisticState?: AgeAssuranceRedirectDialogState}) {
|
|||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
if (unmounted.current) return
|
if (unmounted.current) return
|
||||||
setError(
|
setError(true)
|
||||||
_(
|
|
||||||
msg`We were unable to verify your age assurance status. But don't worry! Your account should be updated soon.`,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unmounted.current = true
|
unmounted.current = true
|
||||||
}
|
}
|
||||||
}, [_, agent, qc, control])
|
}, [agent, qc, control])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<View style={[a.align_start]}>
|
<View style={[a.align_start, a.w_full]}>
|
||||||
<AgeAssuranceBadge />
|
<AgeAssuranceBadge />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
@@ -141,27 +142,44 @@ export function Inner({}: {optimisticState?: AgeAssuranceRedirectDialogState}) {
|
|||||||
a.flex_row,
|
a.flex_row,
|
||||||
a.justify_between,
|
a.justify_between,
|
||||||
a.align_center,
|
a.align_center,
|
||||||
a.gap_md,
|
a.gap_sm,
|
||||||
a.pt_lg,
|
a.pt_lg,
|
||||||
a.pb_md,
|
a.pb_md,
|
||||||
]}>
|
]}>
|
||||||
|
{error && <ErrorIcon size="md" fill={t.palette.negative_500} />}
|
||||||
|
|
||||||
<Text style={[a.text_xl, a.font_heavy]}>
|
<Text style={[a.text_xl, a.font_heavy]}>
|
||||||
<Trans>Verifying</Trans>
|
{error ? <Trans>Unknown status</Trans> : <Trans>Verifying</Trans>}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
{!error && <Loader size="md" />}
|
{!error && <Loader size="md" />}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<Text style={[a.text_md, a.leading_snug]}>
|
<Text style={[a.text_md, a.leading_snug]}>
|
||||||
|
{error ? (
|
||||||
|
<Trans>
|
||||||
|
We were unable to verify your age assurance status. But don't
|
||||||
|
worry! Your account should be updated soon.
|
||||||
|
</Trans>
|
||||||
|
) : (
|
||||||
<Trans>
|
<Trans>
|
||||||
We're confirming your status with our servers. This dialog should
|
We're confirming your status with our servers. This dialog should
|
||||||
close in a few seconds.
|
close in a few seconds.
|
||||||
</Trans>
|
</Trans>
|
||||||
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
{error && (
|
{error && isNative && (
|
||||||
<View style={[a.pt_md]}>
|
<View style={[a.w_full, a.pt_lg]}>
|
||||||
<Admonition type="error">{error}</Admonition>
|
<Button
|
||||||
|
label={_(msg`Close`)}
|
||||||
|
size="large"
|
||||||
|
variant="solid"
|
||||||
|
color="secondary">
|
||||||
|
<ButtonText>
|
||||||
|
<Trans>Close</Trans>
|
||||||
|
</ButtonText>
|
||||||
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user