From ed1c530994aea5266f8c7cf6bc4606b010e6a812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sat, 30 Jun 2018 22:32:06 +0200 Subject: [PATCH] Bitcoin fees field to handle Custom properly --- src/components/FeesField/BitcoinKind.js | 23 ++++++++++++++++------ src/components/base/Input/index.js | 9 ++++++--- src/components/base/InputCurrency/index.js | 11 +++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/components/FeesField/BitcoinKind.js b/src/components/FeesField/BitcoinKind.js index e9458045..0410eae4 100644 --- a/src/components/FeesField/BitcoinKind.js +++ b/src/components/FeesField/BitcoinKind.js @@ -50,10 +50,9 @@ const customItem = { feePerByte: 0, } -class FeesField extends Component< - Props & { fees?: Fees, error?: Error }, - { isFocused: boolean, items: FeeItem[], selectedItem: FeeItem }, -> { +type State = { isFocused: boolean, items: FeeItem[], selectedItem: FeeItem } + +class FeesField extends Component { state = { items: [customItem], selectedItem: customItem, @@ -103,10 +102,21 @@ class FeesField extends Component< onSelectChange = selectedItem => { const { onChange } = this.props - this.setState({ selectedItem }) - if (selectedItem.feePerByte) onChange(selectedItem.feePerByte) + const patch: $Shape = { selectedItem } + 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() { const { account, feePerByte, error, onChange, t } = this.props const { items, selectedItem } = this.state @@ -118,6 +128,7 @@ class FeesField extends Component<