From a8d515ab317e2a084121cad5bb2ce3bd2ab71935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sat, 30 Jun 2018 22:31:20 +0200 Subject: [PATCH 1/3] Ethereum gasLimit field to not fallback on empty --- src/components/AdvancedOptions/EthereumKind.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AdvancedOptions/EthereumKind.js b/src/components/AdvancedOptions/EthereumKind.js index 0fac97b3..e70e5f3f 100644 --- a/src/components/AdvancedOptions/EthereumKind.js +++ b/src/components/AdvancedOptions/EthereumKind.js @@ -25,7 +25,7 @@ export default translate()(({ gasLimit, onChangeGasLimit, t }: Props) => ( { - const gasLimit = parseInt(str, 10) + const gasLimit = parseInt(str || 0, 10) if (!isNaN(gasLimit) && isFinite(gasLimit)) onChangeGasLimit(gasLimit) else onChangeGasLimit(0x5208) }} 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 2/3] 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< Date: Sat, 30 Jun 2018 22:33:04 +0200 Subject: [PATCH 3/3] Fix many race conditions in Send step1 --- src/components/FeesField/RippleKind.js | 6 ++++++ src/components/modals/Send/fields/AmountField.js | 7 ++++--- src/components/modals/Send/fields/RecipientField.js | 7 ++++--- src/components/modals/Send/steps/01-step-amount.js | 10 ++++++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/components/FeesField/RippleKind.js b/src/components/FeesField/RippleKind.js index f40a22e5..f44c8b71 100644 --- a/src/components/FeesField/RippleKind.js +++ b/src/components/FeesField/RippleKind.js @@ -23,11 +23,17 @@ class FeesField extends Component { componentDidMount() { this.sync() } + componentWillUnmount() { + this.syncId++ + } + syncId = 0 async sync() { const api = apiForEndpointConfig(this.props.account.endpointConfig) + const syncId = ++this.syncId try { await api.connect() const info = await api.getServerInfo() + if (syncId !== this.syncId) return const serverFee = parseAPIValue(info.validatedLedger.baseFeeXRP) if (!this.props.fee) { this.props.onChange(serverFee) diff --git a/src/components/modals/Send/fields/AmountField.js b/src/components/modals/Send/fields/AmountField.js index 6605f5f3..3d5a25ef 100644 --- a/src/components/modals/Send/fields/AmountField.js +++ b/src/components/modals/Send/fields/AmountField.js @@ -20,13 +20,14 @@ class AmountField extends Component<*, { canBeSpent: boolean }> { } } componentWillUnmount() { - this.unmount = true + this.syncId++ } - unmount = false + syncId = 0 async resync() { const { account, bridge, transaction } = this.props + const syncId = ++this.syncId const canBeSpent = await bridge.canBeSpent(account, transaction) - if (this.unmount) return + if (this.syncId !== syncId) return this.setState({ canBeSpent }) } diff --git a/src/components/modals/Send/fields/RecipientField.js b/src/components/modals/Send/fields/RecipientField.js index f01dd558..f7974c54 100644 --- a/src/components/modals/Send/fields/RecipientField.js +++ b/src/components/modals/Send/fields/RecipientField.js @@ -33,16 +33,17 @@ class RecipientField extends Component, { isVali } } componentWillUnmount() { - this.unmount = true + this.syncId++ } - unmount = false + syncId = 0 async resync() { const { account, bridge, transaction } = this.props + const syncId = ++this.syncId const isValid = await bridge.isRecipientValid( account.currency, bridge.getTransactionRecipient(account, transaction), ) - if (this.unmount) return + if (syncId !== this.syncId) return this.setState({ isValid }) } diff --git a/src/components/modals/Send/steps/01-step-amount.js b/src/components/modals/Send/steps/01-step-amount.js index efa72337..0e2524d0 100644 --- a/src/components/modals/Send/steps/01-step-amount.js +++ b/src/components/modals/Send/steps/01-step-amount.js @@ -112,14 +112,16 @@ export class StepAmountFooter extends PureComponent< } componentWillUnmount() { - this._isUnmounted = true + this.syncId++ } - _isUnmounted = false + syncId = 0 async resync() { const { account, bridge, transaction } = this.props + const syncId = ++this.syncId + if (!account || !transaction || !bridge) { return } @@ -128,9 +130,9 @@ export class StepAmountFooter extends PureComponent< try { const totalSpent = await bridge.getTotalSpent(account, transaction) - if (this._isUnmounted) return + if (syncId !== this.syncId) return const canBeSpent = await bridge.canBeSpent(account, transaction) - if (this._isUnmounted) return + if (syncId !== this.syncId) return this.setState({ totalSpent, canBeSpent, isSyncing: false }) } catch (err) { this.setState({ isSyncing: false })