diff --git a/src/assets/localization/fallback.strings b/src/assets/localization/fallback.strings index cf78b4034..1ca67d2e9 100644 --- a/src/assets/localization/fallback.strings +++ b/src/assets/localization/fallback.strings @@ -2446,6 +2446,7 @@ "TitleAgeCheckFailed" = "Age Check Failed"; "TitleAgeCheckSuccess" = "Age Check Success"; "ButtonAgeVerification" = "Verify My Age"; +"MiniAppUnavailableError" = "Mini app is not available"; "GiftRibbonPremium" = "premium"; "NotificationGiftsLimit2_one" = "You already sent **one** of these gifts, which is the limit."; "NotificationGiftsLimit2_other" = "You already sent **{count}** of these gifts, which is the limit."; diff --git a/src/components/modals/ageVerification/AgeVerificationModal.tsx b/src/components/modals/ageVerification/AgeVerificationModal.tsx index 606b22828..91443d582 100644 --- a/src/components/modals/ageVerification/AgeVerificationModal.tsx +++ b/src/components/modals/ageVerification/AgeVerificationModal.tsx @@ -1,4 +1,3 @@ -import type { FC } from '../../../lib/teact/teact'; import { memo } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; @@ -20,27 +19,19 @@ export type OwnProps = { }; type StateProps = { - verifyAgeBotUsername?: string; verifyAgeMin: number; }; -const AgeVerificationModal: FC = ({ +const AgeVerificationModal = ({ modal, - verifyAgeBotUsername, verifyAgeMin, -}) => { - const { closeAgeVerificationModal, openChatByUsername } = getActions(); +}: OwnProps & StateProps) => { + const { closeAgeVerificationModal, requestAgeVerification } = getActions(); const lang = useLang(); const isOpen = Boolean(modal); const handleVerifyAge = useLastCallback(() => { - if (verifyAgeBotUsername) { - openChatByUsername({ - shouldStartMainApp: true, - username: verifyAgeBotUsername, - }); - } - closeAgeVerificationModal(); + requestAgeVerification(); }); const handleClose = useLastCallback(() => { @@ -86,11 +77,9 @@ const AgeVerificationModal: FC = ({ export default memo(withGlobal((global): Complete => { const appConfig = global.appConfig; - const verifyAgeBotUsername = appConfig.verifyAgeBotUsername; const verifyAgeMin = appConfig.verifyAgeMin || VERIFY_AGE_MIN_DEFAULT; return { - verifyAgeBotUsername, verifyAgeMin, }; })(AgeVerificationModal)); diff --git a/src/global/actions/api/bots.ts b/src/global/actions/api/bots.ts index 5e4fa6b4b..709c5df4f 100644 --- a/src/global/actions/api/bots.ts +++ b/src/global/actions/api/bots.ts @@ -703,6 +703,42 @@ addActionHandler('requestWebView', async (global, actions, payload): Promise => { + const { tabId = getCurrentTabId() } = payload || {}; + const { verifyAgeBotUsername } = global.appConfig; + + if (!verifyAgeBotUsername) { + actions.showNotification({ + message: { key: 'MiniAppUnavailableError' }, + tabId, + }); + return; + } + + const chat = await fetchChatByUsername(global, verifyAgeBotUsername); + global = getGlobal(); + const bot = chat && selectUser(global, chat.id); + + if (!bot?.hasMainMiniApp) { + actions.showNotification({ + message: { key: 'MiniAppUnavailableError' }, + tabId, + }); + return; + } + + const theme = extractCurrentThemeParams(); + actions.requestMainWebView({ + botId: bot.id, + peerId: bot.id, + theme, + shouldMarkBotTrusted: true, + tabId, + }); + + actions.closeAgeVerificationModal({ tabId }); +}); + addActionHandler('requestMainWebView', async (global, actions, payload): Promise => { const { botId, peerId, theme, startParam, mode, shouldMarkBotTrusted, @@ -717,7 +753,14 @@ addActionHandler('requestMainWebView', async (global, actions, payload): Promise if (checkIfOpenOrActivate(global, botId, tabId)) return; const bot = selectUser(global, botId); - if (!bot) return; + if (!bot) { + actions.showNotification({ + message: { key: 'MiniAppUnavailableError' }, + tabId, + }); + return; + } + const peer = selectPeer(global, peerId); if (!peer) return; @@ -748,6 +791,10 @@ addActionHandler('requestMainWebView', async (global, actions, payload): Promise mode, }); if (!result) { + actions.showNotification({ + message: { key: 'MiniAppUnavailableError' }, + tabId, + }); return; } diff --git a/src/global/types/actions.ts b/src/global/types/actions.ts index 93a9a0e73..9f62b61e7 100644 --- a/src/global/types/actions.ts +++ b/src/global/types/actions.ts @@ -1149,6 +1149,7 @@ export interface ActionPayloads { closeDeleteAccountModal: WithTabId | undefined; openAgeVerificationModal: WithTabId | undefined; closeAgeVerificationModal: WithTabId | undefined; + requestAgeVerification: WithTabId | undefined; setAccountTTL: { days: number; } & WithTabId | undefined; diff --git a/src/types/language.d.ts b/src/types/language.d.ts index 43aa656c7..c088b0626 100644 --- a/src/types/language.d.ts +++ b/src/types/language.d.ts @@ -1797,6 +1797,7 @@ export interface LangPair { 'TitleAgeCheckFailed': undefined; 'TitleAgeCheckSuccess': undefined; 'ButtonAgeVerification': undefined; + 'MiniAppUnavailableError': undefined; 'GiftRibbonPremium': undefined; 'PremiumGiftHeader': undefined; 'PriceInStars': undefined;