mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
* Move send to pages/ * Fix unit tests * Finish UI * Integrate asset dropdown to send actions * Remove console.log * Hide asset change during edit * Enable switch from send token to seand eth * Enable switching from token to eth when editing * Fix linter * Fixing test * Fix unit tests * Fix linter * Fix react warning; remove console.log * fix flat test * Add metrics * Address code review comments * Consistent spacing between send screen form rows. * Reduce height of gas buttons on send screen. * Make send screen gas button height dependent on size of contents.
120 lines
2.8 KiB
JavaScript
120 lines
2.8 KiB
JavaScript
import React, { Component } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import SendRowWrapper from '../send-row-wrapper'
|
|
import AmountMaxButton from './amount-max-button'
|
|
import UserPreferencedCurrencyInput from '../../../../components/app/user-preferenced-currency-input'
|
|
import UserPreferencedTokenInput from '../../../../components/app/user-preferenced-token-input'
|
|
|
|
export default class SendAmountRow extends Component {
|
|
|
|
static propTypes = {
|
|
amount: PropTypes.string,
|
|
amountConversionRate: PropTypes.oneOfType([
|
|
PropTypes.string,
|
|
PropTypes.number,
|
|
]),
|
|
balance: PropTypes.string,
|
|
conversionRate: PropTypes.number,
|
|
convertedCurrency: PropTypes.string,
|
|
gasTotal: PropTypes.string,
|
|
inError: PropTypes.bool,
|
|
primaryCurrency: PropTypes.string,
|
|
selectedToken: PropTypes.object,
|
|
setMaxModeTo: PropTypes.func,
|
|
tokenBalance: PropTypes.string,
|
|
updateGasFeeError: PropTypes.func,
|
|
updateSendAmount: PropTypes.func,
|
|
updateSendAmountError: PropTypes.func,
|
|
updateGas: PropTypes.func,
|
|
}
|
|
|
|
static contextTypes = {
|
|
t: PropTypes.func,
|
|
}
|
|
|
|
validateAmount (amount) {
|
|
const {
|
|
amountConversionRate,
|
|
balance,
|
|
conversionRate,
|
|
gasTotal,
|
|
primaryCurrency,
|
|
selectedToken,
|
|
tokenBalance,
|
|
updateGasFeeError,
|
|
updateSendAmountError,
|
|
} = this.props
|
|
|
|
updateSendAmountError({
|
|
amount,
|
|
amountConversionRate,
|
|
balance,
|
|
conversionRate,
|
|
gasTotal,
|
|
primaryCurrency,
|
|
selectedToken,
|
|
tokenBalance,
|
|
})
|
|
|
|
if (selectedToken) {
|
|
updateGasFeeError({
|
|
amountConversionRate,
|
|
balance,
|
|
conversionRate,
|
|
gasTotal,
|
|
primaryCurrency,
|
|
selectedToken,
|
|
tokenBalance,
|
|
})
|
|
}
|
|
}
|
|
|
|
updateAmount (amount) {
|
|
const { updateSendAmount, setMaxModeTo } = this.props
|
|
|
|
setMaxModeTo(false)
|
|
updateSendAmount(amount)
|
|
}
|
|
|
|
updateGas (amount) {
|
|
const { selectedToken, updateGas } = this.props
|
|
|
|
if (selectedToken) {
|
|
updateGas({ amount })
|
|
}
|
|
}
|
|
|
|
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}
|
|
/>
|
|
)
|
|
}
|
|
|
|
render () {
|
|
const { gasTotal, inError } = this.props
|
|
|
|
return (
|
|
<SendRowWrapper
|
|
label={`${this.context.t('amount')}:`}
|
|
showError={inError}
|
|
errorType={'amount'}
|
|
>
|
|
{!inError && gasTotal && <AmountMaxButton />}
|
|
{ this.renderInput() }
|
|
</SendRowWrapper>
|
|
)
|
|
}
|
|
|
|
}
|