import React, { FC, memo, } from '../../lib/teact/teact'; import { LangCode, Price } from '../../types'; import { formatCurrency } from '../../util/formatCurrency'; import useLang from '../../hooks/useLang'; import './Checkout.scss'; export type OwnProps = { invoiceContent?: { title?: string; text?: string; photoUrl?: string; }; checkoutInfo?: { paymentMethod?: string; paymentProvider?: string; shippingAddress?: string; name?: string; phone?: string; shippingMethod?: string; }; prices?: Price[]; totalPrice?: number; shippingPrices?: Price[]; currency?: string; }; const Checkout: FC = ({ invoiceContent, prices, shippingPrices, checkoutInfo, currency, totalPrice, }) => { const lang = useLang(); const { photoUrl, title, text } = invoiceContent || {}; const { paymentMethod, paymentProvider, shippingAddress, name, phone, shippingMethod, } = (checkoutInfo || {}); return (
{photoUrl && }
{title}

{text}

{ prices && prices.map((item) => ( renderPaymentItem(lang.code, item.label, item.amount, currency) )) } { shippingPrices && shippingPrices.map((item) => ( renderPaymentItem(lang.code, item.label, item.amount, currency) )) } { totalPrice !== undefined && ( renderPaymentItem(lang.code, lang('Checkout.TotalAmount'), totalPrice, currency, true) ) }
{paymentMethod && renderCheckoutItem('icon-card', paymentMethod, 'Payment method')} {paymentProvider && renderCheckoutItem('stripe-provider', paymentProvider, 'Payment provider')} {shippingAddress && renderCheckoutItem('icon-location', shippingAddress, 'Shipping address')} {name && renderCheckoutItem('icon-user', name, 'Name')} {phone && renderCheckoutItem('icon-phone', phone, 'Phone number')} {shippingMethod && renderCheckoutItem('icon-truck', shippingMethod, 'Shipping method')}
); }; function renderPaymentItem( langCode: LangCode | undefined, title: string, value: number, currency?: string, main = false, ) { return (
{ title }
{formatCurrency(value, currency, langCode)}
); } function renderCheckoutItem(icon: string, title: string, data: string) { return (
{ title }

{ data }

); } export default memo(Checkout);