diff --git a/embark-ui/src/components/ContractOverview.css b/embark-ui/src/components/ContractOverview.css new file mode 100644 index 00000000..5f34a49d --- /dev/null +++ b/embark-ui/src/components/ContractOverview.css @@ -0,0 +1,21 @@ +.contract-function-container .collapse.show .card-body { + min-height: 65px; +} + +.contract-function-container .contract-function-button { + position: absolute; + bottom: 15px; + right: 15px; +} + +.contract-function-container .gas-price-form #gasPrice { + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + +.contract-function-container .gas-price-form button { + border-top-left-radius: 0; + border-bottom-left-radius: 0; + border: 0; + box-shadow: none !important; +} diff --git a/embark-ui/src/components/ContractOverview.js b/embark-ui/src/components/ContractOverview.js index 4f1b8512..cffb2071 100644 --- a/embark-ui/src/components/ContractOverview.js +++ b/embark-ui/src/components/ContractOverview.js @@ -17,12 +17,16 @@ import { ListGroup, ListGroupItem } from "reactstrap"; +import GasStationContainer from "../containers/GasStationContainer"; import {formatContractForDisplay} from '../utils/presentation'; +import FontAwesome from 'react-fontawesome'; + +import "./ContractOverview.css"; class ContractFunction extends Component { constructor(props) { super(props); - this.state = {inputs: {}, optionsCollapse: false, functionCollapse: false}; + this.state = {inputs: {}, optionsCollapse: false, functionCollapse: false, gasPriceCollapse: false}; } static isPureCall(method) { @@ -49,11 +53,18 @@ class ContractFunction extends Component { } handleChange(e, name) { - let newInputs = this.state.inputs; + const newInputs = this.state.inputs; newInputs[name] = e.target.value; this.setState({inputs: newInputs}); } + autoSetGasPrice(e) { + e.preventDefault(); + const newInputs = this.state.inputs; + newInputs.gasPrice = this.gasStation.getCurrentGas(); + this.setState({inputs: newInputs}); + } + handleCall(e) { e.preventDefault(); this.props.postContractFunction(this.props.contractProfile.name, this.props.method.name, this.inputsAsArray(), this.state.inputs.gasPrice * 1000000000); @@ -65,66 +76,85 @@ class ContractFunction extends Component { toggleOptions() { this.setState({ - optionsCollapse: !this.state.optionsCollapse, + optionsCollapse: !this.state.optionsCollapse + }); + } + + toggleGasPrice() { + this.setState({ + gasPriceCollapse: !this.state.gasPriceCollapse }); } toggleFunction() { this.setState({ - functionCollapse: !this.state.functionCollapse, + functionCollapse: !this.state.functionCollapse }); } render() { return ( - + this.toggleFunction()}> {ContractFunction.isPureCall(this.props.method) && - + } {ContractFunction.isEvent(this.props.method) && - + } {this.props.method.name}({this.props.method.inputs.map(input => input.name).join(', ')}) - + -
- {this.props.method.inputs.map(input => ( - - - this.handleChange(e, input.name)}/> - - ))} + + {this.props.method.inputs.map(input => ( + + + this.handleChange(e, input.name)}/> + + ))}
{!ContractFunction.isPureCall(this.props.method) && - - - this.toggleOptions()}> - Advanced Options - - - - -
- - - this.handleChange(e, 'gasPrice')}/> - -
-
-
- -
- + + + this.toggleOptions()}> + + Advanced Options + + + + +
+ + + this.handleChange(e, 'gasPrice')}/> + + +
+

this.toggleGasPrice()}> + + Gas price estimator +

+ + { + if (instance) this.gasStation = instance.getWrappedInstance(); + }}/> + +
+
+ } -
- -
+
{this.props.contractFunctions && this.props.contractFunctions.length > 0 && diff --git a/embark-ui/src/components/CopyButton.css b/embark-ui/src/components/CopyButton.css index b33438af..a4789e76 100644 --- a/embark-ui/src/components/CopyButton.css +++ b/embark-ui/src/components/CopyButton.css @@ -1,4 +1,4 @@ -.copy-to-clipboard { +#root .copy-to-clipboard { position: absolute; right: 0; top: 0; diff --git a/embark-ui/src/components/GasStation.js b/embark-ui/src/components/GasStation.js index 777d1333..3044c5d9 100644 --- a/embark-ui/src/components/GasStation.js +++ b/embark-ui/src/components/GasStation.js @@ -49,6 +49,10 @@ class GasStation extends Component { return formattedStats; } + getCurrentGas() { + return this.getGasOracleFormatted()[this.state.gasOracleSliderIndex].gasPrice / this.PRICE_UNIT_DIVIDER; + } + gasSliderChange(e, name) { this.setState({ [name]: e.target.value @@ -91,7 +95,7 @@ class GasStation extends Component { } return - + Gas Price Estimator diff --git a/embark-ui/src/containers/ContractOverviewContainer.js b/embark-ui/src/containers/ContractOverviewContainer.js index a32fec39..90bdceb4 100644 --- a/embark-ui/src/containers/ContractOverviewContainer.js +++ b/embark-ui/src/containers/ContractOverviewContainer.js @@ -5,7 +5,6 @@ import PropTypes from 'prop-types'; import {contractProfile as contractProfileAction, contractFunction as contractFunctionAction} from '../actions'; import ContractOverview from '../components/ContractOverview'; import DataWrapper from "../components/DataWrapper"; -import GasStationContainer from "../containers/GasStationContainer"; import {getContractProfile, getContractFunctions} from "../reducers/selectors"; class ContractOverviewContainer extends Component { @@ -18,14 +17,10 @@ class ContractOverviewContainer extends Component { ( - - - - - + )}/> ); } diff --git a/embark-ui/src/containers/GasStationContainer.js b/embark-ui/src/containers/GasStationContainer.js index e195f010..82bac07d 100644 --- a/embark-ui/src/containers/GasStationContainer.js +++ b/embark-ui/src/containers/GasStationContainer.js @@ -1,7 +1,6 @@ import PropTypes from "prop-types"; import React, {Component} from 'react'; import {connect} from 'react-redux'; -import {withRouter} from "react-router-dom"; import GasStation from '../components/GasStation'; import {stopGasOracle, listenToGasOracle, gasOracle as ethGasAction, blocks as blocksAction} from "../actions"; import DataWrapper from "../components/DataWrapper"; @@ -18,10 +17,14 @@ class GasStationContainer extends Component { this.props.stopGasOracle(); } + getCurrentGas() { + return this.gasStation.getCurrentGas(); + } + render() { return ( - + { this.gasStation = instance; }}/> )}/>; } @@ -43,12 +46,14 @@ function mapStateToProps(state, _props) { }; } -export default withRouter(connect( +export default connect( mapStateToProps, { fetchEthGas: ethGasAction.request, fetchBlocks: blocksAction.request, listenToGasOracle, stopGasOracle - } -)(GasStationContainer)); + }, + null, + { withRef: true } +)(GasStationContainer);