dev@locazia: add disconnect wallet button
This commit is contained in:
parent
658b63f495
commit
8e0cd027bc
|
|
@ -27,7 +27,7 @@ async def t_callback_owned_content(query: types.CallbackQuery, memory=None, user
|
|||
'text': user.translated('back_button'),
|
||||
'callback_data': 'home'
|
||||
}]
|
||||
])
|
||||
]), message_id=query.message.message_id
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,17 +18,24 @@ from app.core._config import WEB_APP_URLS
|
|||
main_router = Router()
|
||||
|
||||
|
||||
async def t_home_menu(__msg, **extra):
|
||||
memory, user, db_session, chat_wrap = extra['memory'], extra['user'], extra['db_session'], extra['chat_wrap']
|
||||
if extra.get('state'):
|
||||
await extra['state'].clear()
|
||||
async def send_home_menu(chat_wrap, user, wallet_connection):
|
||||
return await tg_process_template(
|
||||
chat_wrap, user.translated('home_menu').format(
|
||||
wallet_address=wallet_connection.wallet_address
|
||||
), keyboard=get_inline_keyboard([
|
||||
[{
|
||||
'text': user.translated('ownedContent_button'),
|
||||
'callback_data': 'ownedContent'
|
||||
}],
|
||||
[{
|
||||
'text': user.translated('disconnectWallet_button'),
|
||||
'callback_data': 'disconnectWallet'
|
||||
}]
|
||||
])
|
||||
)
|
||||
|
||||
wallet_connection = db_session.query(WalletConnection).filter(
|
||||
WalletConnection.user_id == user.id,
|
||||
WalletConnection.invalidated == False
|
||||
).first()
|
||||
|
||||
if not wallet_connection:
|
||||
async def send_connect_wallets_list(db_session, chat_wrap, user):
|
||||
ton_connect, ton_connection = TonConnect.by_user(db_session, user, callback_fn=())
|
||||
await ton_connect.restore_connection()
|
||||
wallets = ton_connect._sdk_client.get_wallets()
|
||||
|
|
@ -50,21 +57,21 @@ async def t_home_menu(__msg, **extra):
|
|||
])
|
||||
)
|
||||
|
||||
return await tg_process_template(
|
||||
chat_wrap, user.translated('home_menu').format(
|
||||
wallet_address=wallet_connection.wallet_address
|
||||
), message_id=__msg.message.message_id if isinstance(__msg, types.CallbackQuery) else None,
|
||||
keyboard=get_inline_keyboard([
|
||||
[{
|
||||
'text': user.translated('ownedContent_button'),
|
||||
'callback_data': 'ownedContent'
|
||||
}],
|
||||
[{
|
||||
'text': user.translated('disconnectWallet_button'),
|
||||
'callback_data': 'disconnectWallet'
|
||||
}]
|
||||
])
|
||||
)
|
||||
|
||||
async def t_home_menu(__msg, **extra):
|
||||
memory, user, db_session, chat_wrap = extra['memory'], extra['user'], extra['db_session'], extra['chat_wrap']
|
||||
if extra.get('state'):
|
||||
await extra['state'].clear()
|
||||
|
||||
wallet_connection = db_session.query(WalletConnection).filter(
|
||||
WalletConnection.user_id == user.id,
|
||||
WalletConnection.invalidated == False
|
||||
).first()
|
||||
|
||||
if not wallet_connection:
|
||||
return await send_connect_wallets_list(db_session, chat_wrap, user)
|
||||
|
||||
return await send_home_menu(chat_wrap, user, wallet_connection)
|
||||
|
||||
|
||||
main_router.message.register(t_home_menu, Command('start'))
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ from app.core._keyboards import get_inline_keyboard
|
|||
from app.core._utils.tg_process_template import tg_process_template
|
||||
from app.core.logger import make_log
|
||||
from app.core.models._blockchain.ton.connect import TonConnect, unpack_wallet_info
|
||||
from app.core.models.wallet_connection import WalletConnection
|
||||
from app.bot.routers.index import send_connect_wallets_list
|
||||
|
||||
router = Router()
|
||||
|
||||
|
|
@ -83,9 +85,21 @@ async def t_callback_init_tonconnect(query: types.CallbackQuery, memory=None, us
|
|||
'url': connection_link
|
||||
}
|
||||
]
|
||||
])
|
||||
]), message_id=query.message.message_id
|
||||
)
|
||||
|
||||
|
||||
async def t_callback_disconnect_wallet(query: types.CallbackQuery, memory=None, user=None, db_session=None, chat_wrap=None, **extra):
|
||||
wallet_connections = db_session.query(WalletConnection).filter(
|
||||
WalletConnection.user_id == user.id,
|
||||
WalletConnection.invalidated == False
|
||||
).all()
|
||||
for wallet_connection in wallet_connections:
|
||||
wallet_connection.invalidated = True
|
||||
|
||||
db_session.commit()
|
||||
return await send_connect_wallets_list(db_session, chat_wrap, user)
|
||||
|
||||
router.message.register(t_tonconnect_dev_menu, Command('dev_tonconnect'))
|
||||
router.callback_query.register(t_callback_init_tonconnect, F.data.startswith('initTonconnect_'))
|
||||
router.callback_query.register(t_callback_disconnect_wallet, F.data == 'disconnectWallet')
|
||||
|
|
|
|||
Loading…
Reference in New Issue