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.
124 lines
2.8 KiB
124 lines
2.8 KiB
7 years ago
|
import React, { Component } from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
7 years ago
|
import SendRowWrapper from '../send-row-wrapper/'
|
||
|
import AmountMaxButton from './amount-max-button/'
|
||
6 years ago
|
import CurrencyDisplay from '../../currency-display'
|
||
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,
|
||
6 years ago
|
updateGasFeeError: PropTypes.func,
|
||
7 years ago
|
updateSendAmount: PropTypes.func,
|
||
7 years ago
|
updateSendAmountError: PropTypes.func,
|
||
6 years ago
|
updateGas: PropTypes.func,
|
||
6 years ago
|
};
|
||
|
|
||
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
|
};
|
||
7 years ago
|
|
||
|
validateAmount (amount) {
|
||
|
const {
|
||
|
amountConversionRate,
|
||
7 years ago
|
balance,
|
||
7 years ago
|
conversionRate,
|
||
7 years ago
|
gasTotal,
|
||
|
primaryCurrency,
|
||
|
selectedToken,
|
||
|
tokenBalance,
|
||
6 years ago
|
updateGasFeeError,
|
||
7 years ago
|
updateSendAmountError,
|
||
|
} = this.props
|
||
|
|
||
|
updateSendAmountError({
|
||
|
amount,
|
||
|
amountConversionRate,
|
||
|
balance,
|
||
|
conversionRate,
|
||
|
gasTotal,
|
||
|
primaryCurrency,
|
||
|
selectedToken,
|
||
|
tokenBalance,
|
||
|
})
|
||
6 years ago
|
|
||
|
if (selectedToken) {
|
||
|
updateGasFeeError({
|
||
|
amount,
|
||
|
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)
|
||
6 years ago
|
}
|
||
|
|
||
|
updateGas (amount) {
|
||
|
const { selectedToken, updateGas } = this.props
|
||
|
|
||
|
if (selectedToken) {
|
||
|
updateGas({ amount })
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
render () {
|
||
|
const {
|
||
|
amount,
|
||
|
amountConversionRate,
|
||
|
convertedCurrency,
|
||
|
gasTotal,
|
||
7 years ago
|
inError,
|
||
7 years ago
|
primaryCurrency,
|
||
7 years ago
|
selectedToken,
|
||
|
} = this.props
|
||
|
|
||
|
return (
|
||
|
<SendRowWrapper
|
||
|
label={`${this.context.t('amount')}:`}
|
||
|
showError={inError}
|
||
|
errorType={'amount'}
|
||
|
>
|
||
7 years ago
|
{!inError && gasTotal && <AmountMaxButton />}
|
||
7 years ago
|
<CurrencyDisplay
|
||
7 years ago
|
conversionRate={amountConversionRate}
|
||
|
convertedCurrency={convertedCurrency}
|
||
6 years ago
|
onBlur={newAmount => {
|
||
|
this.updateGas(newAmount)
|
||
|
this.updateAmount(newAmount)
|
||
|
}}
|
||
|
onChange={newAmount => this.validateAmount(newAmount)}
|
||
7 years ago
|
inError={inError}
|
||
7 years ago
|
primaryCurrency={primaryCurrency || 'ETH'}
|
||
7 years ago
|
selectedToken={selectedToken}
|
||
6 years ago
|
value={amount}
|
||
6 years ago
|
step="any"
|
||
7 years ago
|
/>
|
||
7 years ago
|
</SendRowWrapper>
|
||
7 years ago
|
)
|
||
7 years ago
|
}
|
||
|
|
||
|
}
|