diff --git a/src/pages/GiftResult.tsx b/src/pages/GiftResult.tsx index d647223..beb24a7 100644 --- a/src/pages/GiftResult.tsx +++ b/src/pages/GiftResult.tsx @@ -55,8 +55,10 @@ function CodeOnlySuccessState({ const shortCode = purchaseToken.slice(0, 12); const giftCode = `GIFT-${shortCode}`; const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME as string | undefined; - const botLink = botUsername ? `https://t.me/${botUsername}?start=GIFT_${shortCode}` : null; - const cabinetLink = `${window.location.origin}/gift?tab=activate&code=${shortCode}`; + // Encode underscores as %5F so Telegram auto-link detection doesn't strip them + const safeCode = shortCode.replace(/_/g, '%5F'); + const botLink = botUsername ? `https://t.me/${botUsername}?start=GIFT%5F${safeCode}` : null; + const cabinetLink = `${window.location.origin}/gift?tab=activate&code=${safeCode}`; const fullMessage = [ t('gift.shareText', 'I have a gift for you! Activate it here:'), diff --git a/src/pages/GiftSubscription.tsx b/src/pages/GiftSubscription.tsx index 892ad8d..781e36d 100644 --- a/src/pages/GiftSubscription.tsx +++ b/src/pages/GiftSubscription.tsx @@ -1040,8 +1040,10 @@ function SentGiftCard({ gift }: { gift: SentGift }) { const buildShareMessage = useCallback(() => { const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME as string | undefined; - const botLink = botUsername ? `https://t.me/${botUsername}?start=GIFT_${shortCode}` : null; - const cabinetLink = `${window.location.origin}/gift?tab=activate&code=${shortCode}`; + // Encode underscores as %5F so Telegram auto-link detection doesn't strip them + const safeCode = shortCode.replace(/_/g, '%5F'); + const botLink = botUsername ? `https://t.me/${botUsername}?start=GIFT%5F${safeCode}` : null; + const cabinetLink = `${window.location.origin}/gift?tab=activate&code=${safeCode}`; return [ t('gift.shareText'), '', @@ -1304,7 +1306,9 @@ export default function GiftSubscription() { // URL params: ?tab=activate&code=TOKEN for auto-activation const urlTab = searchParams.get('tab') as TabId | null; - const urlCode = searchParams.get('code'); + const rawCode = searchParams.get('code'); + // Strip GIFT- or GIFT_ prefix if user pasted the full display code + const urlCode = rawCode?.replace(/^GIFT[-_]/i, '') ?? rawCode; const [activeTab, setActiveTab] = useState( urlTab === 'activate' || urlTab === 'myGifts' ? urlTab : 'buy', );