generated from Telegram-Mini-Apps/vanillajs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
87 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,14 @@ | |
<link href="css/link.css" rel="stylesheet"> | ||
<link href="css/displayData.css" rel="stylesheet"> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/@telegram-apps/[email protected]/dist/index.iife.js"></script> | ||
<script src="https://telegram.org/js/telegram-web-app.js"></script> | ||
<script src="https://unpkg.com/@tonconnect/[email protected]/dist/tonconnect-ui.min.js"></script> | ||
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<script src="js/utils.js"></script> | ||
<!-- Uncomment next line for local development outside Telegram Mini App --> | ||
<!-- <script src="js/mockEnv.js"></script> --> | ||
<script src="js/initNavigrator.js"></script> | ||
<script src="js/initComponents.js"></script> | ||
<script src="js/initTonConnect.js"></script> | ||
|
||
<script src="js/components/DisplayData.js"></script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,59 @@ | ||
(async () => { | ||
// Uncomment next line for local development outside Telegram Mini App | ||
// mockEnv(); | ||
|
||
const launchParams = window.telegramApps.sdk.retrieveLaunchParams(); | ||
|
||
// Launch eruda and enable SDK debug mode, if debug mode was requested outside. | ||
const debug = launchParams.startParam === 'debug'; | ||
if (debug) { | ||
window.telegramApps.sdk.setDebug(debug); | ||
const tonConnectUI = initTonConnectUI(); | ||
|
||
const routes = [ | ||
{ pathname: '/', Page: HomePage }, | ||
{ pathname: '/init-data', Page: InitDataPage, title: 'Init Data' }, | ||
{ pathname: '/theme-params', Page: ThemeParamsPage, title: 'Theme Params' }, | ||
{ pathname: '/launch-params', Page: LaunchParamsPage, title: 'Launch Params' }, | ||
{ | ||
pathname: '/ton-connect', | ||
Page: TonConnectPage, | ||
title: 'TON Connect', | ||
icon: `${window.location.origin}${window.location.pathname}ton.svg`, | ||
}, | ||
]; | ||
|
||
const root = document.getElementById('root'); | ||
const appContext = { | ||
getWebApp() { | ||
return window.Telegram.WebApp; | ||
}, | ||
tonConnectUI, | ||
routes, | ||
}; | ||
let prevPage; | ||
|
||
|
||
appContext.getWebApp().BackButton.onClick(goBack); | ||
|
||
window.addEventListener('hashchange', () => { | ||
const path = window.location.hash.slice(1); | ||
renderCurrentRoute(path); | ||
updateBackButton(path) | ||
}) | ||
|
||
renderCurrentRoute(window.location.hash.slice(1)); | ||
|
||
function renderCurrentRoute(path) { | ||
const route = routes.find(r => r.pathname === path); | ||
if (!route) { | ||
window.location.hash = '#/'; | ||
return; | ||
} | ||
|
||
// The web version of Telegram is capable of sending some specific CSS styles we would | ||
// like to catch. | ||
if (window.telegramApps.sdk.isIframe()) { | ||
window.telegramApps.sdk.initWeb(true); | ||
prevPage && prevPage.destroy && prevPage.destroy(); | ||
prevPage = new route.Page(appContext); | ||
prevPage.init && prevPage.init(); | ||
prevPage.render(root); | ||
} | ||
|
||
function goBack() { | ||
window.history.go(-1); | ||
} | ||
|
||
function updateBackButton(path) { | ||
if (path === '/') { | ||
appContext.getWebApp().BackButton.isVisible && appContext.getWebApp().BackButton.hide(); | ||
} else { | ||
!appContext.getWebApp().BackButton.isVisible && appContext.getWebApp().BackButton.show(); | ||
} | ||
|
||
const { | ||
miniApp, | ||
viewport, | ||
utils, | ||
themeParams, | ||
initData, | ||
} = await initComponents(); | ||
const navigator = await initNavigator(); | ||
const tonConnectUI = initTonConnectUI(); | ||
|
||
const routes = [ | ||
{ pathname: '/', Page: HomePage }, | ||
{ pathname: '/init-data', Page: InitDataPage, title: 'Init Data' }, | ||
{ pathname: '/theme-params', Page: ThemeParamsPage, title: 'Theme Params' }, | ||
{ pathname: '/launch-params', Page: LaunchParamsPage, title: 'Launch Params' }, | ||
{ | ||
pathname: '/ton-connect', | ||
Page: TonConnectPage, | ||
title: 'TON Connect', | ||
icon: `${window.location.origin}${window.location.pathname}ton.svg`, | ||
}, | ||
]; | ||
|
||
const root = document.getElementById('root'); | ||
const appContext = { | ||
initData, | ||
launchParams, | ||
miniApp, | ||
navigator, | ||
themeParams, | ||
utils, | ||
viewport, | ||
tonConnectUI, | ||
routes, | ||
}; | ||
let prevPage; | ||
|
||
function renderCurrentRoute() { | ||
const route = routes.find(r => r.pathname === navigator.pathname); | ||
if (!route) { | ||
navigator.replace('/'); | ||
return; | ||
} | ||
prevPage && prevPage.destroy && prevPage.destroy(); | ||
prevPage = new route.Page(appContext); | ||
prevPage.init && prevPage.init(); | ||
prevPage.render(root); | ||
} | ||
|
||
navigator.on('change', renderCurrentRoute); | ||
renderCurrentRoute(); | ||
})(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.