-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from Teri-anric/feat/add-telegram
Prepare app to integrate telegram mini-app
- Loading branch information
Showing
26 changed files
with
860 additions
and
37 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import './telegramLogin.css'; | ||
|
||
const TelegramLogin = ({ user, onLogin }) => { | ||
useEffect(() => { | ||
const initTelegramLogin = () => { | ||
const tg = window.Telegram.WebApp; | ||
tg.ready(); | ||
|
||
const user = tg.initDataUnsafe?.user; | ||
if (user) { | ||
onLogin(user); | ||
} | ||
}; | ||
|
||
initTelegramLogin(); | ||
}, [onLogin]); | ||
|
||
const handleLogin = () => { | ||
window.Telegram.Login.auth({ | ||
bot_id: process.env.REACT_APP_BOT_ID, | ||
request_access: 'write' | ||
}, onLogin) | ||
}; | ||
|
||
const handleLogout = () => { | ||
localStorage.removeItem('tg_user'); | ||
onLogin(null); | ||
}; | ||
|
||
return ( | ||
<div className="telegram-login"> | ||
{user ? ( | ||
<div className="user-info" onClick={handleLogout}> | ||
{user.photo_url ? ( | ||
<img src={user.photo_url} alt={user.first_name} className="user-photo" /> | ||
) : ( | ||
<div className="user-photo-placeholder" /> | ||
)} | ||
<span className="user-name">{user.first_name}</span> | ||
</div> | ||
) : ( | ||
<button className="btn-telegram" onClick={handleLogin}> | ||
Login with Telegram | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TelegramLogin; |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
.telegram-login { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.user-info { | ||
background: var(--gradient); | ||
border-radius: 8px; | ||
height: 52px; | ||
width: 190px; | ||
padding: 0 10px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-start; | ||
gap: 10px; | ||
} | ||
|
||
.user-photo { | ||
width: 40px; | ||
height: 40px; | ||
border-radius: 50%; | ||
object-fit: cover; | ||
} | ||
|
||
.user-name { | ||
color: var(--black); | ||
font-size: 16px; | ||
font-family: var(--text-font); | ||
font-weight: 700; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
.btn-telegram { | ||
background: var(--button-gradient); | ||
color: var(--black); | ||
border: none; | ||
height: 52px; | ||
padding: 0 20px; | ||
border-radius: 8px; | ||
cursor: pointer; | ||
font-size: 20px; | ||
font-family: var(--text-font); | ||
font-weight: 700; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.btn-telegram:hover { | ||
background: var(--button-gradient-hover); | ||
} | ||
|
||
.btn-telegram:active { | ||
background: var(--button-gradient-active); | ||
} | ||
|
||
/* div.user-photo-placeholder { | ||
add style to user placeholder | ||
} */ |
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 |
---|---|---|
|
@@ -64,6 +64,8 @@ nav { | |
.wallet-section { | ||
position: absolute; | ||
right: 10px; | ||
display: flex; | ||
gap: 10px; | ||
} | ||
|
||
.nav-items a { | ||
|
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import axios from 'axios'; | ||
|
||
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || 'http://localhost:8000'; | ||
|
||
export const saveTelegramUser = async (telegramUser, walletId) => { | ||
try { | ||
const response = await axios.post(`${API_BASE_URL}/api/telegram/save-user`, { | ||
telegram_id: telegramUser.id, | ||
username: telegramUser.username, | ||
first_name: telegramUser.first_name, | ||
last_name: telegramUser.last_name, | ||
photo_url: telegramUser.photo_url, | ||
wallet_id: walletId | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error saving Telegram user:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const getTelegramUserWalletId = async (tg_user) => { | ||
try { | ||
const response = await axios.post(`${API_BASE_URL}/api/telegram/get-wallet-id/${tg_user.id}`, { | ||
raw: window.Telegram.initData || tg_user, | ||
is_webapp: !!window.Telegram.initData | ||
}); | ||
return response.data.wallet_id; | ||
} catch (error) { | ||
console.error('Error getting wallet ID for Telegram user:', error); | ||
throw error; | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
fastapi==0.115.0 | ||
black==24.8.0 | ||
isort==5.13.2 | ||
psycopg2-binary==2.9.9 | ||
python-dotenv==1.0.1 | ||
uvicorn==0.30.6 | ||
starknet-py==0.24.2 | ||
jinja2==3.1.4 | ||
python-multipart==0.0.9 | ||
itsdangerous==2.2.0 | ||
alembic==1.13.3 | ||
psycopg2-binary==2.9.9 | ||
SQLAlchemy==2.0.35 | ||
pytest==8.3.3 | ||
pytest-asyncio==0.24.0 | ||
pytest-env==1.1.5 | ||
pytest-mock==3.14.0 | ||
httpx==0.27.2 | ||
aiogram>=3.13.1 | ||
celery==5.4.0 | ||
redis==5.2.0 | ||
trio==0.27.0 |
Oops, something went wrong.