From 8886f6b0f270fb0a54ea9377eeb26a82210244e1 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 25 Oct 2018 11:59:25 -0400 Subject: [PATCH] add gas price estimator is functions as well as a button to auto-set --- embark-ui/src/components/ContractOverview.css | 12 ++++++ embark-ui/src/components/ContractOverview.js | 42 +++++++++++++++---- embark-ui/src/components/CopyButton.css | 2 +- embark-ui/src/components/GasStation.js | 6 ++- .../containers/ContractOverviewContainer.js | 13 ++---- .../src/containers/GasStationContainer.js | 15 ++++--- 6 files changed, 67 insertions(+), 23 deletions(-) diff --git a/embark-ui/src/components/ContractOverview.css b/embark-ui/src/components/ContractOverview.css index 40660c6c7..5f34a49d3 100644 --- a/embark-ui/src/components/ContractOverview.css +++ b/embark-ui/src/components/ContractOverview.css @@ -7,3 +7,15 @@ 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 6d782c1e1..def12eec7 100644 --- a/embark-ui/src/components/ContractOverview.js +++ b/embark-ui/src/components/ContractOverview.js @@ -17,6 +17,7 @@ import { ListGroup, ListGroupItem } from "reactstrap"; +import GasStationContainer from "../containers/GasStationContainer"; import {formatContractForDisplay} from '../utils/presentation'; import FontAwesome from 'react-fontawesome'; @@ -25,7 +26,7 @@ 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) { @@ -52,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); @@ -72,6 +80,12 @@ class ContractFunction extends Component { }); } + toggleGasPrice() { + this.setState({ + gasPriceCollapse: !this.state.gasPriceCollapse + }); + } + toggleFunction() { this.setState({ functionCollapse: !this.state.functionCollapse @@ -84,7 +98,7 @@ class ContractFunction extends Component { this.toggleFunction()}> {ContractFunction.isPureCall(this.props.method) && - + } {ContractFunction.isEvent(this.props.method) && @@ -107,24 +121,38 @@ class ContractFunction extends Component { this.toggleOptions()}> - Advanced - Options + + Advanced Options -
+ this.handleChange(e, 'gasPrice')}/> +
+

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

+ + { + if (instance) this.gasStation = instance.getWrappedInstance(); + }}/> +
} - diff --git a/embark-ui/src/components/CopyButton.css b/embark-ui/src/components/CopyButton.css index b33438afd..a4789e761 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 777d1333e..3044c5d9b 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 a32fec395..90bdceb44 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 e195f0105..82bac07d6 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);