Age Verification: Separate flow from other apps (#6903)
This commit is contained in:
parent
a6a9efe602
commit
6ca0fbfacb
@ -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.";
|
||||
|
||||
@ -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<OwnProps & StateProps> = ({
|
||||
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<OwnProps & StateProps> = ({
|
||||
|
||||
export default memo(withGlobal((global): Complete<StateProps> => {
|
||||
const appConfig = global.appConfig;
|
||||
const verifyAgeBotUsername = appConfig.verifyAgeBotUsername;
|
||||
const verifyAgeMin = appConfig.verifyAgeMin || VERIFY_AGE_MIN_DEFAULT;
|
||||
|
||||
return {
|
||||
verifyAgeBotUsername,
|
||||
verifyAgeMin,
|
||||
};
|
||||
})(AgeVerificationModal));
|
||||
|
||||
@ -703,6 +703,42 @@ addActionHandler('requestWebView', async (global, actions, payload): Promise<voi
|
||||
}
|
||||
});
|
||||
|
||||
addActionHandler('requestAgeVerification', async (global, actions, payload): Promise<void> => {
|
||||
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<void> => {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -1149,6 +1149,7 @@ export interface ActionPayloads {
|
||||
closeDeleteAccountModal: WithTabId | undefined;
|
||||
openAgeVerificationModal: WithTabId | undefined;
|
||||
closeAgeVerificationModal: WithTabId | undefined;
|
||||
requestAgeVerification: WithTabId | undefined;
|
||||
setAccountTTL: {
|
||||
days: number;
|
||||
} & WithTabId | undefined;
|
||||
|
||||
1
src/types/language.d.ts
vendored
1
src/types/language.d.ts
vendored
@ -1797,6 +1797,7 @@ export interface LangPair {
|
||||
'TitleAgeCheckFailed': undefined;
|
||||
'TitleAgeCheckSuccess': undefined;
|
||||
'ButtonAgeVerification': undefined;
|
||||
'MiniAppUnavailableError': undefined;
|
||||
'GiftRibbonPremium': undefined;
|
||||
'PremiumGiftHeader': undefined;
|
||||
'PriceInStars': undefined;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user