fix(cockpit/contract): remove contract profiling and use functions

This commit is contained in:
Jonathan Rainville 2019-03-08 12:48:26 -05:00 committed by Iuri Matias
parent a9c5e1ade5
commit 99dcd785bc
2 changed files with 12 additions and 23 deletions

View File

@ -32,7 +32,7 @@ class ContractFunction extends Component {
} }
static isPureCall(method) { static isPureCall(method) {
return (method.mutability === 'view' || method.mutability === 'pure'); return (method.stateMutability === 'view' || method.stateMutability === 'pure');
} }
static isEvent(method) { static isEvent(method) {
@ -70,7 +70,7 @@ class ContractFunction extends Component {
handleCall(e) { handleCall(e) {
e.preventDefault(); e.preventDefault();
this.props.postContractFunction(this.props.contractProfile.name, this.props.method.name, this.inputsAsArray(), this.state.inputs.gasPrice * 1000000000); this.props.postContractFunction(this.props.contractName, this.props.method.name, this.inputsAsArray(), this.state.inputs.gasPrice * 1000000000);
} }
callDisabled() { callDisabled() {
@ -189,7 +189,7 @@ class ContractFunction extends Component {
} }
ContractFunction.propTypes = { ContractFunction.propTypes = {
contractProfile: PropTypes.object, contractName: PropTypes.string,
method: PropTypes.object, method: PropTypes.object,
contractFunctions: PropTypes.arrayOf(PropTypes.object), contractFunctions: PropTypes.arrayOf(PropTypes.object),
postContractFunction: PropTypes.func postContractFunction: PropTypes.func
@ -202,7 +202,7 @@ const filterContractFunctions = (contractFunctions, contractName, method) => {
}; };
const ContractOverview = (props) => { const ContractOverview = (props) => {
const {contractProfile, contract} = props; const {contract} = props;
const contractDisplay = formatContractForDisplay(contract); const contractDisplay = formatContractForDisplay(contract);
if (!contractDisplay) { if (!contractDisplay) {
return ''; return '';
@ -213,14 +213,13 @@ const ContractOverview = (props) => {
{(contractDisplay.state === 'Deployed') && <div>Deployed at {contractDisplay.address}</div>} {(contractDisplay.state === 'Deployed') && <div>Deployed at {contractDisplay.address}</div>}
{(contractDisplay.state !== 'Deployed') && <div>{contractDisplay.address}</div>} {(contractDisplay.state !== 'Deployed') && <div>{contractDisplay.address}</div>}
<br/> <br/>
{contractProfile.methods {contract.abiDefinition
.filter((method) => { .filter((method) => {
return props.onlyConstructor ? method.type === 'constructor' : method.type !== 'constructor'; return props.onlyConstructor ? method.type === 'constructor' : method.type !== 'constructor';
}) })
.map(method => <ContractFunction key={method.name} .map(method => <ContractFunction key={method.name} contractName={contract.className}
method={method} method={method}
contractFunctions={filterContractFunctions(props.contractFunctions, contractProfile.name, method.name)} contractFunctions={filterContractFunctions(props.contractFunctions, contract.className, method.name)}
contractProfile={contractProfile}
postContractFunction={props.postContractFunction}/>)} postContractFunction={props.postContractFunction}/>)}
</div> </div>
); );
@ -229,7 +228,6 @@ const ContractOverview = (props) => {
ContractOverview.propTypes = { ContractOverview.propTypes = {
contract: PropTypes.object, contract: PropTypes.object,
onlyConstructor: PropTypes.bool, onlyConstructor: PropTypes.bool,
contractProfile: PropTypes.object,
contractFunctions: PropTypes.arrayOf(PropTypes.object), contractFunctions: PropTypes.arrayOf(PropTypes.object),
postContractFunction: PropTypes.func postContractFunction: PropTypes.func
}; };

View File

@ -2,23 +2,18 @@ import React, {Component} from 'react';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {contractProfile as contractProfileAction, contractFunction as contractFunctionAction} from '../actions'; import {contractFunction as contractFunctionAction} from '../actions';
import ContractOverview from '../components/ContractOverview'; import ContractOverview from '../components/ContractOverview';
import DataWrapper from "../components/DataWrapper"; import DataWrapper from "../components/DataWrapper";
import {getContractProfile, getContractFunctions} from "../reducers/selectors"; import {getContractFunctions} from "../reducers/selectors";
class ContractOverviewContainer extends Component { class ContractOverviewContainer extends Component {
componentDidMount() {
this.props.fetchContractProfile(this.props.contract.className);
}
render() { render() {
return ( return (
<DataWrapper shouldRender={this.props.contractProfile !== undefined} <DataWrapper shouldRender={this.props.contractFunctions !== undefined}
{...this.props} {...this.props}
render={({contractProfile, contractFunctions, postContractFunction}) => ( render={({contractFunctions, postContractFunction}) => (
<ContractOverview contractProfile={contractProfile} <ContractOverview contractFunctions={contractFunctions}
contractFunctions={contractFunctions}
contract={this.props.contract} contract={this.props.contract}
postContractFunction={postContractFunction}/> postContractFunction={postContractFunction}/>
)}/> )}/>
@ -28,7 +23,6 @@ class ContractOverviewContainer extends Component {
function mapStateToProps(state, props) { function mapStateToProps(state, props) {
return { return {
contractProfile: getContractProfile(state, props.contract.className),
contractFunctions: getContractFunctions(state, props.contract.className), contractFunctions: getContractFunctions(state, props.contract.className),
error: state.errorMessage, error: state.errorMessage,
loading: state.loading loading: state.loading
@ -37,17 +31,14 @@ function mapStateToProps(state, props) {
ContractOverviewContainer.propTypes = { ContractOverviewContainer.propTypes = {
contract: PropTypes.object, contract: PropTypes.object,
contractProfile: PropTypes.object,
contractFunctions: PropTypes.arrayOf(PropTypes.object), contractFunctions: PropTypes.arrayOf(PropTypes.object),
postContractFunction: PropTypes.func, postContractFunction: PropTypes.func,
fetchContractProfile: PropTypes.func,
error: PropTypes.string error: PropTypes.string
}; };
export default connect( export default connect(
mapStateToProps, mapStateToProps,
{ {
fetchContractProfile: contractProfileAction.request,
postContractFunction: contractFunctionAction.post postContractFunction: contractFunctionAction.post
} }
)(ContractOverviewContainer); )(ContractOverviewContainer);