From 859bd24d8e97089caa6fb153fe6f3b6c99044af9 Mon Sep 17 00:00:00 2001 From: Fringg Date: Sun, 29 Mar 2026 06:47:50 +0300 Subject: [PATCH] fix: gift code activation URL encoding and prefix handling - Encode underscores as %5F in share URLs (bot link + cabinet link) to prevent Telegram auto-link detection from stripping trailing _ - Strip GIFT-/GIFT_ prefix from URL code param before pre-filling input - Use ?? instead of || for prefix stripping to preserve empty strings --- src/pages/GiftResult.tsx | 6 ++++-- src/pages/GiftSubscription.tsx | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) 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', );