import { memo, } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import { DEFAULT_MAXIMUM_CHARGE_FOR_MESSAGES, MINIMUM_CHARGE_FOR_MESSAGES, } from '../../../config'; import { formatCurrencyAsString } from '../../../util/formatCurrency'; import { formatPercent } from '../../../util/textFormat'; import useLang from '../../../hooks/useLang'; import useLastCallback from '../../../hooks/useLastCallback'; import Button from '../../ui/Button'; import Icon from '../icons/Icon'; import PaidMessageSlider from './PaidMessageSlider'; type OwnProps = { chargeForMessages: number; canChangeChargeForMessages?: boolean; isGroupChat?: boolean; onChange: (value: number) => void; }; type StateProps = { starsUsdWithdrawRate: number; starsPaidMessageAmountMax: number; starsPaidMessageCommissionPermille: number; }; function PaidMessagePrice({ starsUsdWithdrawRate, starsPaidMessageAmountMax, starsPaidMessageCommissionPermille, canChangeChargeForMessages, isGroupChat, chargeForMessages, onChange, }: OwnProps & StateProps) { const { openPremiumModal } = getActions(); const lang = useLang(); const handleChargeForMessagesChange = useLastCallback((value: number) => { onChange?.(value); }); const handleUnlockWithPremium = useLastCallback(() => { openPremiumModal({ initialSection: 'message_privacy' }); }); return ( <>
{lang(isGroupChat ? 'SetPriceGroupDescription' : 'SectionDescriptionStarsForForMessages', { percent: formatPercent(starsPaidMessageCommissionPermille * 100), amount: formatCurrencyAsString( chargeForMessages * starsUsdWithdrawRate * starsPaidMessageCommissionPermille, 'USD', lang.code, ), }, { withNodes: true, })}
)} > ); } export default memo(withGlobal