Browse Source
Merge pull request #364 from gre/fix-eth-gas-fee-control
The gas fee field only get reset to default gas when you don't focus
master
Meriadec Pillet
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
21 additions and
4 deletions
-
src/components/FeesField/EthereumKind.js
-
src/components/base/InputCurrency/index.js
|
|
@ -15,14 +15,21 @@ type Props = { |
|
|
|
} |
|
|
|
|
|
|
|
class FeesField extends Component<Props & { fees?: Fees, error?: Error }, *> { |
|
|
|
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 ( |
|
|
|
<GenericContainer error={error} help="Gas"> |
|
|
@ -32,6 +39,7 @@ class FeesField extends Component<Props & { fees?: Fees, error?: Error }, *> { |
|
|
|
containerProps={{ grow: true }} |
|
|
|
value={gasPrice} |
|
|
|
onChange={onChange} |
|
|
|
onChangeFocus={this.onChangeFocus} |
|
|
|
/> |
|
|
|
</GenericContainer> |
|
|
|
) |
|
|
|
|
|
@ -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<Props, State> { |
|
|
|
static defaultProps = { |
|
|
|
onChangeFocus: noop, |
|
|
|
onChange: noop, |
|
|
|
renderRight: null, |
|
|
|
units: [], |
|
|
@ -122,8 +124,15 @@ class InputCurrency extends PureComponent<Props, State> { |
|
|
|
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 |
|
|
|