From 04c3441b427b92f849fcb10ad3698d66ae9f3f1e Mon Sep 17 00:00:00 2001 From: user Date: Wed, 28 Feb 2024 23:45:38 +0300 Subject: [PATCH] dev@locazia: make wallet buttons --- app/bot/routers/index.py | 31 +++++++++++++++++++++++++++++++ app/bot/routers/tonconnect.py | 2 -- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/bot/routers/index.py b/app/bot/routers/index.py index b3364e0..52dd4f4 100644 --- a/app/bot/routers/index.py +++ b/app/bot/routers/index.py @@ -9,6 +9,8 @@ from app.bot.routers.tonconnect import router as tonconnect_router from app.core._utils.tg_process_template import tg_process_template from app.core._keyboards import get_inline_keyboard from app.core.logger import logger +from app.core.models.wallet_connection import WalletConnection +from app.core.models._blockchain.ton.connect import TonConnect, unpack_wallet_info from app.core._config import WEB_APP_URLS main_router = Router() @@ -19,6 +21,35 @@ async def t_home_menu(__msg, **extra): if extra.get('state'): await extra['state'].clear() + if not db_session.query(WalletConnection).filter( + WalletConnection.user_id == user.id, + WalletConnection.invalidated == False + ).first(): + ton_connect, ton_connection = TonConnect.by_user(db_session, user, callback_fn=()) + await ton_connect.restore_connection() + wallets = ton_connect._sdk_client.get_wallets() + message_text = user.translated("connectWalletsList_menu") + return await tg_process_template( + chat_wrap, message_text, + keyboard=get_inline_keyboard([ + [ + { + 'text': f"{wallets[i]['name']}", + 'url': f"initTonconnect_{wallets[i]['app_name']}" + } if i < len(wallets) else None, + { + 'text': f"{wallets[i + 1]['name']}", + 'url': f"initTonconnect_{wallets[i + 1]['app_name']}" + } if i + 1 < len(wallets) else None, + { + 'text': f"{wallets[i + 2]['name']}", + 'url': f"initTonconnect_{wallets[i + 2]['app_name']}" + } if i + 2 < len(wallets) else None, + ] + for i in range(0, len(wallets), 3) + ]) + ) + return await tg_process_template( chat_wrap, user.translated('home_menu'), message_id=__msg.message.message_id if isinstance(__msg, types.CallbackQuery) else None, keyboard=get_inline_keyboard([ diff --git a/app/bot/routers/tonconnect.py b/app/bot/routers/tonconnect.py index 974324a..cdf3821 100644 --- a/app/bot/routers/tonconnect.py +++ b/app/bot/routers/tonconnect.py @@ -64,6 +64,4 @@ Use /dev_tonconnect {wallet_app_name} for connect to wallet.""" keyboard=get_inline_keyboard(keyboard) if keyboard else None ) -# async def t_tonconnect_wallets_list() - router.message.register(t_tonconnect_dev_menu, Command('dev_tonconnect'))