Browse Source

Merge pull request #784 from gre/polish-send

Send: polishes
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
d0c1b80912
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/components/AdvancedOptions/EthereumKind.js
  2. 23
      src/components/FeesField/BitcoinKind.js
  3. 6
      src/components/FeesField/RippleKind.js
  4. 9
      src/components/base/Input/index.js
  5. 11
      src/components/base/InputCurrency/index.js
  6. 7
      src/components/modals/Send/fields/AmountField.js
  7. 7
      src/components/modals/Send/fields/RecipientField.js
  8. 10
      src/components/modals/Send/steps/01-step-amount.js

2
src/components/AdvancedOptions/EthereumKind.js

@ -25,7 +25,7 @@ export default translate()(({ gasLimit, onChangeGasLimit, t }: Props) => (
<Input <Input
value={gasLimit} value={gasLimit}
onChange={str => { onChange={str => {
const gasLimit = parseInt(str, 10) const gasLimit = parseInt(str || 0, 10)
if (!isNaN(gasLimit) && isFinite(gasLimit)) onChangeGasLimit(gasLimit) if (!isNaN(gasLimit) && isFinite(gasLimit)) onChangeGasLimit(gasLimit)
else onChangeGasLimit(0x5208) else onChangeGasLimit(0x5208)
}} }}

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

6
src/components/FeesField/RippleKind.js

@ -23,11 +23,17 @@ class FeesField extends Component<Props, State> {
componentDidMount() { componentDidMount() {
this.sync() this.sync()
} }
componentWillUnmount() {
this.syncId++
}
syncId = 0
async sync() { async sync() {
const api = apiForEndpointConfig(this.props.account.endpointConfig) const api = apiForEndpointConfig(this.props.account.endpointConfig)
const syncId = ++this.syncId
try { try {
await api.connect() await api.connect()
const info = await api.getServerInfo() const info = await api.getServerInfo()
if (syncId !== this.syncId) return
const serverFee = parseAPIValue(info.validatedLedger.baseFeeXRP) const serverFee = parseAPIValue(info.validatedLedger.baseFeeXRP)
if (!this.props.fee) { if (!this.props.fee) {
this.props.onChange(serverFee) this.props.onChange(serverFee)

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}

7
src/components/modals/Send/fields/AmountField.js

@ -20,13 +20,14 @@ class AmountField extends Component<*, { canBeSpent: boolean }> {
} }
} }
componentWillUnmount() { componentWillUnmount() {
this.unmount = true this.syncId++
} }
unmount = false syncId = 0
async resync() { async resync() {
const { account, bridge, transaction } = this.props const { account, bridge, transaction } = this.props
const syncId = ++this.syncId
const canBeSpent = await bridge.canBeSpent(account, transaction) const canBeSpent = await bridge.canBeSpent(account, transaction)
if (this.unmount) return if (this.syncId !== syncId) return
this.setState({ canBeSpent }) this.setState({ canBeSpent })
} }

7
src/components/modals/Send/fields/RecipientField.js

@ -33,16 +33,17 @@ class RecipientField<Transaction> extends Component<Props<Transaction>, { isVali
} }
} }
componentWillUnmount() { componentWillUnmount() {
this.unmount = true this.syncId++
} }
unmount = false syncId = 0
async resync() { async resync() {
const { account, bridge, transaction } = this.props const { account, bridge, transaction } = this.props
const syncId = ++this.syncId
const isValid = await bridge.isRecipientValid( const isValid = await bridge.isRecipientValid(
account.currency, account.currency,
bridge.getTransactionRecipient(account, transaction), bridge.getTransactionRecipient(account, transaction),
) )
if (this.unmount) return if (syncId !== this.syncId) return
this.setState({ isValid }) this.setState({ isValid })
} }

10
src/components/modals/Send/steps/01-step-amount.js

@ -112,14 +112,16 @@ export class StepAmountFooter extends PureComponent<
} }
componentWillUnmount() { componentWillUnmount() {
this._isUnmounted = true this.syncId++
} }
_isUnmounted = false syncId = 0
async resync() { async resync() {
const { account, bridge, transaction } = this.props const { account, bridge, transaction } = this.props
const syncId = ++this.syncId
if (!account || !transaction || !bridge) { if (!account || !transaction || !bridge) {
return return
} }
@ -128,9 +130,9 @@ export class StepAmountFooter extends PureComponent<
try { try {
const totalSpent = await bridge.getTotalSpent(account, transaction) const totalSpent = await bridge.getTotalSpent(account, transaction)
if (this._isUnmounted) return if (syncId !== this.syncId) return
const canBeSpent = await bridge.canBeSpent(account, transaction) const canBeSpent = await bridge.canBeSpent(account, transaction)
if (this._isUnmounted) return if (syncId !== this.syncId) return
this.setState({ totalSpent, canBeSpent, isSyncing: false }) this.setState({ totalSpent, canBeSpent, isSyncing: false })
} catch (err) { } catch (err) {
this.setState({ isSyncing: false }) this.setState({ isSyncing: false })

Loading…
Cancel
Save