96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
'use client';
|
|
|
|
import type { WebApp, WebAppUser, WebAppInitData, Platforms } from '@twa-dev/types';
|
|
|
|
// Демо данные для тестирования без Telegram
|
|
const demoUser: WebAppUser = {
|
|
id: 12345,
|
|
first_name: 'Demo',
|
|
username: 'demo_user',
|
|
language_code: 'ru',
|
|
is_premium: false
|
|
};
|
|
|
|
const demoInitData: WebAppInitData = {
|
|
query_id: 'demo_query',
|
|
user: demoUser,
|
|
auth_date: Date.now(),
|
|
hash: 'demo_hash',
|
|
start_param: ''
|
|
};
|
|
|
|
export const isDemoMode = () => {
|
|
return typeof window !== 'undefined' && new URLSearchParams(window.location.search).has('demo');
|
|
};
|
|
|
|
// Создаем заглушки для методов WebApp
|
|
const createNoopFunction = () => () => {};
|
|
|
|
type SafeWebApp = Pick<WebApp,
|
|
| 'initData'
|
|
| 'initDataUnsafe'
|
|
| 'platform'
|
|
| 'colorScheme'
|
|
| 'themeParams'
|
|
| 'isExpanded'
|
|
| 'viewportHeight'
|
|
| 'viewportStableHeight'
|
|
| 'headerColor'
|
|
| 'backgroundColor'
|
|
| 'isClosingConfirmationEnabled'
|
|
| 'BackButton'
|
|
| 'MainButton'
|
|
| 'ready'
|
|
| 'expand'
|
|
| 'close'
|
|
>;
|
|
|
|
export const getDemoWebApp = (): SafeWebApp => ({
|
|
initData: 'demo_mode',
|
|
initDataUnsafe: demoInitData,
|
|
platform: 'WEBVIEW' as Platforms,
|
|
colorScheme: 'light',
|
|
themeParams: {
|
|
bg_color: '#ffffff',
|
|
text_color: '#000000',
|
|
hint_color: '#999999',
|
|
link_color: '#2481cc',
|
|
button_color: '#2481cc',
|
|
button_text_color: '#ffffff',
|
|
secondary_bg_color: '#f0f0f0'
|
|
},
|
|
isExpanded: true,
|
|
viewportHeight: typeof window !== 'undefined' ? window.innerHeight : 800,
|
|
viewportStableHeight: typeof window !== 'undefined' ? window.innerHeight : 800,
|
|
headerColor: '#ffffff',
|
|
backgroundColor: '#ffffff',
|
|
isClosingConfirmationEnabled: true,
|
|
BackButton: {
|
|
isVisible: false,
|
|
onClick: createNoopFunction(),
|
|
offClick: createNoopFunction(),
|
|
show: createNoopFunction(),
|
|
hide: createNoopFunction()
|
|
},
|
|
MainButton: {
|
|
text: '',
|
|
color: '#2481cc',
|
|
textColor: '#ffffff',
|
|
isVisible: false,
|
|
isProgressVisible: false,
|
|
isActive: true,
|
|
setText: createNoopFunction(),
|
|
onClick: createNoopFunction(),
|
|
offClick: createNoopFunction(),
|
|
show: createNoopFunction(),
|
|
hide: createNoopFunction(),
|
|
enable: createNoopFunction(),
|
|
disable: createNoopFunction(),
|
|
showProgress: createNoopFunction(),
|
|
hideProgress: createNoopFunction(),
|
|
setParams: createNoopFunction()
|
|
},
|
|
ready: createNoopFunction(),
|
|
expand: createNoopFunction(),
|
|
close: createNoopFunction(),
|
|
});
|