From 31372c739b3f9c65a2e5f6ffee9de6fb9e046e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Fri, 25 May 2018 15:24:06 +0200 Subject: [PATCH] The gas fee field only get reset to default gas when you don't focus the field --- src/components/FeesField/EthereumKind.js | 12 ++++++++++-- src/components/base/InputCurrency/index.js | 13 +++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/FeesField/EthereumKind.js b/src/components/FeesField/EthereumKind.js index c496e035..0ac63bbc 100644 --- a/src/components/FeesField/EthereumKind.js +++ b/src/components/FeesField/EthereumKind.js @@ -15,14 +15,21 @@ type Props = { } class FeesField extends Component { + state = { + isFocused: false, + } componentDidUpdate() { const { gasPrice, fees, onChange } = this.props - if (!gasPrice && fees && fees.gas_price) { + const { isFocused } = this.state + if (!gasPrice && fees && fees.gas_price && !isFocused) { onChange(fees.gas_price) // we want to set the default to gas_price } } + onChangeFocus = isFocused => { + this.setState({ isFocused }) + } render() { - const { account, gasPrice, onChange, error } = this.props + const { account, gasPrice, error, onChange } = this.props const { units } = account.currency return ( @@ -32,6 +39,7 @@ class FeesField extends Component { containerProps={{ grow: true }} value={gasPrice} onChange={onChange} + onChangeFocus={this.onChangeFocus} /> ) diff --git a/src/components/base/InputCurrency/index.js b/src/components/base/InputCurrency/index.js index 9abe3a45..65c65886 100644 --- a/src/components/base/InputCurrency/index.js +++ b/src/components/base/InputCurrency/index.js @@ -45,6 +45,7 @@ function stopPropagation(e) { } type Props = { + onChangeFocus: boolean => void, onChange: (number, Unit) => void, // FIXME Unit shouldn't be provided (this is not "standard" onChange) onChangeUnit: Unit => void, renderRight: any, @@ -61,6 +62,7 @@ type State = { class InputCurrency extends PureComponent { static defaultProps = { + onChangeFocus: noop, onChange: noop, renderRight: null, units: [], @@ -122,8 +124,15 @@ class InputCurrency extends PureComponent { this.setState({ displayValue: v || '' }) } - handleBlur = () => this.syncInput({ isFocused: false }) - handleFocus = () => this.syncInput({ isFocused: true }) + handleBlur = () => { + this.syncInput({ isFocused: false }) + this.props.onChangeFocus(false) + } + + handleFocus = () => { + this.syncInput({ isFocused: true }) + this.props.onChangeFocus(true) + } syncInput = ({ isFocused }: { isFocused: boolean }) => { const { value, showAllDigits, unit } = this.props