mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
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:
@@ -55,8 +55,10 @@ function CodeOnlySuccessState({
|
|||||||
const shortCode = purchaseToken.slice(0, 12);
|
const shortCode = purchaseToken.slice(0, 12);
|
||||||
const giftCode = `GIFT-${shortCode}`;
|
const giftCode = `GIFT-${shortCode}`;
|
||||||
const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME as string | undefined;
|
const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME as string | undefined;
|
||||||
const botLink = botUsername ? `https://t.me/${botUsername}?start=GIFT_${shortCode}` : null;
|
// Encode underscores as %5F so Telegram auto-link detection doesn't strip them
|
||||||
const cabinetLink = `${window.location.origin}/gift?tab=activate&code=${shortCode}`;
|
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 = [
|
const fullMessage = [
|
||||||
t('gift.shareText', 'I have a gift for you! Activate it here:'),
|
t('gift.shareText', 'I have a gift for you! Activate it here:'),
|
||||||
|
|||||||
@@ -1040,8 +1040,10 @@ function SentGiftCard({ gift }: { gift: SentGift }) {
|
|||||||
|
|
||||||
const buildShareMessage = useCallback(() => {
|
const buildShareMessage = useCallback(() => {
|
||||||
const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME as string | undefined;
|
const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME as string | undefined;
|
||||||
const botLink = botUsername ? `https://t.me/${botUsername}?start=GIFT_${shortCode}` : null;
|
// Encode underscores as %5F so Telegram auto-link detection doesn't strip them
|
||||||
const cabinetLink = `${window.location.origin}/gift?tab=activate&code=${shortCode}`;
|
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 [
|
return [
|
||||||
t('gift.shareText'),
|
t('gift.shareText'),
|
||||||
'',
|
'',
|
||||||
@@ -1304,7 +1306,9 @@ export default function GiftSubscription() {
|
|||||||
|
|
||||||
// URL params: ?tab=activate&code=TOKEN for auto-activation
|
// URL params: ?tab=activate&code=TOKEN for auto-activation
|
||||||
const urlTab = searchParams.get('tab') as TabId | null;
|
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>(
|
const [activeTab, setActiveTab] = useState<TabId>(
|
||||||
urlTab === 'activate' || urlTab === 'myGifts' ? urlTab : 'buy',
|
urlTab === 'activate' || urlTab === 'myGifts' ? urlTab : 'buy',
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user