import type { FC } from '../../../lib/teact/teact'; import React, { memo, useLayoutEffect, useRef } from '../../../lib/teact/teact'; import type { ApiMessage } from '../../../api/types'; import type { ISettings } from '../../../types'; import { CUSTOM_APPENDIX_ATTRIBUTE } from '../../../config'; import { getMessageInvoice } from '../../../global/helpers'; import { formatCurrency } from '../../../util/formatCurrency'; import renderText from '../../common/helpers/renderText'; import getCustomAppendixBg from './helpers/getCustomAppendixBg'; import useLang from '../../../hooks/useLang'; 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, photoUrl, photoWidth, photoHeight, } = invoice!; useLayoutEffect(() => { if (!shouldAffectAppendix) { return; } const contentEl = ref.current!.closest('.message-content')!; if (photoUrl) { getCustomAppendixBg(photoUrl, false, isInSelectMode, isSelected, theme).then((appendixBg) => { contentEl.style.setProperty('--appendix-bg', appendixBg); contentEl.setAttribute(CUSTOM_APPENDIX_ATTRIBUTE, ''); }); } }, [shouldAffectAppendix, photoUrl, isInSelectMode, isSelected, theme]); const photoStyle = photoHeight && photoWidth ? `aspect-ratio: ${photoWidth / photoHeight};` : undefined; return (
{title && (

{renderText(title)}

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

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

); }; export default memo(Invoice);