Verifying if contract can be deployed or not

This commit is contained in:
Richard Ramos 2018-04-19 12:09:46 -04:00 committed by Pascal Precht
parent 56afed906a
commit 92f1ac7576
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 37 additions and 8 deletions

View File

@ -84,14 +84,21 @@ class ContractUI extends React.Component {
</div> </div>
<AccountList accountUpdate={this.updateAccounts} /> <AccountList accountUpdate={this.updateAccounts} />
<h5>Deploy</h5> <h5>Deploy</h5>
<FunctionArea contractName={this.props.name} contract={this.props.contract} type="constructor" /> {
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" />
</Tab> </Tab>
<Tab id="functions" selectedTab={this.state.selectedTab}> <Tab id="functions" selectedTab={this.state.selectedTab}>
<h4 className="mb-5">Functions</h4> <h4 className="mb-5">Functions</h4>
{
this.props.definition.code != "" ?
<InstanceSelector selectedInstance={this.state.selectedInstance} instanceUpdate={this.handleInstanceSelection} /> <InstanceSelector selectedInstance={this.state.selectedInstance} instanceUpdate={this.handleInstanceSelection} />
<FunctionArea contractName={this.props.name} contract={this.props.contract} type="function" /> : ""
<FunctionArea contractName={this.props.name} contract={this.props.contract} type="fallback" /> }
<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" />
</Tab> </Tab>
<Tab id="contract" selectedTab={this.state.selectedTab}> <Tab id="contract" selectedTab={this.state.selectedTab}>

View File

@ -13,7 +13,7 @@ class FunctionArea extends React.Component {
{ {
this.props.contract.options.jsonInterface this.props.contract.options.jsonInterface
.filter(item => item.type == type) .filter(item => item.type == type)
.map((item, i) => <FunctionForm key={i} contract={contract} contractName={contractName} abi={item} instanceUpdate={this.props.instanceUpdate} />) .map((item, i) => <FunctionForm definition={this.props.definition} key={i} contract={contract} contractName={contractName} abi={item} instanceUpdate={this.props.instanceUpdate} />)
} }
</React.Fragment>; </React.Fragment>;
} }

View File

@ -44,7 +44,7 @@ class FunctionForm extends React.Component {
<CardAlert show={this.state.error} message={this.state.message} /> <CardAlert show={this.state.error} message={this.state.message} />
<div className="card-body row"> <div className="card-body row">
<Function contract={this.props.contract} contractName={this.props.contractName} duplicated={isDuplicated} abi={this.props.abi} resultHandler={this.showResults} /> <Function definition={this.props.definition} contract={this.props.contract} contractName={this.props.contractName} duplicated={isDuplicated} abi={this.props.abi} resultHandler={this.showResults} />
</div> </div>
{ {
receipt != null || !this.state.error && this.state.message != null receipt != null || !this.state.error && this.state.message != null

View File

@ -194,6 +194,21 @@ class Function extends React.Component {
} }
render(){ render(){
let btnClass = "btn ml-auto ";
let disabled = false;
if(this.state.onRequest){
disabled = true;
}
if(this.props.definition.code == ""){
btnClass += "btn-secondary";
disabled = true;
} else {
btnClass += "btn-primary";
}
return <ContractContext.Consumer> return <ContractContext.Consumer>
{ (context) => ( { (context) => (
<React.Fragment> <React.Fragment>
@ -208,11 +223,18 @@ class Function extends React.Component {
</code> </code>
</div> </div>
<div className="col-md-1"> <div className="col-md-1">
<button className="btn btn-primary ml-auto" onClick={event => this.handleClick(event, context.updateInstances)} disabled={this.state.onRequest}> <button className={btnClass} title={this.props.definition.code == "" ? "Can't execute function" : "Execute function"} onClick={event => this.handleClick(event, context.updateInstances)} disabled={disabled}>
{ this.state.onRequest ? { this.state.onRequest ?
<img src="../assets/images/loading.gif" className="loading" alt="" /> <img src="../assets/images/loading.gif" className="loading" alt="" />
: :
(
this.props.definition.code == ""
?
<React.Fragment>_</React.Fragment>
:
<React.Fragment>&#9166;</React.Fragment> <React.Fragment>&#9166;</React.Fragment>
)
} }
</button> </button>
</div> </div>