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
This commit is contained in:
Fringg
2026-03-29 06:47:50 +03:00
parent 2b03e7e514
commit 859bd24d8e
2 changed files with 11 additions and 5 deletions

View File

@@ -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:'),

View File

@@ -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<TabId>(
urlTab === 'activate' || urlTab === 'myGifts' ? urlTab : 'buy',
);