├── .eslintrc.cjs
├── .github
├── deployment-branches.png
└── workflows
│ └── github-pages-deploy.yml
├── .gitignore
├── LICENSE
├── README.md
├── assets
└── application.png
├── eslint.config.js
├── index.html
├── package-lock.json
├── package.json
├── public
└── tonconnect-manifest.json
├── src
├── components
│ ├── App.tsx
│ ├── DisplayData
│ │ ├── DisplayData.css
│ │ └── DisplayData.tsx
│ ├── EnvUnsupported.tsx
│ ├── ErrorBoundary.tsx
│ ├── Link
│ │ ├── Link.css
│ │ └── Link.tsx
│ ├── Page.tsx
│ ├── RGB
│ │ ├── RGB.css
│ │ └── RGB.tsx
│ └── Root.tsx
├── css
│ ├── bem.ts
│ └── classnames.ts
├── helpers
│ └── publicUrl.ts
├── index.css
├── index.tsx
├── init.ts
├── mockEnv.ts
├── navigation
│ └── routes.tsx
└── pages
│ ├── IndexPage
│ ├── IndexPage.tsx
│ └── ton.svg
│ ├── InitDataPage.tsx
│ ├── LaunchParamsPage.tsx
│ ├── TONConnectPage
│ ├── TONConnectPage.css
│ └── TONConnectPage.tsx
│ └── ThemeParamsPage.tsx
├── tsconfig.json
├── tsconfig.node.json
└── vite.config.ts
/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: true,
4 | es2021: true
5 | },
6 | extends: [
7 | 'eslint:recommended',
8 | 'plugin:@typescript-eslint/recommended',
9 | 'plugin:react/recommended'
10 | ],
11 | overrides: [
12 | {
13 | env: {
14 | node: true
15 | },
16 | files: [
17 | '.eslintrc.{js,cjs}'
18 | ],
19 | parserOptions: {
20 | 'sourceType': 'script'
21 | }
22 | }
23 | ],
24 | parser: '@typescript-eslint/parser',
25 | parserOptions: {
26 | ecmaVersion: 'latest',
27 | sourceType: 'module'
28 | },
29 | plugins: [
30 | '@typescript-eslint',
31 | 'react'
32 | ],
33 | rules: {
34 | 'react/react-in-jsx-scope': 0,
35 | }
36 | };
37 |
--------------------------------------------------------------------------------
/.github/deployment-branches.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Telegram-Mini-Apps/reactjs-template/59212756e1782ffb962af763063387a1a46a1ea6/.github/deployment-branches.png
--------------------------------------------------------------------------------
/.github/workflows/github-pages-deploy.yml:
--------------------------------------------------------------------------------
1 | # Simple workflow for deploying static content to GitHub Pages
2 | name: Deploy static content to Pages
3 |
4 | on:
5 | # Runs on pushes targeting the default branch
6 | push:
7 | branches: ['master']
8 |
9 | # Allows you to run this workflow manually from the Actions tab
10 | workflow_dispatch:
11 |
12 | # Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
13 | permissions:
14 | contents: read
15 | pages: write
16 | id-token: write
17 |
18 | # Allow one concurrent deployment
19 | concurrency:
20 | group: 'pages'
21 | cancel-in-progress: true
22 |
23 | jobs:
24 | # Single deploy job since we're just deploying
25 | deploy:
26 | environment:
27 | name: github-pages
28 | url: ${{ steps.deployment.outputs.page_url }}
29 | runs-on: ubuntu-latest
30 | steps:
31 | - name: Checkout
32 | uses: actions/checkout@v4
33 |
34 | - name: Setup node
35 | uses: actions/setup-node@v3
36 | with:
37 | node-version: 18
38 | registry-url: 'https://registry.npmjs.org'
39 |
40 | - name: Install deps
41 | run: npm ci
42 |
43 | - name: Build
44 | run: npm run build
45 |
46 | - name: Setup Pages
47 | uses: actions/configure-pages@v5
48 |
49 | - name: Upload artifact
50 | uses: actions/upload-pages-artifact@v3
51 | with:
52 | # Upload dist repository
53 | path: './dist'
54 |
55 | - name: Deploy to GitHub Pages
56 | id: deployment
57 | uses: actions/deploy-pages@v4
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
26 | *.pem
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Telegram Mini Apps
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Telegram Mini Apps React Template
2 |
3 | This template demonstrates how developers can implement a single-page
4 | application on the Telegram Mini Apps platform using the following technologies
5 | and libraries:
6 |
7 | - [React](https://react.dev/)
8 | - [TypeScript](https://www.typescriptlang.org/)
9 | - [TON Connect](https://docs.ton.org/develop/dapps/ton-connect/overview)
10 | - [@telegram-apps SDK](https://docs.telegram-mini-apps.com/packages/telegram-apps-sdk/2-x)
11 | - [Telegram UI](https://github.com/Telegram-Mini-Apps/TelegramUI)
12 | - [Vite](https://vitejs.dev/)
13 |
14 | > The template was created using [npm](https://www.npmjs.com/). Therefore, it is
15 | > required to use it for this project as well. Using other package managers, you
16 | > will receive a corresponding error.
17 |
18 | ## Install Dependencies
19 |
20 | If you have just cloned this template, you should install the project
21 | dependencies using the command:
22 |
23 | ```Bash
24 | npm install
25 | ```
26 |
27 | ## Scripts
28 |
29 | This project contains the following scripts:
30 |
31 | - `dev`. Runs the application in development mode.
32 | - `dev:https`. Runs the application in development mode using locally created valid SSL-certificates.
33 | - `build`. Builds the application for production.
34 | - `lint`. Runs [eslint](https://eslint.org/) to ensure the code quality meets
35 | the required standards.
36 | - `deploy`. Deploys the application to GitHub Pages.
37 |
38 | To run a script, use the `npm run` command:
39 |
40 | ```Bash
41 | npm run {script}
42 | # Example: npm run build
43 | ```
44 |
45 | ## Create Bot and Mini App
46 |
47 | Before you start, make sure you have already created a Telegram Bot. Here is
48 | a [comprehensive guide](https://docs.telegram-mini-apps.com/platform/creating-new-app)
49 | on how to do it.
50 |
51 | ## Run
52 |
53 | Although Mini Apps are designed to be opened
54 | within [Telegram applications](https://docs.telegram-mini-apps.com/platform/about#supported-applications),
55 | you can still develop and test them outside of Telegram during the development
56 | process.
57 |
58 | To run the application in the development mode, use the `dev` script:
59 |
60 | ```bash
61 | npm run dev:https
62 | ```
63 |
64 | > [!NOTE]
65 | > As long as we use [vite-plugin-mkcert](https://www.npmjs.com/package/vite-plugin-mkcert),
66 | > launching the dev mode for the first time, you may see sudo password request.
67 | > The plugin requires it to properly configure SSL-certificates. To disable the plugin, use the `npm run dev` command.
68 |
69 | After this, you will see a similar message in your terminal:
70 |
71 | ```bash
72 | VITE v5.2.12 ready in 237 ms
73 |
74 | ➜ Local: https://localhost:5173/reactjs-template
75 | ➜ Network: https://172.18.16.1:5173/reactjs-template
76 | ➜ Network: https://172.19.32.1:5173/reactjs-template
77 | ➜ Network: https://192.168.0.171:5173/reactjs-template
78 | ➜ press h + enter to show help
79 | ```
80 |
81 | Here, you can see the `Local` link, available locally, and `Network` links
82 | accessible to all devices in the same network with the current device.
83 |
84 | To view the application, you need to open the `Local`
85 | link (`https://localhost:5173/reactjs-template` in this example) in your
86 | browser:
87 |
88 | 
89 |
90 | It is important to note that some libraries in this template, such as
91 | `@telegram-apps/sdk`, are not intended for use outside of Telegram.
92 |
93 | Nevertheless, they appear to function properly. This is because the
94 | `src/mockEnv.ts` file, which is imported in the application's entry point (
95 | `src/index.ts`), employs the `mockTelegramEnv` function to simulate the Telegram
96 | environment. This trick convinces the application that it is running in a
97 | Telegram-based environment. Therefore, be cautious not to use this function in
98 | production mode unless you fully understand its implications.
99 |
100 | > [!WARNING]
101 | > Because we are using self-signed SSL certificates, the Android and iOS
102 | > Telegram applications will not be able to display the application. These
103 | > operating systems enforce stricter security measures, preventing the Mini App
104 | > from loading. To address this issue, refer to
105 | > [this guide](https://docs.telegram-mini-apps.com/platform/getting-app-link#remote).
106 |
107 | ## Deploy
108 |
109 | This boilerplate uses GitHub Pages as the way to host the application
110 | externally. GitHub Pages provides a CDN which will let your users receive the
111 | application rapidly. Alternatively, you could use such services
112 | as [Heroku](https://www.heroku.com/) or [Vercel](https://vercel.com).
113 |
114 | ### Manual Deployment
115 |
116 | This boilerplate uses the [gh-pages](https://www.npmjs.com/package/gh-pages)
117 | tool, which allows deploying your application right from your PC.
118 |
119 | #### Configuring
120 |
121 | Before running the deployment process, ensure that you have done the following:
122 |
123 | 1. Replaced the `homepage` value in `package.json`. The GitHub Pages deploy tool
124 | uses this value to
125 | determine the related GitHub project.
126 | 2. Replaced the `base` value in `vite.config.ts` and have set it to the name of
127 | your GitHub
128 | repository. Vite will use this value when creating paths to static assets.
129 |
130 | For instance, if your GitHub username is `telegram-mini-apps` and the repository
131 | name is `is-awesome`, the value in the `homepage` field should be the following:
132 |
133 | ```json
134 | {
135 | "homepage": "https://telegram-mini-apps.github.io/is-awesome"
136 | }
137 | ```
138 |
139 | And `vite.config.ts` should have this content:
140 |
141 | ```ts
142 | export default defineConfig({
143 | base: '/is-awesome/',
144 | // ...
145 | });
146 | ```
147 |
148 | You can find more information on configuring the deployment in the `gh-pages`
149 | [docs](https://github.com/tschaub/gh-pages?tab=readme-ov-file#github-pages-project-sites).
150 |
151 | #### Before Deploying
152 |
153 | Before deploying the application, make sure that you've built it and going to
154 | deploy the fresh static files:
155 |
156 | ```bash
157 | npm run build
158 | ```
159 |
160 | Then, run the deployment process, using the `deploy` script:
161 |
162 | ```Bash
163 | npm run deploy
164 | ```
165 |
166 | After the deployment completed successfully, visit the page with data according
167 | to your username and repository name. Here is the page link example using the
168 | data mentioned above:
169 | https://telegram-mini-apps.github.io/is-awesome
170 |
171 | ### GitHub Workflow
172 |
173 | To simplify the deployment process, this template includes a
174 | pre-configured [GitHub workflow](.github/workflows/github-pages-deploy.yml) that
175 | automatically deploys the project when changes are pushed to the `master`
176 | branch.
177 |
178 | To enable this workflow, create a new environment (or edit the existing one) in
179 | the GitHub repository settings and name it `github-pages`. Then, add the
180 | `master` branch to the list of deployment branches.
181 |
182 | You can find the environment settings using this
183 | URL: `https://github.com/{username}/{repository}/settings/environments`.
184 |
185 | 
186 |
187 | In case, you don't want to do it automatically, or you don't use GitHub as the
188 | project codebase, remove the `.github` directory.
189 |
190 | ### GitHub Web Interface
191 |
192 | Alternatively, developers can configure automatic deployment using the GitHub
193 | web interface. To do this, follow the link:
194 | `https://github.com/{username}/{repository}/settings/pages`.
195 |
196 | ## TON Connect
197 |
198 | This boilerplate utilizes
199 | the [TON Connect](https://docs.ton.org/develop/dapps/ton-connect/overview)
200 | project to demonstrate how developers can integrate functionality related to TON
201 | cryptocurrency.
202 |
203 | The TON Connect manifest used in this boilerplate is stored in the `public`
204 | folder, where all publicly accessible static files are located. Remember
205 | to [configure](https://docs.ton.org/develop/dapps/ton-connect/manifest) this
206 | file according to your project's information.
207 |
208 | ## Useful Links
209 |
210 | - [Platform documentation](https://docs.telegram-mini-apps.com/)
211 | - [@telegram-apps/sdk-react documentation](https://docs.telegram-mini-apps.com/packages/telegram-apps-sdk-react)
212 | - [Telegram developers community chat](https://t.me/devs)
213 |
--------------------------------------------------------------------------------
/assets/application.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Telegram-Mini-Apps/reactjs-template/59212756e1782ffb962af763063387a1a46a1ea6/assets/application.png
--------------------------------------------------------------------------------
/eslint.config.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 |
3 | import eslint from '@eslint/js';
4 | import tseslint from 'typescript-eslint';
5 | import react from 'eslint-plugin-react';
6 | import reactHooks from 'eslint-plugin-react-hooks';
7 | import globals from 'globals';
8 |
9 | export default tseslint.config(
10 | {
11 | files: ['src/**/*.{js,jsx,mjs,cjs,ts,tsx}'],
12 | extends: [
13 | eslint.configs.recommended,
14 | ...tseslint.configs.recommendedTypeChecked,
15 | ],
16 | plugins: {
17 | react,
18 | 'react-hooks': reactHooks
19 | },
20 | languageOptions: {
21 | parserOptions: {
22 | ecmaVersion: 'latest',
23 | sourceType: 'module',
24 | ecmaFeatures: {
25 | jsx: true,
26 | },
27 | },
28 | globals: {
29 | ...globals.browser,
30 | },
31 | },
32 | rules: {
33 | '@typescript-eslint/no-unused-expressions': 0,
34 | },
35 | }
36 | );
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |