signal-desktop/ts/state/smart/SafetyNumberModal.tsx
Jamie Kyle 27b55e472d
Refactor smart components
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
2024-03-13 13:44:13 -07:00

39 lines
1.5 KiB
TypeScript

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { memo } from 'react';
import { useSelector } from 'react-redux';
import { SafetyNumberModal } from '../../components/SafetyNumberModal';
import type { StateType } from '../reducer';
import { getContactSafetyNumber } from '../selectors/safetyNumber';
import { getConversationSelector } from '../selectors/conversations';
import { getIntl } from '../selectors/user';
import { useSafetyNumberActions } from '../ducks/safetyNumber';
import { useGlobalModalActions } from '../ducks/globalModals';
export type SmartSafetyNumberModalProps = {
contactID: string;
};
export const SmartSafetyNumberModal = memo(function SmartSafetyNumberModal({
contactID,
}: SmartSafetyNumberModalProps) {
const i18n = useSelector(getIntl);
const conversationSelector = useSelector(getConversationSelector);
const contact = conversationSelector(contactID);
const contactSafetyNumber = useSelector((state: StateType) => {
return getContactSafetyNumber(state, { contactID });
});
const { generateSafetyNumber, toggleVerified } = useSafetyNumberActions();
const { toggleSafetyNumberModal } = useGlobalModalActions();
return (
<SafetyNumberModal
i18n={i18n}
contact={contact}
safetyNumber={contactSafetyNumber.safetyNumber}
verificationDisabled={contactSafetyNumber.verificationDisabled}
toggleSafetyNumberModal={toggleSafetyNumberModal}
generateSafetyNumber={generateSafetyNumber}
toggleVerified={toggleVerified}
/>
);
});