// Copyright 2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import { ConversationType } from '../state/ducks/conversations'; import { LocalizerType } from '../types/Util'; import { getPlaceholder } from '../util/safetyNumber'; import { Intl } from './Intl'; export type PropsType = { contact?: ConversationType; generateSafetyNumber: (contact: ConversationType) => void; i18n: LocalizerType; onClose?: () => void; safetyNumber: string; safetyNumberChanged?: boolean; toggleVerified: (contact: ConversationType) => void; verificationDisabled: boolean; }; export const SafetyNumberViewer = ({ contact, generateSafetyNumber, i18n, onClose, safetyNumber, safetyNumberChanged, 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 safetyNumberChangedKey = safetyNumberChanged ? 'changedRightAfterVerify' : 'yourSafetyNumberWith'; const verifyButtonText = isVerified ? i18n('unverify') : i18n('verify'); return (
{onClose && (
)}
{safetyNumber || getPlaceholder()}
{isVerified ? ( ) : ( )}
); };