@@ -22,24 +22,30 @@ import {
22
22
SendNanoContractTxLoadingFinishedTrigger ,
23
23
} from '../types' ;
24
24
import { PromptRejectedError , SendNanoContractTxError , InvalidParamsError } from '../errors' ;
25
- import { NanoContractAction } from '@hathor/wallet-lib/lib/nano_contracts/types' ;
25
+ import { NanoContractAction , NanoContractActionType } from '@hathor/wallet-lib/lib/nano_contracts/types' ;
26
26
27
27
export type NanoContractActionWithStringAmount = Omit < NanoContractAction , 'amount' > & {
28
28
amount : string ,
29
29
}
30
30
31
+ const NanoContractActionSchema = z . object ( {
32
+ type : z . nativeEnum ( NanoContractActionType ) ,
33
+ token : z . string ( ) ,
34
+ amount : z . string ( ) . regex ( / ^ \d + $ / )
35
+ . pipe ( z . coerce . bigint ( ) . positive ( ) ) ,
36
+ address : z . string ( ) . nullish ( ) ,
37
+ changeAddress : z . string ( ) . nullish ( ) ,
38
+ } ) . transform ( ( data ) : NanoContractAction => ( {
39
+ ...data ,
40
+ address : data . address ?? null ,
41
+ changeAddress : data . changeAddress ?? null ,
42
+ } ) ) ;
43
+
31
44
const sendNanoContractSchema = z . object ( {
32
45
method : z . string ( ) . min ( 1 ) ,
33
46
blueprint_id : z . string ( ) . nullish ( ) ,
34
47
nc_id : z . string ( ) . nullish ( ) ,
35
- actions : z . array (
36
- z . custom < NanoContractActionWithStringAmount > ( ) . transform ( action => ( {
37
- ...action ,
38
- amount : z . string ( ) . regex ( / ^ \d + $ / )
39
- . pipe ( z . coerce . bigint ( ) . nonnegative ( ) )
40
- . parse ( action . amount )
41
- } ) )
42
- ) ,
48
+ actions : z . array ( NanoContractActionSchema ) ,
43
49
args : z . array ( z . unknown ( ) ) . default ( [ ] ) ,
44
50
push_tx : z . boolean ( ) . default ( true ) ,
45
51
} ) . transform ( data => ( {
0 commit comments