55 ContractCallPayloadBuilder ,
66 ContractFunction ,
77} from '@multiversx/sdk-core' ;
8- import { useForm } from 'react-hook-form' ;
8+ import { useForm , useWatch } from 'react-hook-form' ;
99import { zodResolver } from '@hookform/resolvers/zod' ;
1010import { Form } from '@/components/ui/form' ;
1111import {
@@ -21,18 +21,23 @@ import {
2121 builtInSC ,
2222 TokenPropertyOrRole ,
2323} from '@/components/operations/constants' ;
24- import { OperationsInputField } from '@/components/operations/operations-input-field' ;
2524import { OperationsCheckboxGroup } from '@/components/operations/operations-checkbox-group' ;
2625import { OperationsSubmitButton } from '@/components/operations/operations-submit-button' ;
27- import { useContext } from 'react' ;
26+ import { useContext , useEffect } from 'react' ;
2827import { OperationsStateDialogContext } from '@/components/operations/operations-status-dialog' ;
2928import { CommonOpertationContentProps } from '@/components/operations/operations-common-types' ;
29+ import { OperationsSelectField } from '@/components/operations/operations-select-field' ;
30+ import { useCreatorTokens } from '@/hooks/use-creator-tokens' ;
3031
3132const formSchema = z . object ( {
3233 tokenId : z . string ( ) . min ( 1 , 'The field is required' ) ,
3334 properties : z . array ( z . string ( ) ) ,
3435} ) ;
3536
37+ type CreatorTokens = {
38+ ticker : string ;
39+ } ;
40+
3641const propertiesMap : Record <
3742 CommonOpertationContentProps [ 'tokenType' ] ,
3843 TokenPropertyOrRole [ ]
@@ -52,14 +57,20 @@ export const ChangeProperties = ({
5257 OperationsStateDialogContext
5358 ) ;
5459
60+ const { tokens } = useCreatorTokens < CreatorTokens > ( {
61+ tokenType,
62+ } ) ;
63+
5564 const form = useForm < z . infer < typeof formSchema > > ( {
5665 resolver : zodResolver ( formSchema ) ,
5766 defaultValues : {
5867 tokenId : '' ,
59- properties : propertiesMap [ tokenType ] . map ( ( property ) => property . name ) ,
68+ properties : [ ] ,
6069 } ,
6170 } ) ;
6271
72+ const watchTokenId = useWatch ( { control : form . control , name : 'tokenId' } ) ;
73+
6374 const onSubmit = ( { tokenId, properties } : z . infer < typeof formSchema > ) => {
6475 const args : TypedValue [ ] = [ BytesValue . fromUTF8 ( tokenId . trim ( ) ) ] ;
6576
@@ -91,6 +102,21 @@ export const ChangeProperties = ({
91102 close ( ) ;
92103 } ;
93104
105+ useEffect ( ( ) => {
106+ const tokenData = tokens ?. find ( ( token ) => token . ticker === watchTokenId ) ;
107+ if ( tokenData ) {
108+ const properties = propertiesMap [ tokenType ] . filter ( ( property ) => {
109+ const key = property . name as keyof typeof tokenData ;
110+ return tokenData [ key ] ;
111+ } ) ;
112+ form . setValue (
113+ 'properties' ,
114+ properties . map ( ( property ) => property . name )
115+ ) ;
116+ }
117+ // eslint-disable-next-line react-hooks/exhaustive-deps
118+ } , [ tokenType , tokens , watchTokenId ] ) ;
119+
94120 return (
95121 < >
96122 < DialogHeader className = "p-8 pb-0" >
@@ -109,11 +135,18 @@ export const ChangeProperties = ({
109135 className = "space-y-8"
110136 >
111137 < div className = "flex-1 overflow-auto p-1" >
112- < OperationsInputField
138+ < OperationsSelectField
113139 name = "tokenId"
114140 label = "Token id"
115- placeholder = "Example: MyToken-23432"
116141 description = "Please provide your token id"
142+ options = {
143+ tokens
144+ ? tokens ?. map ( ( token ) => ( {
145+ value : token . ticker ,
146+ label : token . ticker ,
147+ } ) )
148+ : [ ]
149+ }
117150 />
118151 < OperationsCheckboxGroup
119152 items = { propertiesMap [ tokenType ] }
0 commit comments