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

63 lines
1.6 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import SendRowWrapper from '../send-row-wrapper';
import UserPreferencedCurrencyInput from '../../../../components/app/user-preferenced-currency-input';
import UserPreferencedTokenInput from '../../../../components/app/user-preferenced-token-input';
import { AssetType } from '../../../../../shared/constants/transaction';
import AmountMaxButton from './amount-max-button';
2018-04-11 16:21:54 +02:00
export default class SendAmountRow extends Component {
static propTypes = {
amount: PropTypes.string,
inError: PropTypes.bool,
asset: PropTypes.object,
2018-04-11 16:21:54 +02:00
updateSendAmount: PropTypes.func,
};
static contextTypes = {
t: PropTypes.func,
};
2018-04-11 16:21:54 +02:00
handleChange = (newAmount) => {
this.props.updateSendAmount(newAmount);
};
2020-11-03 00:41:28 +01:00
renderInput() {
const { amount, inError, asset } = this.props;
return asset.type === AssetType.token ? (
2020-11-03 00:41:28 +01:00
<UserPreferencedTokenInput
error={inError}
onChange={this.handleChange}
token={asset.details}
2020-11-03 00:41:28 +01:00
value={amount}
/>
) : (
<UserPreferencedCurrencyInput
error={inError}
onChange={this.handleChange}
hexValue={amount}
2020-11-03 00:41:28 +01:00
/>
);
}
2020-11-03 00:41:28 +01:00
render() {
const { inError, asset } = this.props;
if (asset.type === AssetType.NFT) {
return null;
}
2018-04-11 16:21:54 +02:00
return (
<SendRowWrapper
label={`${this.context.t('amount')}:`}
showError={inError}
errorType="amount"
2018-04-11 16:21:54 +02:00
>
<AmountMaxButton inError={inError} />
2020-11-03 00:41:28 +01:00
{this.renderInput()}
2018-04-11 16:21:54 +02:00
</SendRowWrapper>
);
2018-04-11 16:21:54 +02:00
}
}