-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabi.jsx
126 lines (97 loc) · 2.97 KB
/
abi.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var PureRenderMixin = React.addons.PureRenderMixin;
ABIView = React.createClass({
mixins: [PureRenderMixin],
getInitialState () {
return { result: null };
},
renderInputs () {
var inputs = this.props.inputs.map( ( input, i ) => {
var notice = this.props.natspecdev
&& this.props.natspecdev.params
&& this.props.natspecdev.params[ input.name ];
return <div><tr key={i}> <td className="label"> <label> {input.name || input.type}</label></td><td className="input"> <input type="text" ref={i} /> </td><td className="type"> :: {input.type} </td> </tr><tr><td></td><td colSpan="2"><span className="explainer">{notice}</span></td></tr></div>;
});
if( inputs.length > 0 ) {
return (
<form ref="form">
<fieldset>
<legend>Input</legend>
<table>
<tbody>
{inputs}
</tbody>
</table>
</fieldset>
</form>
);
} else {
return null;
}
},
renderResult () {
if ( this.props.type != "function" ) return null;
var outputs = this.props.outputs.map( ( output, i ) => {
return <tr key={i}>
<td className="label">
<label> {output.name || output.type}</label>
</td>
<td className="input">
<input disabled type="text" value={ this.props.outputs.length > 1 && this.state.result && this.state.result[i] || this.state.result } />
</td>
<td className="type">:: {output.type}</td>
</tr>;
});
if( outputs.length > 0 ) {
return (
<fieldset>
<legend>Output</legend>
<table>
<tbody>
{outputs}
</tbody>
</table>
</fieldset>
);
} else {
return null;
}
},
callContract () {
var args = [];
for( let i=0; i<this.props.inputs.length; i++ ) {
args.push(this.refs[i].getDOMNode().value);
}
this.setState({ result: this.props.callContract( args ) });
},
render () {
var nsuser = this.props.natspecuser && this.props.natspecuser.notice;
var nsdev = this.props.natspecdev && this.props.natspecdev.details;
var displayNotice = ( notice ) => {
return <span className="explainer">{ notice }</span>;
}
return (
<div>
{ nsuser && displayNotice( nsuser ) }
{ nsdev && displayNotice( nsdev ) }
{this.renderInputs()}
<button onClick = {this.callContract}> Call </button>
{this.renderResult()}
</div>
);
}
});
ABISelect = React.createClass({
mixins: [PureRenderMixin],
render () {
var notice = this.props.natspecuser && this.props.natspecuser.notice;
var displayNotice = () => {
return <span className="dev explainer"> { this.props.natspecuser.notice.slice(0,100) } </span>;
}
return (
<div>
<span className="name"> {this.props.name} </span>
{ notice && displayNotice() }
</div>
);
}
});