1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 20:57:12 +01:00
metamask-extension/ui/app/components/send/send-content/send-amount-row/send-amount-row.component.js

124 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-04-11 16:21:54 +02:00
import React, { Component } from 'react'
import PropTypes from 'prop-types'
2018-05-15 14:29:23 +02:00
import SendRowWrapper from '../send-row-wrapper/'
import AmountMaxButton from './amount-max-button/'
import CurrencyDisplay from '../../currency-display'
2018-04-11 16:21:54 +02:00
export default class SendAmountRow extends Component {
static propTypes = {
amount: PropTypes.string,
amountConversionRate: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
balance: PropTypes.string,
2018-04-26 18:38:38 +02:00
conversionRate: PropTypes.number,
convertedCurrency: PropTypes.string,
2018-04-11 16:21:54 +02:00
gasTotal: PropTypes.string,
inError: PropTypes.bool,
2018-04-11 16:21:54 +02:00
primaryCurrency: PropTypes.string,
selectedToken: PropTypes.object,
setMaxModeTo: PropTypes.func,
2018-04-11 16:21:54 +02:00
tokenBalance: PropTypes.string,
2018-06-29 19:19:40 +02:00
updateGasFeeError: PropTypes.func,
2018-04-11 16:21:54 +02:00
updateSendAmount: PropTypes.func,
updateSendAmountError: PropTypes.func,
updateGas: PropTypes.func,
};
static contextTypes = {
t: PropTypes.func,
};
2018-04-11 16:21:54 +02:00
validateAmount (amount) {
const {
amountConversionRate,
2018-04-26 18:38:38 +02:00
balance,
conversionRate,
2018-04-11 16:21:54 +02:00
gasTotal,
primaryCurrency,
selectedToken,
tokenBalance,
2018-06-29 19:19:40 +02:00
updateGasFeeError,
2018-04-11 16:21:54 +02:00
updateSendAmountError,
} = this.props
updateSendAmountError({
amount,
amountConversionRate,
balance,
conversionRate,
gasTotal,
primaryCurrency,
selectedToken,
tokenBalance,
})
2018-06-29 19:19:40 +02:00
if (selectedToken) {
updateGasFeeError({
amount,
amountConversionRate,
balance,
conversionRate,
gasTotal,
primaryCurrency,
selectedToken,
tokenBalance,
})
}
2018-04-11 16:21:54 +02:00
}
updateAmount (amount) {
2018-04-11 16:21:54 +02:00
const { updateSendAmount, setMaxModeTo } = this.props
setMaxModeTo(false)
updateSendAmount(amount)
}
updateGas (amount) {
const { selectedToken, updateGas } = this.props
if (selectedToken) {
updateGas({ amount })
}
2018-04-11 16:21:54 +02:00
}
render () {
const {
amount,
amountConversionRate,
convertedCurrency,
gasTotal,
inError,
primaryCurrency,
2018-04-11 16:21:54 +02:00
selectedToken,
} = this.props
return (
<SendRowWrapper
label={`${this.context.t('amount')}:`}
showError={inError}
errorType={'amount'}
>
2018-04-26 18:38:38 +02:00
{!inError && gasTotal && <AmountMaxButton />}
2018-04-11 16:21:54 +02:00
<CurrencyDisplay
conversionRate={amountConversionRate}
convertedCurrency={convertedCurrency}
onBlur={newAmount => {
this.updateGas(newAmount)
this.updateAmount(newAmount)
}}
onChange={newAmount => this.validateAmount(newAmount)}
2018-04-26 18:38:38 +02:00
inError={inError}
primaryCurrency={primaryCurrency || 'ETH'}
2018-04-26 18:38:38 +02:00
selectedToken={selectedToken}
value={amount}
step="any"
2018-04-26 18:38:38 +02:00
/>
2018-04-11 16:21:54 +02:00
</SendRowWrapper>
)
2018-04-11 16:21:54 +02:00
}
}