From 94b3f3403be4a7502e25e513a1fc73e0cecca474 Mon Sep 17 00:00:00 2001 From: HenryNguyen5 Date: Wed, 7 Mar 2018 18:55:46 -0500 Subject: [PATCH] Fix recommended gas price breaking on subtab switch (#1268) --- .../TXMetaDataPanel/components/SimpleGas.tsx | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/common/components/TXMetaDataPanel/components/SimpleGas.tsx b/common/components/TXMetaDataPanel/components/SimpleGas.tsx index 5469b29c..f8686da6 100644 --- a/common/components/TXMetaDataPanel/components/SimpleGas.tsx +++ b/common/components/TXMetaDataPanel/components/SimpleGas.tsx @@ -40,14 +40,22 @@ interface ActionProps { type Props = OwnProps & StateProps & ActionProps; +interface State { + hasSetRecommendedGasPrice: boolean; +} + class SimpleGas extends React.Component { + public state: State = { + hasSetRecommendedGasPrice: false + }; + public componentDidMount() { - this.fixGasPrice(); this.props.fetchGasEstimates(); } public componentWillReceiveProps(nextProps: Props) { - if (!this.props.gasEstimates && nextProps.gasEstimates) { + if (!this.state.hasSetRecommendedGasPrice && nextProps.gasEstimates) { + this.setState({ hasSetRecommendedGasPrice: true }); this.props.setGasPrice(nextProps.gasEstimates.fast.toString()); } } @@ -121,21 +129,6 @@ class SimpleGas extends React.Component { this.props.inputGasPrice(gasGwei.toString()); }; - private fixGasPrice() { - const { gasPrice, gasEstimates } = this.props; - if (!gasEstimates) { - return; - } - - // If the gas price is above or below our minimum, bring it in line - const gasPriceGwei = this.getGasPriceGwei(gasPrice.value); - if (gasPriceGwei < gasEstimates.safeLow) { - this.props.setGasPrice(gasEstimates.safeLow.toString()); - } else if (gasPriceGwei > gasEstimates.fastest) { - this.props.setGasPrice(gasEstimates.fastest.toString()); - } - } - private getGasPriceGwei(gasPriceValue: Wei) { return parseFloat(fromWei(gasPriceValue, 'gwei')); }