From 923c9461671caedb16e53e15aac9da5390bff649 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 7 Nov 2022 23:00:29 +0400 Subject: [PATCH] Various fixes for Web App bots (#2102) --- src/api/gramjs/methods/bots.ts | 4 +-- src/components/main/WebAppModal.tsx | 15 +++++--- src/components/main/hooks/useWebAppFrame.ts | 40 +++++++++++++-------- src/hooks/useWindowSize.ts | 6 ++-- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/api/gramjs/methods/bots.ts b/src/api/gramjs/methods/bots.ts index dbda371d7..81c0fd34d 100644 --- a/src/api/gramjs/methods/bots.ts +++ b/src/api/gramjs/methods/bots.ts @@ -179,7 +179,7 @@ export async function requestWebView({ startParam, themeParams: theme ? buildInputThemeParams(theme) : undefined, fromBotMenu: isFromBotMenu || undefined, - platform: 'web', + platform: 'webz', ...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }), })); @@ -204,7 +204,7 @@ export async function requestSimpleWebView({ url, bot: buildInputPeer(bot.id, bot.accessHash), themeParams: theme ? buildInputThemeParams(theme) : undefined, - platform: 'web', + platform: 'webz', })); return result?.url; diff --git a/src/components/main/WebAppModal.tsx b/src/components/main/WebAppModal.tsx index 61f742ef4..3522373f5 100644 --- a/src/components/main/WebAppModal.tsx +++ b/src/components/main/WebAppModal.tsx @@ -103,6 +103,9 @@ const WebAppModal: FC = ({ const prevPopupParams = usePrevious(popupParams); const renderingPopupParams = popupParams || prevPopupParams; + // eslint-disable-next-line no-null/no-null + const frameRef = useRef(null); + const lang = useLang(); const { url, buttonText, queryId, @@ -191,8 +194,8 @@ const WebAppModal: FC = ({ ]); const { - ref, reloadFrame, sendEvent, sendViewport, sendTheme, - } = useWebAppFrame(isOpen, isSimple, handleEvent); + reloadFrame, sendEvent, sendViewport, sendTheme, + } = useWebAppFrame(frameRef, isOpen, isSimple, handleEvent); const shouldShowMainButton = mainButton?.isVisible && mainButton.text.trim().length > 0; @@ -238,6 +241,10 @@ const WebAppModal: FC = ({ }); }, [sendEvent]); + const handlePopupModalClose = useCallback(() => { + handlePopupClose(); + }, [handlePopupClose]); + // Notify view that height changed useOnChange(() => { setTimeout(() => { @@ -427,13 +434,13 @@ const WebAppModal: FC = ({ {isOpen && ( <>