diff --git a/src/components/TopUpModal.tsx b/src/components/TopUpModal.tsx index b2d8b00..bde9b70 100644 --- a/src/components/TopUpModal.tsx +++ b/src/components/TopUpModal.tsx @@ -207,7 +207,10 @@ export default function TopUpModal({ method, onClose, initialAmountRubles }: Top setError(t('balance.errors.noPaymentLink')); return; } - if (!webApp?.openInvoice) { + // openInvoice requires WebApp version 6.1+ + const supportsInvoice = + webApp?.openInvoice && webApp?.isVersionAtLeast && webApp.isVersionAtLeast('6.1'); + if (!supportsInvoice) { setError(t('balance.errors.starsOnlyInTelegram')); return; } diff --git a/src/pages/Wheel.tsx b/src/pages/Wheel.tsx index 78f9ff1..b6efc99 100644 --- a/src/pages/Wheel.tsx +++ b/src/pages/Wheel.tsx @@ -207,8 +207,12 @@ export default function Wheel() { const starsInvoiceMutation = useMutation({ mutationFn: wheelApi.createStarsInvoice, onSuccess: (data) => { - if (window.Telegram?.WebApp?.openInvoice) { - window.Telegram.WebApp.openInvoice(data.invoice_url, async (status) => { + const webApp = window.Telegram?.WebApp; + // openInvoice requires WebApp version 6.1+ + const supportsInvoice = + webApp?.openInvoice && webApp?.isVersionAtLeast && webApp.isVersionAtLeast('6.1'); + if (supportsInvoice) { + webApp.openInvoice(data.invoice_url, async (status) => { if (status === 'paid') { // Mark this as a Stars spin so handleSpinComplete knows to use the pending result isStarsSpinRef.current = true; diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 8b6f85e..0836c04 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -85,6 +85,8 @@ interface TelegramWebApp { button_color?: string; button_text_color?: string; }; + // Version check helper + isVersionAtLeast: (version: string) => boolean; } interface Window {