From f8b3be8be9a0410441507d83e223ae61ee2cdfa4 Mon Sep 17 00:00:00 2001 From: Sagar Shah Date: Thu, 10 Aug 2023 13:52:46 -0500 Subject: [PATCH] task: improve ENS set avatar workflow (#229) --- chat/display_widgets.py | 9 +++++++++ knowledge_base/widgets.yaml | 4 ++++ tools/index_widget.py | 3 ++- .../ens_set_avatar_nft.py | 15 +++++++++------ .../tests/test_ens_set_avatar_nft.py | 7 ++++--- utils/constants.py | 2 +- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/chat/display_widgets.py b/chat/display_widgets.py index 28465e45..00dedc0f 100644 --- a/chat/display_widgets.py +++ b/chat/display_widgets.py @@ -59,6 +59,15 @@ def _widgetize_inner(command: str, params: str, depth: int = 0) -> str: f"-Item {idx}.{_widgetize(item['name'], json.dumps(item['params']), depth=depth)}" for idx, item in enumerate(items, start=1) ]) + elif command == 'nft-asset-list-container': + params = json.loads(params) + nfts = params['assets'] + lines.extend([ + f"A list with {len(nfts)} NFTs:", + ] + [ + f"-Item {idx}.{_widgetize(nft['name'], json.dumps(nft['params']), depth=depth)}" + for idx, nft in enumerate(nfts, start=1) + ]) elif command == 'streaming-list-container': params = json.loads(params) operation = params['operation'] diff --git a/knowledge_base/widgets.yaml b/knowledge_base/widgets.yaml index 973116b5..5bf628f3 100644 --- a/knowledge_base/widgets.yaml +++ b/knowledge_base/widgets.yaml @@ -314,10 +314,14 @@ nftId: description: Token ID of the NFT. type: string + collectionName: + description: Name of NFT collection. Use an empty string if the input parameter value is unknown but do not ask user to input empty string. + type: string required: - domain - nftContractAddress - nftId + - collectionName type: object return_value_description: '' - _name_: aave_supply diff --git a/tools/index_widget.py b/tools/index_widget.py index b289a72e..c0f02a21 100644 --- a/tools/index_widget.py +++ b/tools/index_widget.py @@ -638,7 +638,7 @@ def set_ens_primary_name(domain: str) ->TxPayloadForSending: @error_wrap @ensure_wallet_connected -def set_ens_avatar_nft(domain: str, nftContractAddress: str, nftId: str) ->TxPayloadForSending: +def set_ens_avatar_nft(domain: str, nftContractAddress: str, nftId: str, collectionName: str) ->TxPayloadForSending: wallet_chain_id = 1 # TODO: get from context wallet_address = context.get_wallet_address() user_chat_message_id = context.get_user_chat_message_id() @@ -647,6 +647,7 @@ def set_ens_avatar_nft(domain: str, nftContractAddress: str, nftId: str) ->TxPay 'domain': domain, 'nftContractAddress': nftContractAddress, 'nftId': nftId, + 'collectionName': collectionName } result = ens.ENSSetAvatarNFTWorkflow(wallet_chain_id, wallet_address, user_chat_message_id, params).run() diff --git a/ui_workflows/ens/contract_abi_integratrion/ens_set_avatar_nft.py b/ui_workflows/ens/contract_abi_integratrion/ens_set_avatar_nft.py index 2109bc76..923129cc 100644 --- a/ui_workflows/ens/contract_abi_integratrion/ens_set_avatar_nft.py +++ b/ui_workflows/ens/contract_abi_integratrion/ens_set_avatar_nft.py @@ -18,10 +18,13 @@ class ENSSetAvatarNFTWorkflow(BaseSingleStepContractWorkflow): def __init__(self, wallet_chain_id: int, wallet_address: str, chat_message_id: str, workflow_params: Dict) -> None: self.domain = workflow_params['domain'] - self.nftContractAddress = workflow_params['nftContractAddress'] - self.nftId = workflow_params['nftId'] + self.nft_contract_address = workflow_params['nftContractAddress'] + self.nft_id = workflow_params['nftId'] + self.collection_name = workflow_params['collectionName'] - user_description = f"Set avatar for ENS {self.domain}" + collection_name_text = self.collection_name or 'NFT' + + user_description = f"Set {collection_name_text} #{self.nft_id} as avatar for ENS {self.domain}" super().__init__(wallet_chain_id, wallet_address, chat_message_id, user_description, self.WORKFLOW_TYPE, workflow_params) @@ -29,10 +32,10 @@ def _general_workflow_validation(self): if not self.domain: raise WorkflowValidationError("Unable to interpret an ENS domain in current chat for setting avatar, please specify an ENS domain") - if not self.nftContractAddress: + if not self.nft_contract_address: raise WorkflowValidationError("Unable to interpret an NFT collection in current chat for setting avatar, ask for a collection first and try again") - if not self.nftId: + if not self.nft_id: raise WorkflowValidationError("Unable to interpret an NFT ID in current chat for setting avatar, please specify an NFT ID") ens_update_common_pre_workflow_validation(self.web3_provider, self.domain, self.wallet_address) @@ -41,7 +44,7 @@ def _run(self) -> Result: params = { "domain": self.domain, "key": "avatar", - "value": f"eip155:1/erc721:{self.nftContractAddress}/{self.nftId}" + "value": f"eip155:1/erc721:{self.nft_contract_address}/{self.nft_id}" } result = ENSSetTextWorkflow(self.wallet_chain_id, self.wallet_address, self.chat_message_id, params).run() diff --git a/ui_workflows/ens/contract_abi_integratrion/tests/test_ens_set_avatar_nft.py b/ui_workflows/ens/contract_abi_integratrion/tests/test_ens_set_avatar_nft.py index 63b1ff08..c9da3186 100644 --- a/ui_workflows/ens/contract_abi_integratrion/tests/test_ens_set_avatar_nft.py +++ b/ui_workflows/ens/contract_abi_integratrion/tests/test_ens_set_avatar_nft.py @@ -5,14 +5,15 @@ # Invoke this with python -m pytest -s -k "test_contract_ens_set_avatar_nft" def test_contract_ens_set_avatar_nft(setup_fork): - domain = "owocki.gitcoin.eth" - wallet_address = "0xDDF369C3bf18b1B12EA295d597B943b955eF4671" + domain = "vitalik.eth" + wallet_address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" wallet_chain_id = 1 # Tenderly Mainnet Fork mock_chat_message_id = str(uuid.uuid4()) workflow_params = { "domain": domain, "nftContractAddress": "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D", - "nftId": "2836" + "nftId": "2836", + "collectionName": "Bored Ape Yacht Club" } result = ENSSetAvatarNFTWorkflow(wallet_chain_id, wallet_address, mock_chat_message_id, workflow_params).run() diff --git a/utils/constants.py b/utils/constants.py index 0a559066..4fc1db93 100644 --- a/utils/constants.py +++ b/utils/constants.py @@ -53,7 +53,7 @@ WIDGET_INFO_TOKEN_LIMIT = 4000 # Widget Index -WIDGET_INDEX_NAME = "WidgetV19" +WIDGET_INDEX_NAME = "WidgetV20" def get_widget_index_name(): if env.is_local():