@@ -96,40 +96,56 @@ export class ActionField {
96
96
this . placeholder = options . placeholder ;
97
97
this . transformation = options . transformation ;
98
98
}
99
- /**
100
- * the value to pass to the contract call (as calculated from the user's input data)
101
- * @return [description]
102
- */
103
- public callValue ( userValue : string | string [ ] ) {
104
- if ( Array . isArray ( userValue ) ) {
105
- userValue = userValue . map ( ( val : string ) => Object . prototype . hasOwnProperty . call ( val , "trim" ) ? val . trim ( ) : val ) ;
106
- } else if ( Object . prototype . hasOwnProperty . call ( userValue , "trim" ) ) {
107
- userValue = userValue . trim ( ) ;
99
+
100
+ private transformValue ( value : string , web3 : any ) : string | boolean {
101
+ if ( Object . prototype . hasOwnProperty . call ( value , "trim" ) ) {
102
+ value = ( value as string ) . trim ( ) ;
108
103
}
109
104
110
105
if ( this . type === "bool" ) {
111
- return parseInt ( userValue as string , 10 ) === 1 ;
106
+ return parseInt ( value as string , 10 ) === 1 ;
112
107
}
113
-
114
- if ( this . decimals ) {
115
- return ( new BN ( userValue as string ) . mul ( new BN ( 10 ) . pow ( new BN ( this . decimals ) ) ) ) . toString ( ) ;
108
+ /**
109
+ * Note that if this is an array item, the field's one `decimals` value applies
110
+ * to all items in the array. Same for `transformation`.
111
+ */
112
+ else if ( this . decimals ) {
113
+ return ( new BN ( value as string ) . mul ( new BN ( 10 ) . pow ( new BN ( this . decimals ) ) ) ) . toString ( ) ;
114
+ }
115
+ else {
116
+ switch ( this . transformation ) {
117
+ case "namehash" : {
118
+ return namehash . hash ( value ) ;
119
+ }
120
+ case "keccak256" : {
121
+ return web3 . utils . keccak256 ( value ) ;
122
+ }
123
+ case "toWei" : {
124
+ return web3 . utils . toWei ( value . toString ( ) , "ether" ) . toString ( ) ;
125
+ }
126
+ default :
127
+ return value ;
128
+ }
116
129
}
130
+ }
131
+
132
+ /**
133
+ * the value to pass to the contract call (as calculated from the user's input data)
134
+ * @return [description]
135
+ */
136
+ public callValue ( userValue : string | Array < string > ) : string | boolean | Array < string | boolean > {
137
+ let returnValue : string | boolean | Array < string | boolean > = userValue ;
117
138
118
139
const web3 = new Web3 ( ) ;
119
140
120
- switch ( this . transformation ) {
121
- case "namehash" : {
122
- return namehash . hash ( userValue ) ;
123
- }
124
- case "keccak256" : {
125
- return web3 . utils . keccak256 ( userValue ) ;
126
- }
127
- case "toWei" : {
128
- return web3 . utils . toWei ( userValue . toString ( ) , "ether" ) . toString ( ) ;
129
- }
141
+ if ( Array . isArray ( returnValue ) ) {
142
+ returnValue = ( returnValue as Array < string > ) . map ( ( val : string ) : string | boolean => {
143
+ return this . transformValue ( val , web3 ) ;
144
+ } ) ;
145
+ } else {
146
+ returnValue = this . transformValue ( returnValue , web3 ) ;
130
147
}
131
-
132
- return userValue ;
148
+ return returnValue ;
133
149
}
134
150
}
135
151
0 commit comments