From 836adaf7b2040d96e7a6b4d6aafd450df65fcc41 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 8 Mar 2024 22:58:48 +0300 Subject: [PATCH] dev@locazia: add "confirm tx" message --- app/api/routes/_blockchain.py | 18 ++++- app/core/_blockchain/ton/connect.py | 37 ++++++++++ app/core/background/indexer_service.py | 3 +- app/core/models/node_storage.py | 7 ++ locale/en/LC_MESSAGES/sanic_telegram_bot.mo | Bin 1223 -> 1566 bytes locale/en/LC_MESSAGES/sanic_telegram_bot.po | 77 +++++++++++++------- 6 files changed, 113 insertions(+), 29 deletions(-) diff --git a/app/api/routes/_blockchain.py b/app/api/routes/_blockchain.py index 0dfbd16..2e9cef5 100644 --- a/app/api/routes/_blockchain.py +++ b/app/api/routes/_blockchain.py @@ -6,7 +6,7 @@ from sanic import response from tonsdk.boc import begin_cell, begin_dict from tonsdk.utils import Address -from app.core._blockchain.ton.connect import TonConnect +from app.core._blockchain.ton.connect import TonConnect, TON_CONNECT_WALLETS_LIST from app.core._blockchain.ton.platform import platform from app.core._config import PROJECT_HOST from app.core.logger import make_log @@ -14,6 +14,8 @@ from app.core._utils.resolve_content import resolve_content from app.core.content.utils import create_metadata_for_item from app.core._crypto.content import create_encrypted_content from app.core.models.node_storage import StoredContent +from app.core.models._telegram import Wrapped_CBotChat +from app.core._keyboards import get_inline_keyboard def valid_royalty_params(royalty_params): @@ -137,6 +139,20 @@ async def s_api_v1_blockchain_send_new_content_message(request): ] })) + await (Wrapped_CBotChat(request.app.memory._telegram_bot, chat_id=request.ctx.user.telegram_id)).send_message( + request.ctx.user.translated('p_tonconnectTransactionRequested'), + reply_markup=get_inline_keyboard([ + [{ + 'text': request.ctx.user.translated('gotoWallet_button'), + 'url': next(x['universal_url'] for x in TON_CONNECT_WALLETS_LIST if x['app_name'] == ton_connection.wallet_key['app_name']) + }], + [{ + 'text': request.ctx.user.translated('home_button'), + 'callback_data': 'home' + }] + ]) + ) + return response.json({"message": "Transaction requested"}) except BaseException as e: make_log("Blockchain", f"Error while sending new content message: {e}" + '\n' + traceback.format_exc(), level='error') diff --git a/app/core/_blockchain/ton/connect.py b/app/core/_blockchain/ton/connect.py index 0b6a981..1318d41 100644 --- a/app/core/_blockchain/ton/connect.py +++ b/app/core/_blockchain/ton/connect.py @@ -13,6 +13,40 @@ from app.core.models.wallet_connection import WalletConnection TON_CONNECT_MANIFEST_URI = os.getenv("TON_CONNECT_MANIFEST_URI") +TON_CONNECT_WALLETS_LIST = [ + { + 'about_url': 'https://wallet.tg/', + 'app_name': 'telegram-wallet', + 'bridge_url': 'https://bridge.tonapi.io/bridge', + 'image': 'https://wallet.tg/images/logo-288.png', + 'name': 'Wallet', + 'universal_url': 'https://t.me/wallet?attach=wallet&startattach=tonconnect' + }, + { + 'about_url': 'https://tonkeeper.com', + 'app_name': 'tonkeeper', + 'bridge_url': 'https://bridge.tonapi.io/bridge', + 'image': 'https://tonkeeper.com/assets/tonconnect-icon.png', + 'name': 'Tonkeeper', + 'universal_url': 'https://app.tonkeeper.com/ton-connect'}, + { + 'about_url': 'https://mytonwallet.io', + 'app_name': 'mytonwallet', + 'bridge_url': 'https://tonconnectbridge.mytonwallet.org/bridge/', + 'image': 'https://mytonwallet.io/icon-256.png', + 'name': 'MyTonWallet', + 'universal_url': 'https://connect.mytonwallet.org' + }, + { + 'about_url': 'https://tonhub.com', + 'app_name': 'tonhub', + 'bridge_url': 'https://connect.tonhubapi.com/tonconnect', + 'image': 'https://tonhub.com/tonconnect_logo.png', + 'name': 'Tonhub', + 'universal_url': 'https://tonhub.com/ton-connect' + } +] + def unpack_wallet_info(wallet_info) -> dict: return { @@ -65,6 +99,9 @@ class TonConnect: if wallet["app_name"] == app_name: return await self._sdk_client.connect(wallet) + async def raw_new_connection(self, app_startup: dict): + return await self._sdk_client.connect(app_startup) + async def restore_connection(self): return await self._sdk_client.restore_connection() diff --git a/app/core/background/indexer_service.py b/app/core/background/indexer_service.py index 0a68cdb..32761f0 100644 --- a/app/core/background/indexer_service.py +++ b/app/core/background/indexer_service.py @@ -111,7 +111,8 @@ async def indexer_loop(platform_found: bool, seqno: int) -> [bool, int]: ).first() encrypted_stored_content = session.query(StoredContent).filter( - StoredContent.hash == item_content_hash_str + StoredContent.hash == item_content_hash_str, + StoredContent.type.like("local%") ).first() if encrypted_stored_content: encrypted_stored_content_meta = encrypted_stored_content.meta diff --git a/app/core/models/node_storage.py b/app/core/models/node_storage.py index aacc8ad..64708ca 100644 --- a/app/core/models/node_storage.py +++ b/app/core/models/node_storage.py @@ -49,6 +49,13 @@ class StoredContent(AlchemyBase): accept_type=self.meta.get('content_type', 'image/jpeg') ) + @property + def decrypt_possible(self) -> bool: + if self.encrypted is False: + return True + + return bool(self.key_id or self.decrypted_content_id) + def json_format(self): extra_fields = {} if self.btfs_cid: diff --git a/locale/en/LC_MESSAGES/sanic_telegram_bot.mo b/locale/en/LC_MESSAGES/sanic_telegram_bot.mo index 602c09252c1c4dfa45d28a50414ed02913b80292..b496b38157c1358983a3dac41f5d0fef1e6be393 100644 GIT binary patch delta 844 zcmY+>J8aWH7zgmn187Z3d8t7H#IZ1d(kdH@q9|@-+7vs9@+xgrA}2i@3&#%5MTjYg z4GB~s2eFZ*%pk#l5IYMa0~13e76#}-B{u$N3@M*<{@pA0-F^8m{X91Kax(gqAZF3d zp$*aEXt5AJh&DV5O(^F3fsf&7j9dUV0|CXVLTNkgu)9D>jRQS z=PV|wfn6BK=0{K*xEmp)1YbdMKqyK`5}tu#eKoKSA7I>s;xS+0BK!$2!mEdn18%@P zdaX18iOyPSh=pPA`pm?1~ECN6M7s%rW?&)7Z3}R?_2bu9^LbdaT z!<{wVvKVhP`dE4ZT z4zv3Q=89cr|ChjfA4<-a9h+ z)q6bQ=e2b1xG8$ArmD0cYYI&(nw(d&axPa^DwPbj+D2bDSfa}GPKv5>VYw!fq*XO* zne&coO!lOxq~$dwQD<%suSwCQcQbrrZh@{btAz?s?oe%=ZtjhSZ??Q|;dx2S@HV4O z$BReQxOf-6>sOA9pWXlQc84zNt=nER(hBQ6?^9%09q+uR>1O6Y(Wv{kYUzb$Mw0eM zPae{e#q=JdDDf@R?f5zPq|Vf|={=|K2Dv;Vx_XIhF8%pGg2^qiH}ZCAt!p{@wm670 Go0H$1X2hxh delta 451 zcmX}my-LGS6bJB|kE(5jS}iSp!F5$zZ-NSjQpCY;xAp;&G_=KVQ`%dqQ~L&jS65wJ zbm<_txz@$OQ5Qja8#kRA5Ca;%!6#${!74I}#Q$!_!?2{Ml;o?jBRAEQ ztgB2hWKUgOH<`JbWoFjgpvssE>Qr!>iGIawkJTAyDtolvg diff --git a/locale/en/LC_MESSAGES/sanic_telegram_bot.po b/locale/en/LC_MESSAGES/sanic_telegram_bot.po index 8ba1af8..28fdaba 100644 --- a/locale/en/LC_MESSAGES/sanic_telegram_bot.po +++ b/locale/en/LC_MESSAGES/sanic_telegram_bot.po @@ -6,62 +6,85 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: 1\n" +"Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-29 01:26+0300\n" -"PO-Revision-Date: 2024-02-29 01:00+0\n" -"Last-Translator: oscux\n" -"Language: en\n" +"POT-Creation-Date: 2024-03-08 22:45+0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: app/bot/routers/home.py:16 +#: app/bot/routers/home.py:16 app/bot/routers/home.py:15 +#: app/client_bot/routers/home.py:15 msgid "home_menu" -msgstr "Hi, {name}!" -"\n\n" -"Here you can upload your content to the blockchain and manage it." -"\n\n" -"You logged in with wallet: {wallet_address}" +msgstr "" +"Hi, {name}!\n" +"\n" +"Here you can upload your content to the blockchain and manage it.\n" +"\n" +"You logged as {wallet_address}" -#: app/bot/routers/home.py:20 +#: app/bot/routers/home.py:20 app/client_bot/routers/home.py:20 msgid "ownedContent_button" msgstr "šŸ“Š My content" -#: app/bot/routers/home.py:24 +#: app/bot/routers/home.py:24 app/client_bot/routers/home.py:24 msgid "disconnectWallet_button" msgstr "šŸ”Œ Disconnect wallet" -#: app/bot/routers/home.py:35 +#: app/bot/routers/home.py:35 app/client_bot/routers/home.py:35 msgid "connectWalletsList_menu" -msgstr "–> To work, you need to connect your wallet" -"\n\n" -"Please select the wallet you want to connect:" +msgstr "" +"/ Welcome to MY [šŸ”“]\n" +"\n" +"Please select the wallet you want to connect to the bot:" -#: app/bot/routers/index.py:23 +#: app/bot/routers/index.py:23 app/bot/routers/index.py:22 +#: app/client_bot/routers/index.py:18 msgid "error_unknownCommand" msgstr "Unknown command, please try again or press /start" -#: app/bot/routers/content.py:16 +#: app/bot/routers/content.py:16 app/bot/routers/content.py:12 msgid "ownedContent_menu" -msgstr "šŸ“Š My content" -"\n\n" +msgstr "" +"šŸ“Š My content\n" +"\n" "Here you can see the list of your content." -#: app/bot/routers/content.py:21 +#: app/bot/routers/content.py:21 app/bot/routers/content.py:17 msgid "webApp_uploadContent_button" msgstr "šŸ“¤ Upload content" -#: app/bot/routers/content.py:27 +#: app/bot/routers/content.py:27 app/bot/routers/content.py:23 msgid "back_button" msgstr "ā—€ļø Back" #: app/bot/routers/tonconnect.py:80 msgid "tonconnectInit_menu" -msgstr "šŸ”Œ Connect wallet" -"\n\n" -"Press the button below to connect your wallet." +msgstr "" +"šŸ”Œ Connect wallet\n" +"\n" +"Press the button below to connect your wallet" -#: app/bot/routers/tonconnect.py:101 +#: app/bot/routers/tonconnect.py:101 app/bot/routers/tonconnect.py:105 msgid "p_successConnectWallet" msgstr "āœ… Wallet connected successfully" + +#: app/api/routes/_blockchain.py:143 +msgid "p_tonconnectTransactionRequested" +msgstr "ā³ Transaction requested\n\nšŸ‘‰ Please confirm the transaction in your wallet" + +#: app/api/routes/_blockchain.py:146 +msgid "gotoWallet_button" +msgstr "Open wallet" + +#: app/api/routes/_blockchain.py:150 app/bot/routers/tonconnect.py:90 +msgid "home_button" +msgstr "ā—€ļø Back" + +#: app/bot/routers/tonconnect.py:86 +msgid "tonconnectOpenWallet_button" +msgstr "[Connect wallet]"