import React, { memo, useRef } from '../../../lib/teact/teact'; import type { FC } from '../../../lib/teact/teact'; import type { ApiMessage } from '../../../api/types'; import type { ISettings } from '../../../types'; import { CUSTOM_APPENDIX_ATTRIBUTE } from '../../../config'; import { getMessageInvoice, getWebDocumentHash } from '../../../global/helpers'; import { formatCurrency } from '../../../util/formatCurrency'; import renderText from '../../common/helpers/renderText'; import getCustomAppendixBg from './helpers/getCustomAppendixBg'; import useLayoutEffectWithPrevDeps from '../../../hooks/useLayoutEffectWithPrevDeps'; import useLang from '../../../hooks/useLang'; import useMedia from '../../../hooks/useMedia'; import Skeleton from '../../ui/Skeleton'; import './Invoice.scss'; type OwnProps = { message: ApiMessage; shouldAffectAppendix?: boolean; isInSelectMode?: boolean; isSelected?: boolean; theme: ISettings['theme']; }; const Invoice: FC = ({ message, shouldAffectAppendix, isInSelectMode, isSelected, theme, }) => { // eslint-disable-next-line no-null/no-null const ref = useRef(null); const lang = useLang(); const invoice = getMessageInvoice(message); const { title, text, amount, currency, isTest, photo, } = invoice!; const photoUrl = useMedia(getWebDocumentHash(photo)); useLayoutEffectWithPrevDeps(([prevShouldAffectAppendix]) => { if (!shouldAffectAppendix) { if (prevShouldAffectAppendix) { ref.current!.closest('.message-content')!.removeAttribute(CUSTOM_APPENDIX_ATTRIBUTE); } return; } if (photoUrl) { const contentEl = ref.current!.closest('.message-content')!; getCustomAppendixBg(photoUrl, false, isInSelectMode, isSelected, theme).then((appendixBg) => { contentEl.style.setProperty('--appendix-bg', appendixBg); contentEl.setAttribute(CUSTOM_APPENDIX_ATTRIBUTE, ''); }); } }, [shouldAffectAppendix, photoUrl, isInSelectMode, isSelected, theme] as const); return (
{title && (

{renderText(title)}

)} {text && (
{renderText(text, ['emoji', 'br'])}
)}
{photoUrl && ( )} {!photoUrl && photo && ( )}

{formatCurrency(amount, currency, lang.code)} {isTest && {lang('PaymentTestInvoice')}}

); }; export default memo(Invoice);