Fix prettier formatting in AgeAssuranceAccountCard
This commit is contained in:
@@ -9,8 +9,8 @@ import {AgeAssuranceAppealDialog} from '#/components/ageAssurance/AgeAssuranceAp
|
|||||||
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
|
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
|
||||||
import {AgeAssuranceConfigUnavailableError} from '#/components/ageAssurance/AgeAssuranceErrors'
|
import {AgeAssuranceConfigUnavailableError} from '#/components/ageAssurance/AgeAssuranceErrors'
|
||||||
import {
|
import {
|
||||||
AgeAssuranceInitDialog,
|
AgeAssuranceInitDialog,
|
||||||
useDialogControl,
|
useDialogControl,
|
||||||
} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
||||||
import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy'
|
import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy'
|
||||||
import {Button, ButtonText} from '#/components/Button'
|
import {Button, ButtonText} from '#/components/Button'
|
||||||
@@ -25,313 +25,271 @@ import {useComputeAgeAssuranceRegionAccess} from '#/ageAssurance/useComputeAgeAs
|
|||||||
import {useAnalytics} from '#/analytics'
|
import {useAnalytics} from '#/analytics'
|
||||||
import {IS_NATIVE} from '#/env'
|
import {IS_NATIVE} from '#/env'
|
||||||
import {
|
import {
|
||||||
type Geolocation,
|
type Geolocation,
|
||||||
useDeviceGeolocationApi,
|
useDeviceGeolocationApi,
|
||||||
useGeolocation,
|
useGeolocation,
|
||||||
} from '#/geolocation'
|
} from '#/geolocation'
|
||||||
import {USRegionNameToRegionCode} from '#/geolocation/util'
|
import {USRegionNameToRegionCode} from '#/geolocation/util'
|
||||||
import {device, useStorage} from '#/storage'
|
import {device, useStorage} from '#/storage'
|
||||||
|
|
||||||
const USRegionCodeToRegionName: {[regionCode: string]: string} =
|
const USRegionCodeToRegionName: {[regionCode: string]: string} =
|
||||||
Object.fromEntries(
|
Object.fromEntries(
|
||||||
Object.entries(USRegionNameToRegionCode).map(([name, code]) => [
|
Object.entries(USRegionNameToRegionCode).map(([name, code]) => [
|
||||||
code,
|
code,
|
||||||
name,
|
name,
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
|
|
||||||
function formatRegion(
|
function formatRegion(
|
||||||
geolocation: Geolocation,
|
geolocation: Geolocation,
|
||||||
appLang: string,
|
appLang: string,
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
const {countryCode, regionCode} = geolocation
|
const {countryCode, regionCode} = geolocation
|
||||||
if (!countryCode) return undefined
|
if (!countryCode) return undefined
|
||||||
const country = regionName(countryCode, appLang)
|
const country = regionName(countryCode, appLang)
|
||||||
// If `regionName` couldn't resolve a real name and fell through to the raw
|
// If `regionName` couldn't resolve a real name and fell through to the raw
|
||||||
// code, we'd rather show nothing than a bare ISO code in the prose.
|
// code, we'd rather show nothing than a bare ISO code in the prose.
|
||||||
if (country === countryCode) return undefined
|
if (country === countryCode) return undefined
|
||||||
if (regionCode && countryCode === 'US') {
|
if (regionCode && countryCode === 'US') {
|
||||||
const state = USRegionCodeToRegionName[regionCode]
|
const state = USRegionCodeToRegionName[regionCode]
|
||||||
if (state) return `${state}, ${country}`
|
if (state) return `${state}, ${country}`
|
||||||
}
|
}
|
||||||
return country
|
return country
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AgeAssuranceAccountCard({style}: ViewStyleProp & {}) {
|
export function AgeAssuranceAccountCard({style}: ViewStyleProp & {}) {
|
||||||
const aa = useAgeAssurance()
|
const aa = useAgeAssurance()
|
||||||
if (aa.state.access === aa.Access.Full) return null
|
if (aa.state.access === aa.Access.Full) return null
|
||||||
if (aa.state.error === 'config') {
|
if (aa.state.error === 'config') {
|
||||||
return (
|
return (
|
||||||
<View style={style}>
|
<View style={style}>
|
||||||
<AgeAssuranceConfigUnavailableError />
|
<AgeAssuranceConfigUnavailableError />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return <Inner style={style} />
|
return <Inner style={style} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function Inner({style}: ViewStyleProp & {}) {
|
function Inner({style}: ViewStyleProp & {}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {t: l, i18n} = useLingui()
|
const {t: l, i18n} = useLingui()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
const control = useDialogControl()
|
const control = useDialogControl()
|
||||||
const appealControl = Dialog.useDialogControl()
|
const appealControl = Dialog.useDialogControl()
|
||||||
const getTimeAgo = useGetTimeAgo()
|
const getTimeAgo = useGetTimeAgo()
|
||||||
const {gtPhone} = useBreakpoints()
|
const {gtPhone} = useBreakpoints()
|
||||||
|
|
||||||
const copy = useAgeAssuranceCopy()
|
const copy = useAgeAssuranceCopy()
|
||||||
const aa = useAgeAssurance()
|
const aa = useAgeAssurance()
|
||||||
const {status, lastInitiatedAt} = aa.state
|
const {status, lastInitiatedAt} = aa.state
|
||||||
const isBlocked = status === aa.Status.Blocked
|
const isBlocked = status === aa.Status.Blocked
|
||||||
const hasInitiated = !!lastInitiatedAt
|
const hasInitiated = !!lastInitiatedAt
|
||||||
const hasCompletedFlow = status === aa.Status.Assured
|
const hasCompletedFlow = status === aa.Status.Assured
|
||||||
const timeAgo = lastInitiatedAt
|
const timeAgo = lastInitiatedAt
|
||||||
? getTimeAgo(lastInitiatedAt, new Date())
|
? getTimeAgo(lastInitiatedAt, new Date())
|
||||||
: null
|
: null
|
||||||
const diff = lastInitiatedAt
|
const diff = lastInitiatedAt
|
||||||
? dateDiff(lastInitiatedAt, new Date(), 'down')
|
? dateDiff(lastInitiatedAt, new Date(), 'down')
|
||||||
: null
|
: null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AgeAssuranceInitDialog control={control} />
|
<AgeAssuranceInitDialog control={control} />
|
||||||
<AgeAssuranceAppealDialog control={appealControl} />
|
<AgeAssuranceAppealDialog control={appealControl} />
|
||||||
|
|
||||||
<View style={style}>
|
<View style={style}>
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[a.p_lg, a.rounded_md, a.border, t.atoms.border_contrast_low]}>
|
||||||
a.p_lg,
|
<View
|
||||||
a.rounded_md,
|
style={[
|
||||||
a.border,
|
a.flex_row,
|
||||||
t.atoms.border_contrast_low,
|
a.justify_between,
|
||||||
]}>
|
a.align_center,
|
||||||
<View
|
a.gap_lg,
|
||||||
style={[
|
a.pb_md,
|
||||||
a.flex_row,
|
a.z_10,
|
||||||
a.justify_between,
|
]}>
|
||||||
a.align_center,
|
<View style={[a.align_start]}>
|
||||||
a.gap_lg,
|
<AgeAssuranceBadge />
|
||||||
a.pb_md,
|
|
||||||
a.z_10,
|
|
||||||
]}>
|
|
||||||
<View style={[a.align_start]}>
|
|
||||||
<AgeAssuranceBadge />
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={[a.pb_md, a.gap_sm]}>
|
|
||||||
<Text style={[a.text_sm, a.leading_snug]}>
|
|
||||||
{copy.notice}
|
|
||||||
</Text>
|
|
||||||
{hasCompletedFlow && (
|
|
||||||
<Text style={[a.text_sm, a.leading_snug]}>
|
|
||||||
<Trans>
|
|
||||||
If you are 18 years of age or older and want
|
|
||||||
to try again, click the button below and use
|
|
||||||
a different verification method if one is
|
|
||||||
available in your region. If you have
|
|
||||||
questions or concerns,{' '}
|
|
||||||
<InlineLinkText
|
|
||||||
label={l`Contact our support team`}
|
|
||||||
{...createStaticClick(() => {
|
|
||||||
appealControl.open()
|
|
||||||
})}>
|
|
||||||
our support team can help.
|
|
||||||
</InlineLinkText>
|
|
||||||
</Trans>
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<RegionNotice />
|
|
||||||
</View>
|
|
||||||
|
|
||||||
{isBlocked ? (
|
|
||||||
<Admonition type="warning">
|
|
||||||
<Trans>
|
|
||||||
You are currently unable to access Bluesky's Age
|
|
||||||
Assurance flow. Please{' '}
|
|
||||||
<InlineLinkText
|
|
||||||
label={l`Contact our moderation team`}
|
|
||||||
{...createStaticClick(() => {
|
|
||||||
appealControl.open()
|
|
||||||
ax.metric(
|
|
||||||
'ageAssurance:appealDialogOpen',
|
|
||||||
{},
|
|
||||||
)
|
|
||||||
})}>
|
|
||||||
contact our moderation team
|
|
||||||
</InlineLinkText>{' '}
|
|
||||||
if you believe this is an error.
|
|
||||||
</Trans>
|
|
||||||
</Admonition>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Divider />
|
|
||||||
<View
|
|
||||||
style={[
|
|
||||||
a.pt_md,
|
|
||||||
gtPhone
|
|
||||||
? [
|
|
||||||
a.flex_row_reverse,
|
|
||||||
a.gap_xl,
|
|
||||||
a.justify_between,
|
|
||||||
a.align_center,
|
|
||||||
]
|
|
||||||
: [a.gap_md],
|
|
||||||
]}>
|
|
||||||
<Button
|
|
||||||
label={l`Verify now`}
|
|
||||||
size="small"
|
|
||||||
variant="solid"
|
|
||||||
color={
|
|
||||||
hasInitiated ? 'secondary' : 'primary'
|
|
||||||
}
|
|
||||||
onPress={() => {
|
|
||||||
control.open()
|
|
||||||
ax.metric(
|
|
||||||
'ageAssurance:initDialogOpen',
|
|
||||||
{
|
|
||||||
hasInitiatedPreviously:
|
|
||||||
hasInitiated,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}}>
|
|
||||||
<ButtonText>
|
|
||||||
{hasInitiated ? (
|
|
||||||
<Trans>Verify again</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>Verify now</Trans>
|
|
||||||
)}
|
|
||||||
</ButtonText>
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
{lastInitiatedAt && timeAgo && diff ? (
|
|
||||||
<Text
|
|
||||||
style={[
|
|
||||||
a.text_sm,
|
|
||||||
a.italic,
|
|
||||||
t.atoms.text_contrast_medium,
|
|
||||||
]}
|
|
||||||
title={i18n.date(lastInitiatedAt, {
|
|
||||||
dateStyle: 'medium',
|
|
||||||
timeStyle: 'medium',
|
|
||||||
})}>
|
|
||||||
{diff.value === 0 ? (
|
|
||||||
<Trans>
|
|
||||||
Last initiated just now
|
|
||||||
</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>
|
|
||||||
Last initiated {timeAgo} ago
|
|
||||||
</Trans>
|
|
||||||
)}
|
|
||||||
</Text>
|
|
||||||
) : (
|
|
||||||
<Text
|
|
||||||
style={[
|
|
||||||
a.text_sm,
|
|
||||||
a.italic,
|
|
||||||
t.atoms.text_contrast_medium,
|
|
||||||
]}>
|
|
||||||
<Trans>
|
|
||||||
Age assurance only takes a few
|
|
||||||
minutes
|
|
||||||
</Trans>
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
</>
|
</View>
|
||||||
)
|
|
||||||
|
<View style={[a.pb_md, a.gap_sm]}>
|
||||||
|
<Text style={[a.text_sm, a.leading_snug]}>{copy.notice}</Text>
|
||||||
|
{hasCompletedFlow && (
|
||||||
|
<Text style={[a.text_sm, a.leading_snug]}>
|
||||||
|
<Trans>
|
||||||
|
If you are 18 years of age or older and want to try again,
|
||||||
|
click the button below and use a different verification method
|
||||||
|
if one is available in your region. If you have questions or
|
||||||
|
concerns,{' '}
|
||||||
|
<InlineLinkText
|
||||||
|
label={l`Contact our support team`}
|
||||||
|
{...createStaticClick(() => {
|
||||||
|
appealControl.open()
|
||||||
|
})}>
|
||||||
|
our support team can help.
|
||||||
|
</InlineLinkText>
|
||||||
|
</Trans>
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<RegionNotice />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{isBlocked ? (
|
||||||
|
<Admonition type="warning">
|
||||||
|
<Trans>
|
||||||
|
You are currently unable to access Bluesky's Age Assurance flow.
|
||||||
|
Please{' '}
|
||||||
|
<InlineLinkText
|
||||||
|
label={l`Contact our moderation team`}
|
||||||
|
{...createStaticClick(() => {
|
||||||
|
appealControl.open()
|
||||||
|
ax.metric('ageAssurance:appealDialogOpen', {})
|
||||||
|
})}>
|
||||||
|
contact our moderation team
|
||||||
|
</InlineLinkText>{' '}
|
||||||
|
if you believe this is an error.
|
||||||
|
</Trans>
|
||||||
|
</Admonition>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Divider />
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.pt_md,
|
||||||
|
gtPhone
|
||||||
|
? [
|
||||||
|
a.flex_row_reverse,
|
||||||
|
a.gap_xl,
|
||||||
|
a.justify_between,
|
||||||
|
a.align_center,
|
||||||
|
]
|
||||||
|
: [a.gap_md],
|
||||||
|
]}>
|
||||||
|
<Button
|
||||||
|
label={l`Verify now`}
|
||||||
|
size="small"
|
||||||
|
variant="solid"
|
||||||
|
color={hasInitiated ? 'secondary' : 'primary'}
|
||||||
|
onPress={() => {
|
||||||
|
control.open()
|
||||||
|
ax.metric('ageAssurance:initDialogOpen', {
|
||||||
|
hasInitiatedPreviously: hasInitiated,
|
||||||
|
})
|
||||||
|
}}>
|
||||||
|
<ButtonText>
|
||||||
|
{hasInitiated ? (
|
||||||
|
<Trans>Verify again</Trans>
|
||||||
|
) : (
|
||||||
|
<Trans>Verify now</Trans>
|
||||||
|
)}
|
||||||
|
</ButtonText>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{lastInitiatedAt && timeAgo && diff ? (
|
||||||
|
<Text
|
||||||
|
style={[a.text_sm, a.italic, t.atoms.text_contrast_medium]}
|
||||||
|
title={i18n.date(lastInitiatedAt, {
|
||||||
|
dateStyle: 'medium',
|
||||||
|
timeStyle: 'medium',
|
||||||
|
})}>
|
||||||
|
{diff.value === 0 ? (
|
||||||
|
<Trans>Last initiated just now</Trans>
|
||||||
|
) : (
|
||||||
|
<Trans>Last initiated {timeAgo} ago</Trans>
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
style={[a.text_sm, a.italic, t.atoms.text_contrast_medium]}>
|
||||||
|
<Trans>Age assurance only takes a few minutes</Trans>
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function RegionNotice() {
|
function RegionNotice() {
|
||||||
const {t: l, i18n} = useLingui()
|
const {t: l, i18n} = useLingui()
|
||||||
const aa = useAgeAssurance()
|
const aa = useAgeAssurance()
|
||||||
const geolocation = useGeolocation()
|
const geolocation = useGeolocation()
|
||||||
const [deviceGeolocation] = useStorage(device, ['deviceGeolocation'])
|
const [deviceGeolocation] = useStorage(device, ['deviceGeolocation'])
|
||||||
const {setDeviceGeolocation} = useDeviceGeolocationApi()
|
const {setDeviceGeolocation} = useDeviceGeolocationApi()
|
||||||
const computeAgeAssuranceRegionAccess = useComputeAgeAssuranceRegionAccess()
|
const computeAgeAssuranceRegionAccess = useComputeAgeAssuranceRegionAccess()
|
||||||
const locationControl = Dialog.useDialogControl()
|
const locationControl = Dialog.useDialogControl()
|
||||||
|
|
||||||
const region = formatRegion(geolocation, i18n.locale)
|
const region = formatRegion(geolocation, i18n.locale)
|
||||||
const isGPS = !!deviceGeolocation?.countryCode
|
const isGPS = !!deviceGeolocation?.countryCode
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{IS_NATIVE && (
|
{IS_NATIVE && (
|
||||||
<DeviceLocationRequestDialog
|
<DeviceLocationRequestDialog
|
||||||
control={locationControl}
|
control={locationControl}
|
||||||
onLocationAcquired={props => {
|
onLocationAcquired={props => {
|
||||||
const access = computeAgeAssuranceRegionAccess(
|
const access = computeAgeAssuranceRegionAccess(props.geolocation)
|
||||||
props.geolocation,
|
if (access !== aa.Access.Full) {
|
||||||
)
|
props.disableDialogAction()
|
||||||
if (access !== aa.Access.Full) {
|
props.setDialogError(
|
||||||
props.disableDialogAction()
|
l`We're sorry, but based on your device's location, you are currently located in a region that requires age assurance.`,
|
||||||
props.setDialogError(
|
)
|
||||||
l`We're sorry, but based on your device's location, you are currently located in a region that requires age assurance.`,
|
} else {
|
||||||
)
|
props.closeDialog(() => {
|
||||||
} else {
|
// set this after close!
|
||||||
props.closeDialog(() => {
|
setDeviceGeolocation(props.geolocation)
|
||||||
// set this after close!
|
Toast.show(l`Thanks! You're all set.`, {
|
||||||
setDeviceGeolocation(props.geolocation)
|
type: 'success',
|
||||||
Toast.show(l`Thanks! You're all set.`, {
|
})
|
||||||
type: 'success',
|
})
|
||||||
})
|
}
|
||||||
})
|
}}
|
||||||
}
|
/>
|
||||||
}}
|
)}
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{region && (
|
{region && (
|
||||||
<Text style={[a.text_sm, a.leading_snug]}>
|
<Text style={[a.text_sm, a.leading_snug]}>
|
||||||
{isGPS ? (
|
{isGPS ? (
|
||||||
<Trans>
|
<Trans>
|
||||||
Based on your device's location, we think you're in{' '}
|
Based on your device's location, we think you're in{' '}
|
||||||
<Text style={[a.text_sm, a.font_bold]}>
|
<Text style={[a.text_sm, a.font_bold]}>{region}</Text>. Some
|
||||||
{region}
|
features are limited because of regional age laws.
|
||||||
</Text>
|
</Trans>
|
||||||
. Some features are limited because of regional age
|
) : (
|
||||||
laws.
|
<Trans>
|
||||||
</Trans>
|
Based on your network, we think you're in{' '}
|
||||||
) : (
|
<Text style={[a.text_sm, a.font_bold]}>{region}</Text>. Some
|
||||||
<Trans>
|
features are limited because of regional age laws.
|
||||||
Based on your network, we think you're in{' '}
|
</Trans>
|
||||||
<Text style={[a.text_sm, a.font_bold]}>
|
)}
|
||||||
{region}
|
</Text>
|
||||||
</Text>
|
)}
|
||||||
. Some features are limited because of regional age
|
|
||||||
laws.
|
|
||||||
</Trans>
|
|
||||||
)}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{region && !isGPS && (
|
{region && !isGPS && (
|
||||||
<Text style={[a.text_sm, a.leading_snug]}>
|
<Text style={[a.text_sm, a.leading_snug]}>
|
||||||
<Trans>
|
<Trans>This estimate may be inaccurate if you're using a VPN.</Trans>
|
||||||
This estimate may be inaccurate if you're using a VPN.
|
</Text>
|
||||||
</Trans>
|
)}
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{IS_NATIVE && (
|
{IS_NATIVE && (
|
||||||
<Text style={[a.text_sm, a.leading_snug]}>
|
<Text style={[a.text_sm, a.leading_snug]}>
|
||||||
<Trans>
|
<Trans>
|
||||||
<InlineLinkText
|
<InlineLinkText
|
||||||
label={l`Confirm your location`}
|
label={l`Confirm your location`}
|
||||||
{...createStaticClick(() => {
|
{...createStaticClick(() => {
|
||||||
locationControl.open()
|
locationControl.open()
|
||||||
})}>
|
})}>
|
||||||
Tap here to confirm your location.
|
Tap here to confirm your location.
|
||||||
</InlineLinkText>
|
</InlineLinkText>
|
||||||
</Trans>
|
</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user