fix mini app bot father

This commit is contained in:
lendry
2026-06-26 11:08:10 +03:00
parent 489b4d4a23
commit 7ed7cbdd16
7 changed files with 174 additions and 31 deletions

View File

@@ -2,21 +2,20 @@
import { useMemo, useState } from 'react';
import { Check, Copy, Loader2, Bot } from 'lucide-react';
import { useAuth } from '@/components/id/auth-provider';
import { useToast } from '@/components/id/toast-provider';
import { usePublicSettings } from '@/components/id/public-settings-provider';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { createManagedBot, getApiErrorMessage } from '@/lib/api';
import { useEmbeddedAuthFallback } from '@/lib/embedded-auth-bridge';
import { useMiniAppAuth } from '@/hooks/use-mini-app-auth';
import { cn } from '@/lib/utils';
type Step = 'name' | 'username' | 'done';
export function BotCreateMiniAppContent() {
const { token, isPinLocked, isLoading } = useAuth();
const embeddedToken = useEmbeddedAuthFallback();
const { projectName } = usePublicSettings();
const { effectiveToken, canUse, authReady, waitingForBridge, isLoading } = useMiniAppAuth();
const { showToast } = useToast();
const effectiveToken = token ?? embeddedToken;
const [step, setStep] = useState<Step>('name');
const [name, setName] = useState('');
@@ -24,11 +23,11 @@ export function BotCreateMiniAppContent() {
const [creating, setCreating] = useState(false);
const [createdBot, setCreatedBot] = useState<{ username: string; token: string; botId: string } | null>(null);
const canUse = Boolean(effectiveToken && !isPinLocked);
const canUseSession = canUse;
const usernamePreview = useMemo(() => `${username.replace(/_bot$/i, '').trim()}_bot`, [username]);
async function handleCreate() {
if (!canUse || !effectiveToken) return;
if (!canUseSession || !effectiveToken) return;
const trimmedName = name.trim();
const trimmedUsername = username.replace(/_bot$/i, '').trim();
if (!trimmedName) {
@@ -64,7 +63,7 @@ export function BotCreateMiniAppContent() {
showToast('Токен скопирован');
}
if (isLoading && !effectiveToken) {
if ((isLoading || waitingForBridge || !authReady) && !effectiveToken) {
return (
<div className="flex min-h-screen items-center justify-center p-6 text-center text-sm text-[#667085]">
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
@@ -73,10 +72,10 @@ export function BotCreateMiniAppContent() {
);
}
if (!canUse) {
if (!canUseSession) {
return (
<div className="flex min-h-screen items-center justify-center p-6 text-center text-sm text-[#667085]">
Войдите в Lendry ID, чтобы создать бота
Войдите в {projectName}, чтобы создать бота
</div>
);
}