1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-24 12:23:39 +02:00
metamask-extension/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js

97 lines
2.3 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/'
2018-04-11 16:21:54 +02:00
import CurrencyDisplay from '../../../send/currency-display'
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,
updateSendAmount: PropTypes.func,
updateSendAmountError: 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,
updateSendAmountError,
} = this.props
updateSendAmountError({
amount,
amountConversionRate,
balance,
conversionRate,
gasTotal,
primaryCurrency,
selectedToken,
tokenBalance,
})
}
updateAmount (amount) {
2018-04-11 16:21:54 +02:00
const { updateSendAmount, setMaxModeTo } = this.props
setMaxModeTo(false)
updateSendAmount(amount)
}
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.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 || '0x0'}
/>
2018-04-11 16:21:54 +02:00
</SendRowWrapper>
)
2018-04-11 16:21:54 +02:00
}
}
SendAmountRow.contextTypes = {
t: PropTypes.func,
}