You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
2.8 KiB
120 lines
2.8 KiB
7 years ago
|
import React, { Component } from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
6 years ago
|
import SendRowWrapper from '../send-row-wrapper'
|
||
|
import AmountMaxButton from './amount-max-button'
|
||
6 years ago
|
import UserPreferencedCurrencyInput from '../../../../components/app/user-preferenced-currency-input'
|
||
|
import UserPreferencedTokenInput from '../../../../components/app/user-preferenced-token-input'
|
||
7 years ago
|
|
||
|
export default class SendAmountRow extends Component {
|
||
|
|
||
|
static propTypes = {
|
||
7 years ago
|
amount: PropTypes.string,
|
||
7 years ago
|
amountConversionRate: PropTypes.oneOfType([
|
||
|
PropTypes.string,
|
||
|
PropTypes.number,
|
||
|
]),
|
||
7 years ago
|
balance: PropTypes.string,
|
||
7 years ago
|
conversionRate: PropTypes.number,
|
||
7 years ago
|
convertedCurrency: PropTypes.string,
|
||
7 years ago
|
gasTotal: PropTypes.string,
|
||
7 years ago
|
inError: PropTypes.bool,
|
||
7 years ago
|
primaryCurrency: PropTypes.string,
|
||
|
selectedToken: PropTypes.object,
|
||
7 years ago
|
setMaxModeTo: PropTypes.func,
|
||
7 years ago
|
tokenBalance: PropTypes.string,
|
||
7 years ago
|
updateGasFeeError: PropTypes.func,
|
||
7 years ago
|
updateSendAmount: PropTypes.func,
|
||
7 years ago
|
updateSendAmountError: PropTypes.func,
|
||
7 years ago
|
updateGas: PropTypes.func,
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
|
validateAmount (amount) {
|
||
|
const {
|
||
|
amountConversionRate,
|
||
7 years ago
|
balance,
|
||
7 years ago
|
conversionRate,
|
||
7 years ago
|
gasTotal,
|
||
|
primaryCurrency,
|
||
|
selectedToken,
|
||
|
tokenBalance,
|
||
7 years ago
|
updateGasFeeError,
|
||
7 years ago
|
updateSendAmountError,
|
||
|
} = this.props
|
||
|
|
||
|
updateSendAmountError({
|
||
|
amount,
|
||
|
amountConversionRate,
|
||
|
balance,
|
||
|
conversionRate,
|
||
|
gasTotal,
|
||
|
primaryCurrency,
|
||
|
selectedToken,
|
||
|
tokenBalance,
|
||
|
})
|
||
7 years ago
|
|
||
|
if (selectedToken) {
|
||
|
updateGasFeeError({
|
||
|
amountConversionRate,
|
||
|
balance,
|
||
|
conversionRate,
|
||
|
gasTotal,
|
||
|
primaryCurrency,
|
||
|
selectedToken,
|
||
|
tokenBalance,
|
||
|
})
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
updateAmount (amount) {
|
||
7 years ago
|
const { updateSendAmount, setMaxModeTo } = this.props
|
||
|
|
||
|
setMaxModeTo(false)
|
||
|
updateSendAmount(amount)
|
||
7 years ago
|
}
|
||
|
|
||
|
updateGas (amount) {
|
||
|
const { selectedToken, updateGas } = this.props
|
||
|
|
||
|
if (selectedToken) {
|
||
|
updateGas({ amount })
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
renderInput () {
|
||
|
const { amount, inError, selectedToken } = this.props
|
||
|
const Component = selectedToken ? UserPreferencedTokenInput : UserPreferencedCurrencyInput
|
||
|
|
||
|
return (
|
||
|
<Component
|
||
|
onChange={newAmount => this.validateAmount(newAmount)}
|
||
|
onBlur={newAmount => {
|
||
|
this.updateGas(newAmount)
|
||
|
this.updateAmount(newAmount)
|
||
|
}}
|
||
|
error={inError}
|
||
|
value={amount}
|
||
|
/>
|
||
|
)
|
||
|
}
|
||
|
|
||
7 years ago
|
render () {
|
||
6 years ago
|
const { gasTotal, inError } = this.props
|
||
7 years ago
|
|
||
|
return (
|
||
|
<SendRowWrapper
|
||
|
label={`${this.context.t('amount')}:`}
|
||
|
showError={inError}
|
||
|
errorType={'amount'}
|
||
|
>
|
||
7 years ago
|
{!inError && gasTotal && <AmountMaxButton />}
|
||
6 years ago
|
{ this.renderInput() }
|
||
7 years ago
|
</SendRowWrapper>
|
||
7 years ago
|
)
|
||
7 years ago
|
}
|
||
|
|
||
|
}
|