@ -15,28 +15,8 @@ export function ContractGUI (props: ContractGUIProps) {
classList : string ,
dataId : string
} > ( { title : '' , content : '' , classList : '' , dataId : '' } )
const [ clipboardContent , setClipboardContent ] = useState < string > ( '' )
const multiFields = useRef < Array < HTMLInputElement | null > > ( [ ] )
useEffect ( ( ) = > {
const multiString = getMultiValsString ( )
const multiJSON = JSON . parse ( '[' + multiString + ']' )
let encodeObj
if ( props . evmBC ) {
encodeObj = txFormat . encodeData ( props . funcABI , multiJSON , props . evmBC )
} else {
encodeObj = txFormat . encodeData ( props . funcABI , multiJSON , null )
}
if ( encodeObj . error ) {
console . error ( encodeObj . error )
// throw new Error(encodeObj.error)
setClipboardContent ( encodeObj . error )
} else {
setClipboardContent ( encodeObj . data )
}
} , [ ] )
useEffect ( ( ) = > {
if ( props . title ) {
setTitle ( props . title )
@ -75,6 +55,28 @@ export function ContractGUI (props: ContractGUIProps) {
}
} , [ props . lookupOnly , props . funcABI , title ] )
const getContentOnCTC = ( ) = > {
const multiString = getMultiValsString ( )
// copy-to-clipboard icon is only visible for method requiring input params
if ( ! multiString ) {
return 'cannot encode empty arguments'
}
const multiJSON = JSON . parse ( '[' + multiString + ']' )
let encodeObj
if ( props . evmBC ) {
encodeObj = txFormat . encodeData ( props . funcABI , multiJSON , props . evmBC )
} else {
encodeObj = txFormat . encodeData ( props . funcABI , multiJSON , null )
}
if ( encodeObj . error ) {
console . error ( encodeObj . error )
return encodeObj . error
} else {
return encodeObj . data
}
}
const switchMethodViewOn = ( ) = > {
setToggleContainer ( true )
makeMultiVal ( )
@ -187,7 +189,7 @@ export function ContractGUI (props: ContractGUIProps) {
} ) }
< / div >
< div className = "udapp_group udapp_multiArg" >
< CopyToClipboard content = { clipboardContent } tip = 'Encode values of input fields & copy to clipboard' icon = 'fa-clipboard' direction = { 'left' } / >
< CopyToClipboard tip = 'Encode values of input fields & copy to clipboard' icon = 'fa-clipboard' direction = { 'left' } getContent = { getContentOnCTC } / >
< button onClick = { handleExpandMultiClick } title = { buttonOptions . title } data - id = { buttonOptions . dataId } className = { ` udapp_instanceButton ${ buttonOptions . classList } ` } > { buttonOptions . content } < / button >
< / div >
< / div >