import { memo, useRef } from '../../../../lib/teact/teact'; import { withGlobal } from '../../../../global'; import type { ApiSticker } from '../../../../api/types'; import type { ApiMessageActionGiftPremium, ApiMessageActionGiftStars, ApiMessageActionGiftTon } from '../../../../api/types/messageActions'; import { selectCanPlayAnimatedEmojis, selectGiftStickerForDuration, selectGiftStickerForStars, selectGiftStickerForTon, } from '../../../../global/selectors'; import { formatCurrency } from '../../../../util/formatCurrency'; import { renderTextWithEntities } from '../../../common/helpers/renderTextWithEntities'; import { type ObserveFn } from '../../../../hooks/useIntersectionObserver'; import useLang from '../../../../hooks/useLang'; import Sparkles from '../../../common/Sparkles'; import StickerView from '../../../common/StickerView'; import styles from '../ActionMessage.module.scss'; type OwnProps = { action: ApiMessageActionGiftPremium | ApiMessageActionGiftStars | ApiMessageActionGiftTon; observeIntersectionForLoading?: ObserveFn; observeIntersectionForPlaying?: ObserveFn; onClick?: NoneToVoidFunction; }; type StateProps = { sticker?: ApiSticker; canPlayAnimatedEmojis: boolean; }; const STICKER_SIZE = 150; const GiftAction = ({ action, sticker, canPlayAnimatedEmojis, onClick, observeIntersectionForLoading, observeIntersectionForPlaying, }: OwnProps & StateProps) => { const stickerRef = useRef(); const lang = useLang(); const message = action.type === 'giftPremium' ? action.message : undefined; const renderTonTitle = () => { const { cryptoAmount, cryptoCurrency } = action; const price = cryptoAmount ? formatCurrency(lang, cryptoAmount, cryptoCurrency!, { asFontIcon: true }) : undefined; return price; }; return (
{sticker && ( )}

{action.type === 'giftPremium' ? ( lang('ActionGiftPremiumTitle', { months: action.months }, { pluralValue: action.months }) ) : action.type === 'giftStars' ? ( lang('ActionGiftStarsTitle', { amount: action.stars }, { pluralValue: action.stars }) ) : renderTonTitle()}

{message && renderTextWithEntities(message)} {!message && (lang(action.type === 'giftTon' ? 'DescriptionAboutTon' : action.type === 'giftPremium' ? 'ActionGiftPremiumText' : 'ActionGiftStarsText'))}
{lang('ActionViewButton')}
); }; export default memo(withGlobal( (global, { action }): StateProps => { const sticker = action.type === 'giftPremium' ? selectGiftStickerForDuration(global, action.months) : action.type === 'giftStars' ? selectGiftStickerForStars(global, action.stars) : selectGiftStickerForTon(global, action.cryptoAmount); const canPlayAnimatedEmojis = selectCanPlayAnimatedEmojis(global); return { sticker, canPlayAnimatedEmojis, }; }, )(GiftAction));