Browse Source

Bitcoin fees field to handle Custom properly

master
Gaëtan Renaudeau 7 years ago
parent
commit
ed1c530994
  1. 23
      src/components/FeesField/BitcoinKind.js
  2. 9
      src/components/base/Input/index.js
  3. 11
      src/components/base/InputCurrency/index.js

23
src/components/FeesField/BitcoinKind.js

@ -50,10 +50,9 @@ const customItem = {
feePerByte: 0, feePerByte: 0,
} }
class FeesField extends Component< type State = { isFocused: boolean, items: FeeItem[], selectedItem: FeeItem }
Props & { fees?: Fees, error?: Error },
{ isFocused: boolean, items: FeeItem[], selectedItem: FeeItem }, class FeesField extends Component<Props & { fees?: Fees, error?: Error }, State> {
> {
state = { state = {
items: [customItem], items: [customItem],
selectedItem: customItem, selectedItem: customItem,
@ -103,10 +102,21 @@ class FeesField extends Component<
onSelectChange = selectedItem => { onSelectChange = selectedItem => {
const { onChange } = this.props const { onChange } = this.props
this.setState({ selectedItem }) const patch: $Shape<State> = { selectedItem }
if (selectedItem.feePerByte) onChange(selectedItem.feePerByte) if (selectedItem.feePerByte) {
onChange(selectedItem.feePerByte)
} else {
const { input } = this
if (!selectedItem.feePerByte && input.current) {
patch.isFocused = true
input.current.select()
}
}
this.setState(patch)
} }
input = React.createRef()
render() { render() {
const { account, feePerByte, error, onChange, t } = this.props const { account, feePerByte, error, onChange, t } = this.props
const { items, selectedItem } = this.state const { items, selectedItem } = this.state
@ -118,6 +128,7 @@ class FeesField extends Component<
<GenericContainer error={error} help={t('app:send.steps.amount.unitPerByte')}> <GenericContainer error={error} help={t('app:send.steps.amount.unitPerByte')}>
<Select width={156} options={items} value={selectedItem} onChange={this.onSelectChange} /> <Select width={156} options={items} value={selectedItem} onChange={this.onSelectChange} />
<InputCurrency <InputCurrency
ref={this.input}
defaultUnit={satoshi} defaultUnit={satoshi}
units={units} units={units}
containerProps={{ grow: true }} containerProps={{ grow: true }}

9
src/components/base/Input/index.js

@ -151,9 +151,12 @@ class Input extends PureComponent<Props, State> {
onBlur(e) onBlur(e)
} }
handleSelectEverything = () => { select = () => {
this._input && this._input.setSelectionRange(0, this._input.value.length) const { _input } = this
this._input && this._input.focus() if (_input) {
_input.select()
_input.focus()
}
} }
_input = null _input = null

11
src/components/base/InputCurrency/index.js

@ -190,6 +190,16 @@ class InputCurrency extends PureComponent<Props, State> {
) )
} }
select = () => {
// TODO we should fowardRef so InputCurrency ref is on Input
this.input && this.input.select()
}
input: ?Input
onRef = (input: ?Input) => {
this.input = input
}
render() { render() {
const { renderRight, showAllDigits, unit, subMagnitude } = this.props const { renderRight, showAllDigits, unit, subMagnitude } = this.props
const { displayValue } = this.state const { displayValue } = this.state
@ -198,6 +208,7 @@ class InputCurrency extends PureComponent<Props, State> {
<Input <Input
{...this.props} {...this.props}
ff="Rubik" ff="Rubik"
ref={this.onRef}
value={displayValue} value={displayValue}
onChange={this.handleChange} onChange={this.handleChange}
onFocus={this.handleFocus} onFocus={this.handleFocus}

Loading…
Cancel
Save