Skip to content

Commit

Permalink
task: improve ENS set avatar workflow (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgzsh269 authored Aug 10, 2023
1 parent 78e9cea commit f8b3be8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
9 changes: 9 additions & 0 deletions chat/display_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
4 changes: 4 additions & 0 deletions knowledge_base/widgets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tools/index_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
15 changes: 9 additions & 6 deletions ui_workflows/ens/contract_abi_integratrion/ens_set_avatar_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ 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)

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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit f8b3be8

Please sign in to comment.