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
parent
commit
8d37ff6691
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/components/FeesField/EthereumKind.js
  2. 13
      src/components/base/InputCurrency/index.js

12
src/components/FeesField/EthereumKind.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>
)

13
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<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

Loading…
Cancel
Save