2018-04-16 18:05:57 +00:00
|
|
|
class ContractUI extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.updateInstances = this.updateInstances.bind(this);
|
|
|
|
this.updateAccounts = this.updateAccounts.bind(this);
|
|
|
|
this.handleInstanceSelection = this.handleInstanceSelection.bind(this);
|
2018-04-18 19:06:41 +00:00
|
|
|
this.handleMenuClick = this.handleMenuClick.bind(this);
|
|
|
|
|
2018-04-16 18:05:57 +00:00
|
|
|
this.state = {
|
|
|
|
accounts: [],
|
|
|
|
instances: [],
|
|
|
|
selectedInstance: null,
|
|
|
|
updateAccounts: this.updateAccounts,
|
2018-04-18 19:06:41 +00:00
|
|
|
updateInstances: this.updateInstances,
|
|
|
|
selectedTab: 'deploy'
|
2018-04-16 18:05:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if(props.contract.options.address != null){
|
|
|
|
this.state.instances = [props.contract.options.address];
|
|
|
|
this.state.selectedInstance = props.contract.options.address;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
this.updateAccounts();
|
|
|
|
}
|
|
|
|
|
2018-04-18 19:06:41 +00:00
|
|
|
handleMenuClick(e){
|
|
|
|
e.preventDefault();
|
|
|
|
this.setState({
|
|
|
|
selectedTab: e.target.getAttribute('data-target')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-16 18:05:57 +00:00
|
|
|
async updateAccounts(){
|
|
|
|
let accounts = await web3.eth.getAccounts();
|
|
|
|
window.accounts = accounts;
|
|
|
|
|
|
|
|
console.log("%cawait web3.eth.getAccounts()", 'font-weight: bold');
|
|
|
|
console.log(accounts);
|
|
|
|
|
|
|
|
this.setState({accounts: accounts});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateInstances(_instance){
|
|
|
|
this.state.instances.push(_instance);
|
|
|
|
this.setState({
|
|
|
|
instances: this.state.instances
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleInstanceSelection(_instance){
|
|
|
|
this.props.contract.options.address = _instance;
|
|
|
|
this.setState({
|
|
|
|
selectedInstance: _instance
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ContractContext.Provider value={this.state}>
|
2018-04-18 19:06:41 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-3">
|
|
|
|
<h3 className="page-title mb-5">{this.props.name}</h3>
|
|
|
|
<div>
|
|
|
|
<div className="list-group list-group-transparent mb-0">
|
2018-04-19 13:59:48 +00:00
|
|
|
<MenuItem icon="fe-file-plus" click={this.handleMenuClick} selectedTab={this.state.selectedTab} target="deploy" text="Deployment / Utils" />
|
|
|
|
<MenuItem icon="fe-list" click={this.handleMenuClick} selectedTab={this.state.selectedTab} target="functions" text="Functions" />
|
|
|
|
<MenuItem icon="fe-file-text" click={this.handleMenuClick} selectedTab={this.state.selectedTab} target="contract" text="Source Code" />
|
2018-04-18 19:06:41 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-9">
|
|
|
|
<Tab id="deploy" selectedTab={this.state.selectedTab}>
|
|
|
|
<h4 className="mb-5">Deployment Utils</h4>
|
|
|
|
<div className="card">
|
|
|
|
<div className="card-body">
|
|
|
|
<ul>
|
|
|
|
<li>Open your browser's console: <code>Tools > Developer Tools</code></li>
|
|
|
|
<li>Remix: <a href="https://remix.ethereum.org" target="_blank">http://remix.ethereum.org</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-04-16 18:05:57 +00:00
|
|
|
<AccountList accountUpdate={this.updateAccounts} />
|
2018-04-18 19:06:41 +00:00
|
|
|
<h5>Deploy</h5>
|
2018-04-19 16:09:46 +00:00
|
|
|
{
|
|
|
|
this.props.definition.code == "" ? <p>Interface or set to not deploy</p>: ""
|
|
|
|
}
|
|
|
|
<FunctionArea definition={this.props.definition} contractName={this.props.name} contract={this.props.contract} type="constructor" />
|
2018-04-16 18:05:57 +00:00
|
|
|
</Tab>
|
2018-04-18 19:06:41 +00:00
|
|
|
|
|
|
|
<Tab id="functions" selectedTab={this.state.selectedTab}>
|
|
|
|
<h4 className="mb-5">Functions</h4>
|
2018-04-19 16:09:46 +00:00
|
|
|
{
|
|
|
|
this.props.definition.code != "" ?
|
|
|
|
<InstanceSelector selectedInstance={this.state.selectedInstance} instanceUpdate={this.handleInstanceSelection} />
|
|
|
|
: ""
|
|
|
|
}
|
|
|
|
<FunctionArea definition={this.props.definition} contractName={this.props.name} contract={this.props.contract} type="function" />
|
|
|
|
<FunctionArea definition={this.props.definition} contractName={this.props.name} contract={this.props.contract} type="fallback" />
|
2018-04-16 18:05:57 +00:00
|
|
|
</Tab>
|
2018-04-18 19:06:41 +00:00
|
|
|
|
|
|
|
<Tab id="contract" selectedTab={this.state.selectedTab}>
|
|
|
|
<h4 className="mb-5">Source Code</h4>
|
|
|
|
<SourceArea definition={this.props.definition} source={this.props.source} />
|
2018-04-16 18:05:57 +00:00
|
|
|
</Tab>
|
|
|
|
</div>
|
2018-04-18 19:06:41 +00:00
|
|
|
</div>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-16 18:05:57 +00:00
|
|
|
</ContractContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
2018-04-18 19:06:41 +00:00
|
|
|
}
|