116 lines
3.6 KiB
TypeScript
116 lines
3.6 KiB
TypeScript
'use client';
|
|
|
|
import type { WebApp, WebAppUser, WebAppInitData, Platforms, HapticFeedback } from '@twa-dev/types';
|
|
|
|
// Демо данные для тестирования без Telegram
|
|
const demoUser: WebAppUser = {
|
|
id: 12345,
|
|
first_name: 'Demo',
|
|
username: 'demo_user',
|
|
language_code: 'ru',
|
|
is_premium: false,
|
|
last_name: '',
|
|
photo_url: ''
|
|
};
|
|
|
|
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 = () => () => {};
|
|
|
|
// Создаем заглушку для HapticFeedback
|
|
const demoHapticFeedback: HapticFeedback = {
|
|
impactOccurred: (_style: "light" | "medium" | "heavy" | "rigid" | "soft") => demoHapticFeedback,
|
|
notificationOccurred: (_type: "error" | "success" | "warning") => demoHapticFeedback,
|
|
selectionChanged: () => demoHapticFeedback
|
|
};
|
|
|
|
export const getDemoWebApp = (): WebApp => ({
|
|
initData: JSON.stringify(demoInitData),
|
|
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()
|
|
},
|
|
HapticFeedback: demoHapticFeedback,
|
|
CloudStorage: {
|
|
setItem: createNoopFunction(),
|
|
getItem: createNoopFunction(),
|
|
getItems: createNoopFunction(),
|
|
removeItem: createNoopFunction(),
|
|
removeItems: createNoopFunction(),
|
|
getKeys: createNoopFunction()
|
|
},
|
|
version: '7.0',
|
|
isVersionAtLeast: (version: string) => true,
|
|
setHeaderColor: createNoopFunction(),
|
|
setBackgroundColor: createNoopFunction(),
|
|
enableClosingConfirmation: createNoopFunction(),
|
|
disableClosingConfirmation: createNoopFunction(),
|
|
onEvent: createNoopFunction(),
|
|
offEvent: createNoopFunction(),
|
|
sendData: createNoopFunction(),
|
|
switchInlineQuery: createNoopFunction(),
|
|
openLink: createNoopFunction(),
|
|
openTelegramLink: createNoopFunction(),
|
|
openInvoice: createNoopFunction(),
|
|
showPopup: createNoopFunction(),
|
|
showAlert: createNoopFunction(),
|
|
showConfirm: createNoopFunction(),
|
|
showScanQrPopup: createNoopFunction(),
|
|
closeScanQrPopup: createNoopFunction(),
|
|
readTextFromClipboard: createNoopFunction(),
|
|
requestWriteAccess: createNoopFunction(),
|
|
requestContact: createNoopFunction(),
|
|
ready: createNoopFunction(),
|
|
expand: createNoopFunction(),
|
|
close: createNoopFunction(),
|
|
});
|