File size: 3,397 Bytes
c66532a 4b6073f 52c3f76 71eba6c 4b6073f 71eba6c 4b6073f 71eba6c 4b6073f 71eba6c 4b6073f 71eba6c 4b6073f 71eba6c c66532a 71eba6c 4b6073f c66532a 71eba6c 4b6073f 71eba6c 4b6073f 71eba6c c66532a 4b6073f 71eba6c c66532a 71eba6c 4b6073f c66532a dcb96db 71eba6c ebbc020 c66532a fe269d1 71eba6c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
from flask import Flask, Response, request
import requests
app = Flask(__name__)
@app.route('/')
def index():
html_content = '''
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>TON Connect</title>
<script src="https://unpkg.com/@tonconnect/ui@latest/dist/tonconnect-ui.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #111;
color: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
h1 {
margin-bottom: 20px;
}
#ton-connect-button {
margin-top: 10px;
}
#status, #balance {
margin-top: 15px;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Подключение к TON</h1>
<div id="ton-connect-button"></div>
<div id="status">Статус: не подключено</div>
<div id="balance">Баланс: —</div>
<script>
const tonConnectUI = new TON_CONNECT_UI.TonConnectUI({
manifestUrl: 'https://huggingface.co/spaces/Aleksmorshen/MorshenGroup/resolve/main/tonconnect-manifest.json',
buttonRootId: 'ton-connect-button'
});
async function fetchBalance(address) {
try {
const res = await fetch(`/get_balance?address=${address}`);
const data = await res.json();
if (data.balance !== undefined) {
document.getElementById('balance').innerText = `Баланс: ${data.balance} TON`;
} else {
document.getElementById('balance').innerText = `Баланс: ошибка`;
}
} catch (e) {
document.getElementById('balance').innerText = `Баланс: ошибка`;
}
}
tonConnectUI.onStatusChange(wallet => {
const statusDiv = document.getElementById('status');
if (wallet) {
const address = wallet.account.address;
statusDiv.innerText = `✅ Подключено: ${address}`;
fetchBalance(address);
} else {
statusDiv.innerText = '❌ Не подключено';
document.getElementById('balance').innerText = `Баланс: —`;
}
});
</script>
</body>
</html>
'''
return Response(html_content, mimetype='text/html')
@app.route('/get_balance')
def get_balance():
address = request.args.get('address')
if not address:
return {'error': 'No address provided'}, 400
try:
res = requests.get(f'https://tonapi.io/v2/accounts/{address}')
data = res.json()
raw_balance = int(data.get('balance', 0))
ton_balance = raw_balance / 1e9
return {'balance': round(ton_balance, 4)}
except:
return {'error': 'failed to fetch'}, 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860) |