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('SectionTitleStarsForForMessages')}

{!canChangeChargeForMessages && ( )} {canChangeChargeForMessages && (

{lang(isGroupChat ? 'SetPriceGroupDescription' : 'SectionDescriptionStarsForForMessages', { percent: formatPercent(starsPaidMessageCommissionPermille * 100), amount: formatCurrencyAsString( chargeForMessages * starsUsdWithdrawRate * starsPaidMessageCommissionPermille, 'USD', lang.code, ), }, { withNodes: true, })}

)} ); } export default memo(withGlobal( (global): Complete => { const starsUsdWithdrawRateX1000 = global.appConfig.starsUsdWithdrawRateX1000; const starsUsdWithdrawRate = starsUsdWithdrawRateX1000 ? starsUsdWithdrawRateX1000 / 1000 : 1; const configStarsPaidMessageCommissionPermille = global.appConfig.starsPaidMessageCommissionPermille; const starsPaidMessageCommissionPermille = configStarsPaidMessageCommissionPermille ? configStarsPaidMessageCommissionPermille / 1000 : 100; return { starsPaidMessageCommissionPermille, starsUsdWithdrawRate, starsPaidMessageAmountMax: global.appConfig.starsPaidMessageAmountMax || DEFAULT_MAXIMUM_CHARGE_FOR_MESSAGES, }; }, )(PaidMessagePrice));