// Copyright 2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import { Button, ButtonVariant } from './Button'; import type { ConversationType } from '../state/ducks/conversations'; import { Intl } from './Intl'; import type { LocalizerType } from '../types/Util'; export type PropsType = { contact: ConversationType; generateSafetyNumber: (contact: ConversationType) => void; i18n: LocalizerType; onClose: () => void; safetyNumber: string; toggleVerified: (contact: ConversationType) => void; verificationDisabled: boolean; }; export function SafetyNumberViewer({ contact, generateSafetyNumber, i18n, onClose, safetyNumber, toggleVerified, verificationDisabled, }: PropsType): JSX.Element | null { React.useEffect(() => { if (!contact) { return; } generateSafetyNumber(contact); }, [contact, generateSafetyNumber, safetyNumber]); if (!contact) { return null; } if (!contact.phoneNumber) { return (
{i18n('cannotGenerateSafetyNumber')}
); } const showNumber = Boolean(contact.name || contact.profileName); const numberFragment = showNumber && contact.phoneNumber ? ` ยท ${contact.phoneNumber}` : ''; const name = `${contact.title}${numberFragment}`; const boldName = ( {name} ); const { isVerified } = contact; const verifiedStatusKey = isVerified ? 'isVerified' : 'isNotVerified'; const verifyButtonText = isVerified ? i18n('unverify') : i18n('verify'); return (
{safetyNumber || getPlaceholder()}
{isVerified ? ( ) : ( )}
); } function getPlaceholder(): string { return Array.from(Array(12)) .map(() => 'XXXXX') .join(' '); }