-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.jsx
134 lines (102 loc) · 3.46 KB
/
app.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
127
128
129
130
131
132
133
134
var PureRenderMixin = React.addons.PureRenderMixin;
Web3Inspector = React.createClass({
mixins: [PureRenderMixin],
getInitialState () {
return {
active: false,
contracts: Contracts
};
},
toggle () {
this.setState({
active: !this.state.active
});
},
setContracts( o ) {
var newContracts = React.addons.update(this.state.contracts, o );
this.setState( { contracts: newContracts } );
},
render () {
var mainClasses = React.addons.classSet({
active: this.state.active
});
var children = _.map(this.state.contracts, ( v, k ) => {
return {
nav: ContractNavigationView,
main: Contract,
object: { name: k, ...v, setContracts:this.setContracts },
class: "contract"
};
});
return <div id="web3Inspector" className={mainClasses} >
<div className="activeToggle" onClick={this.toggle}></div>
<TreeView className={mainClasses} children={children} class="contract" {...this.props} />
</div>;
}
});
ContractInspector = {
// TODO - cleanup this mess
init ( options ) {
web3.setProvider( new web3.providers.HttpProvider( options.httpProvider ) );
// web3.currentProvider.send({jsonrpc: "2.0", method: "evm_reset", params: [], id: 1});
web3.eth.defaultAccount = web3.eth.coinbase;
var initContractInspector = function( contracts ) {
$('body').append('<div id="web3Inspector-wrapper"></div>');
React.render(<Web3Inspector contracts={contracts} />, document.getElementById("web3Inspector-wrapper"));
}
_.each(Contracts, ( con ) => {
let C = web3.eth.contract( con.abi );
con.Class = C;
con.instances = [];
});
// TODO - refactor this
var rdyCounter = 0;
var toDeploy = _.pick(Contracts, _.pluck( _.filter(options.contracts, function(c){
return c.deploy;
}),'name'));
var toWhisk = _.pick(Contracts, _.pluck( _.filter(options.contracts, function(c){
return typeof c.address === 'string';
}),'name'));
// Instanceate
_.each( toWhisk, (Contract, name) => {
var c = Contract.Class.at( _.find(options.contracts, (c) => { return c.name == name; }).address );
Contract.instance = c;
Contract.instances.push(c);
});
// Deploy Contracts
_.each( toDeploy, ( Contract, name ) => {
c = Contract.Class.new( {from: web3.eth.coinbase, data: Contract.binary }, function( err, con ){
if( err ) throw new Error(err);
if( !con.address ) return null;
Contract.instance = con;
Contract.instances.push( con );
// Render after every contract has been initialized
if ( ++rdyCounter == _.keys( toDeploy ).length ) {
if ( options.contractSetup && typeof options.contractSetup === "function" ) {
options.contractSetup ( () => {
initContractInspector( Contracts );
});
} else {
initContractInspector( Contracts );
}
}
});
});
if( _.keys(toDeploy).length == 0 )
initContractInspector( Contracts );
}
}
ContractNavigationView = React.createClass({
mixins: [PureRenderMixin],
render() {
var status = React.addons.classSet({
statusIcon: true,
green: typeof this.props.instance == "object"
});
return (
<div> { this.props.name }
<span className={status}></span>
</div>
);
}
});