From 8f9731a5cf9e9fcca8a07f88b8031f0d4622699f Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 24 Sep 2024 14:48:47 +0200 Subject: [PATCH] Mini Apps: Fix modal freeze when opening mini app via button (#4994) --- src/global/actions/api/bots.ts | 7 +++++-- src/global/actions/api/chats.ts | 1 + src/global/types.ts | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/global/actions/api/bots.ts b/src/global/actions/api/bots.ts index e7fa75714..a1c4db8b2 100644 --- a/src/global/actions/api/bots.ts +++ b/src/global/actions/api/bots.ts @@ -670,7 +670,7 @@ addActionHandler('loadPreviewMedias', async (global, actions, payload): Promise< addActionHandler('requestAppWebView', async (global, actions, payload): Promise => { const { - botId, appName, startApp, theme, isWriteAllowed, isFromConfirm, + botId, appName, startApp, theme, isWriteAllowed, isFromConfirm, shouldSkipBotTrustRequest, tabId = getCurrentTabId(), } = payload; @@ -719,7 +719,10 @@ addActionHandler('requestAppWebView', async (global, actions, payload): Promise< return; } - if (botApp.isInactive || !selectIsTrustedBot(global, botId)) { + const shouldRequestBotTrust = !shouldSkipBotTrustRequest && (botApp.isInactive || !selectIsTrustedBot(global, botId)); + + if (shouldRequestBotTrust) { + payload.shouldSkipBotTrustRequest = true; global = updateTabState(global, { botTrustRequest: { botId, diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 93c75dfa3..ee32c3c1a 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -2891,6 +2891,7 @@ export async function checkWebAppExists( if (!botName || !appName) return false; global = getGlobal(); const chatByUsername = await fetchChatByUsername(global, botName); + global = getGlobal(); const bot = chatByUsername && selectUser(global, chatByUsername.id); const botApp = bot && await callApi('fetchBotApp', { bot, diff --git a/src/global/types.ts b/src/global/types.ts index 1db1b4bec..e9dbc1e53 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -2961,6 +2961,7 @@ export interface ActionPayloads { startApp?: string; isWriteAllowed?: boolean; isFromConfirm?: boolean; + shouldSkipBotTrustRequest?: boolean; } & WithTabId; loadPreviewMedias: { botId: string;