2021-02-04 19:15:23 +01:00
|
|
|
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';
|
2022-03-16 23:15:03 +01:00
|
|
|
import { ASSET_TYPES } from '../../../../../shared/constants/transaction';
|
2021-02-04 19:15:23 +01:00
|
|
|
import AmountMaxButton from './amount-max-button';
|
2018-04-11 16:21:54 +02:00
|
|
|
|
|
|
|
export default class SendAmountRow extends Component {
|
|
|
|
static propTypes = {
|
2018-04-27 02:38:14 +02:00
|
|
|
amount: PropTypes.string,
|
|
|
|
inError: PropTypes.bool,
|
2021-06-23 23:35:25 +02:00
|
|
|
asset: PropTypes.object,
|
2018-04-11 16:21:54 +02:00
|
|
|
updateSendAmount: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-02 04:09:28 +02:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2020-03-11 21:13:48 +01:00
|
|
|
handleChange = (newAmount) => {
|
2021-06-23 23:35:25 +02:00
|
|
|
this.props.updateSendAmount(newAmount);
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-03-11 21:13:48 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderInput() {
|
2021-06-23 23:35:25 +02:00
|
|
|
const { amount, inError, asset } = this.props;
|
2018-10-17 01:03:29 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
return asset.type === ASSET_TYPES.TOKEN ? (
|
2020-11-03 00:41:28 +01:00
|
|
|
<UserPreferencedTokenInput
|
|
|
|
error={inError}
|
|
|
|
onChange={this.handleChange}
|
2021-06-23 23:35:25 +02:00
|
|
|
token={asset.details}
|
2020-11-03 00:41:28 +01:00
|
|
|
value={amount}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<UserPreferencedCurrencyInput
|
|
|
|
error={inError}
|
|
|
|
onChange={this.handleChange}
|
2022-01-20 16:42:13 +01:00
|
|
|
hexValue={amount}
|
2020-11-03 00:41:28 +01:00
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2022-01-10 17:23:53 +01:00
|
|
|
const { inError, asset } = this.props;
|
|
|
|
|
|
|
|
if (asset.type === ASSET_TYPES.COLLECTIBLE) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-11 16:21:54 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SendRowWrapper
|
|
|
|
label={`${this.context.t('amount')}:`}
|
|
|
|
showError={inError}
|
2019-11-18 16:08:47 +01:00
|
|
|
errorType="amount"
|
2018-04-11 16:21:54 +02:00
|
|
|
>
|
2021-06-23 23:35:25 +02:00
|
|
|
<AmountMaxButton inError={inError} />
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderInput()}
|
2018-04-11 16:21:54 +02:00
|
|
|
</SendRowWrapper>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
}
|