feat: add Stars payment confirmation and admin validation

- Show confirmation dialog before redirecting to Telegram for Stars
  payment (native popup in Mini App, confirm in browser)
- Warn admin when saving wheel config with Stars enabled but
  Telegram Stars payment method is disabled globally
- Add translation keys: confirmStarsTitle, confirmStarsPayment,
  starsNotEnabledGlobally (ru, en, zh, fa)
This commit is contained in:
c0mrade
2026-02-04 16:41:25 +03:00
parent 02640d1c38
commit e6f8ae6ab0
6 changed files with 37 additions and 4 deletions

View File

@@ -21,7 +21,9 @@ import {
} from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
import { adminWheelApi, type WheelPrizeAdmin, type CreateWheelPrizeData } from '../api/wheel';
import { adminPaymentMethodsApi } from '../api/adminPaymentMethods';
import { useDestructiveConfirm } from '@/platform';
import { useNotify } from '@/platform/hooks/useNotify';
import FortuneWheel from '../components/wheel/FortuneWheel';
import { ColorPicker } from '@/components/ColorPicker';
import { useBackButton } from '../platform/hooks/useBackButton';
@@ -291,6 +293,7 @@ export default function AdminWheel() {
const queryClient = useQueryClient();
const confirmDelete = useDestructiveConfirm();
const { capabilities } = usePlatform();
const notify = useNotify();
// Use native Telegram back button in Mini App
useBackButton(() => navigate('/admin'));
@@ -794,10 +797,21 @@ export default function AdminWheel() {
{hasSettingsChanges && (
<div className="flex justify-end border-t border-dark-700 pt-6">
<button
onClick={() => {
if (settingsForm) {
updateConfigMutation.mutate(settingsForm);
onClick={async () => {
if (!settingsForm) return;
if (settingsForm.spin_cost_stars_enabled) {
try {
const methods = await adminPaymentMethodsApi.getAll();
const starsMethod = methods.find((m) => m.method_id === 'telegram_stars');
if (!starsMethod?.is_enabled) {
notify.warning(t('admin.wheel.starsNotEnabledGlobally'));
return;
}
} catch {
// If we can't check, allow saving
}
}
updateConfigMutation.mutate(settingsForm);
}}
disabled={updateConfigMutation.isPending}
className="btn-primary flex items-center gap-2"

View File

@@ -7,6 +7,7 @@ import WheelLegend from '../components/wheel/WheelLegend';
import InsufficientBalancePrompt from '../components/InsufficientBalancePrompt';
import { usePlatform, useHaptic } from '@/platform';
import { useNotify } from '@/platform/hooks/useNotify';
import { useNativeDialog } from '@/platform/hooks/useNativeDialog';
import { Card } from '@/components/data-display/Card/Card';
import { Button } from '@/components/primitives/Button/Button';
import { motion, AnimatePresence } from 'framer-motion';
@@ -63,6 +64,7 @@ export default function Wheel() {
const { openInvoice, capabilities } = usePlatform();
const haptic = useHaptic();
const notify = useNotify();
const dialog = useNativeDialog();
const [isSpinning, setIsSpinning] = useState(false);
const [targetRotation, setTargetRotation] = useState<number | null>(null);
@@ -306,7 +308,12 @@ export default function Wheel() {
},
});
const handleDirectStarsPay = () => {
const handleDirectStarsPay = async () => {
const confirmed = await dialog.confirm(
t('wheel.confirmStarsPayment'),
t('wheel.confirmStarsTitle'),
);
if (!confirmed) return;
setIsPayingStars(true);
starsInvoiceMutation.mutate();
};