@@ -17,6 +17,20 @@ import { networkRpc } from "@/lib/web3";
1717import { Server } from "@stellar/stellar-sdk/rpc" ;
1818import { Networks , scValToNative } from "@stellar/stellar-sdk" ;
1919
20+ function createLogSingnature ( method : FunctionSpec , args : any , result : any ) {
21+ const strArgs = method . inputs . map ( ( arg ) => {
22+ const value = args [ arg . name ] ?. value ;
23+ return `${ arg . name } : ${ arg . value . type } = ${ value } ` ;
24+ } ) ;
25+ const output = method . outputs . at ( 0 ) ;
26+ const signature =
27+ `fn ${ method . name }
28+ ${ strArgs . join ( ", " ) }
29+ result: ${ output ?. type } = ${ result }
30+ ` ;
31+ return signature ;
32+ }
33+
2034function InvokeFunction ( { method } : { method : FunctionSpec } ) {
2135 const [ isOpen , setIsOpen ] = useState ( "" ) ;
2236 const [ args , setArgs ] = useState < Record < string , { type : string ; value : string ; subType : string } > > ( { } ) ;
@@ -38,7 +52,7 @@ function InvokeFunction({ method }: { method: FunctionSpec }) {
3852 const server = new Server ( networkRpc [ Networks . TESTNET ] ) ;
3953 const argsArray = Object . values ( args ) ;
4054 const data = {
41- contractId : contractAddress || "CBT42OCEG6ECN74FRMI4CBXOAZWXCQNJE2UC3RNNB3VNFIUHULJCP242" ,
55+ contractId : contractAddress ! ,
4256 method : method . name ,
4357 args : argsArray ,
4458 } ;
@@ -63,7 +77,8 @@ function InvokeFunction({ method }: { method: FunctionSpec }) {
6377 logger . info ( `TxId: ${ result . hash } ` ) ;
6478 if ( response . returnValue ) {
6579 logger . info ( `TX Result: ${ scValToNative ( response . returnValue ) } ` ) ;
66- setIsOpen ( JSON . stringify ( response . returnValue , null , 2 ) ) ;
80+ const logSignature = createLogSingnature ( method , args , scValToNative ( response . returnValue ) ) ;
81+ setIsOpen ( logSignature ) ;
6782 }
6883 toast . success ( `Function invoked successfully` ) ;
6984 return response ;
@@ -131,11 +146,11 @@ function InvokeFunction({ method }: { method: FunctionSpec }) {
131146 < Dialog open = { Boolean ( isOpen ) } onOpenChange = { ( val ) => setIsOpen ( val ? isOpen : "" ) } >
132147 < DialogContent >
133148 < DialogHeader >
134- < DialogTitle > Function Returned Value </ DialogTitle >
149+ < DialogTitle > Function Signature </ DialogTitle >
135150 </ DialogHeader >
136151
137152 < div className = "" >
138- < textarea defaultValue = { isOpen } rows = { 12 } className = "w-full resize-none p-2 text-white bg-black/10" />
153+ < textarea defaultValue = { isOpen } rows = { 6 } className = "w-full font-medium text-lg resize-none p-2 text-white bg-black/10" />
139154 </ div >
140155
141156 < DialogFooter >
0 commit comments