2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import PageContainerContent from '../../../components/ui/page-container/page-container-content.component';
|
|
|
|
import Dialog from '../../../components/ui/dialog';
|
2021-04-28 20:02:01 +02:00
|
|
|
import {
|
|
|
|
ETH_GAS_PRICE_FETCH_WARNING_KEY,
|
|
|
|
GAS_PRICE_FETCH_FAILURE_ERROR_KEY,
|
|
|
|
GAS_PRICE_EXCESSIVE_ERROR_KEY,
|
2021-06-22 19:39:44 +02:00
|
|
|
UNSENDABLE_ASSET_ERROR_KEY,
|
2021-04-28 20:02:01 +02:00
|
|
|
} from '../../../helpers/constants/error-keys';
|
2021-02-04 19:15:23 +01:00
|
|
|
import SendAmountRow from './send-amount-row';
|
|
|
|
import SendHexDataRow from './send-hex-data-row';
|
|
|
|
import SendAssetRow from './send-asset-row';
|
2021-07-31 03:29:21 +02:00
|
|
|
import SendGasRow from './send-gas-row';
|
2018-04-11 16:21:54 +02:00
|
|
|
|
|
|
|
export default class SendContent extends Component {
|
2019-07-31 21:56:44 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2018-05-23 18:43:25 +02:00
|
|
|
static propTypes = {
|
2021-06-23 23:35:25 +02:00
|
|
|
isAssetSendable: PropTypes.bool,
|
2019-07-31 21:56:44 +02:00
|
|
|
showAddToAddressBookModal: PropTypes.func,
|
2018-08-16 09:43:13 +02:00
|
|
|
showHexData: PropTypes.bool,
|
2019-08-14 01:13:05 +02:00
|
|
|
contact: PropTypes.object,
|
|
|
|
isOwnedAccount: PropTypes.bool,
|
2020-08-28 17:27:07 +02:00
|
|
|
warning: PropTypes.string,
|
2021-03-03 01:28:12 +01:00
|
|
|
error: PropTypes.string,
|
2021-03-05 18:32:09 +01:00
|
|
|
gasIsExcessive: PropTypes.bool.isRequired,
|
2021-04-28 20:02:01 +02:00
|
|
|
isEthGasPrice: PropTypes.bool,
|
|
|
|
noGasPrice: PropTypes.bool,
|
2021-09-30 13:57:59 +02:00
|
|
|
networkOrAccountNotSupports1559: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-23 18:43:25 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-04-28 20:02:01 +02:00
|
|
|
const {
|
|
|
|
warning,
|
|
|
|
error,
|
|
|
|
gasIsExcessive,
|
|
|
|
isEthGasPrice,
|
|
|
|
noGasPrice,
|
2021-06-23 23:35:25 +02:00
|
|
|
isAssetSendable,
|
2021-09-30 13:57:59 +02:00
|
|
|
networkOrAccountNotSupports1559,
|
2021-04-28 20:02:01 +02:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
let gasError;
|
|
|
|
if (gasIsExcessive) gasError = GAS_PRICE_EXCESSIVE_ERROR_KEY;
|
|
|
|
else if (noGasPrice) gasError = GAS_PRICE_FETCH_FAILURE_ERROR_KEY;
|
|
|
|
|
2018-04-11 16:21:54 +02:00
|
|
|
return (
|
|
|
|
<PageContainerContent>
|
2018-04-30 18:09:05 +02:00
|
|
|
<div className="send-v2__form">
|
2021-04-28 20:02:01 +02:00
|
|
|
{gasError && this.renderError(gasError)}
|
|
|
|
{isEthGasPrice && this.renderWarning(ETH_GAS_PRICE_FETCH_WARNING_KEY)}
|
2021-06-23 23:35:25 +02:00
|
|
|
{isAssetSendable === false &&
|
|
|
|
this.renderError(UNSENDABLE_ASSET_ERROR_KEY)}
|
2021-06-22 19:39:44 +02:00
|
|
|
{error && this.renderError(error)}
|
2020-11-03 00:41:28 +01:00
|
|
|
{warning && this.renderWarning()}
|
|
|
|
{this.maybeRenderAddContact()}
|
2021-06-23 23:35:25 +02:00
|
|
|
<SendAssetRow />
|
|
|
|
<SendAmountRow />
|
2021-09-30 13:57:59 +02:00
|
|
|
{networkOrAccountNotSupports1559 && <SendGasRow />}
|
2021-06-23 23:35:25 +02:00
|
|
|
{this.props.showHexData && <SendHexDataRow />}
|
2018-04-11 16:21:54 +02:00
|
|
|
</div>
|
|
|
|
</PageContainerContent>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
maybeRenderAddContact() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
isOwnedAccount,
|
|
|
|
showAddToAddressBookModal,
|
|
|
|
contact = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
if (isOwnedAccount || contact.name) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog
|
|
|
|
type="message"
|
|
|
|
className="send__dialog"
|
|
|
|
onClick={showAddToAddressBookModal}
|
|
|
|
>
|
|
|
|
{t('newAccountDetectedDialogMessage')}
|
|
|
|
</Dialog>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
2020-08-28 17:27:07 +02:00
|
|
|
|
2021-04-28 20:02:01 +02:00
|
|
|
renderWarning(gasWarning = '') {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
|
|
|
const { warning } = this.props;
|
2020-08-28 17:27:07 +02:00
|
|
|
return (
|
2020-11-03 00:41:28 +01:00
|
|
|
<Dialog type="warning" className="send__error-dialog">
|
2021-04-28 20:02:01 +02:00
|
|
|
{gasWarning === '' ? t(warning) : t(gasWarning)}
|
2020-08-28 17:27:07 +02:00
|
|
|
</Dialog>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-08-28 17:27:07 +02:00
|
|
|
}
|
2021-03-03 01:28:12 +01:00
|
|
|
|
2021-06-22 19:39:44 +02:00
|
|
|
renderError(error) {
|
2021-03-03 01:28:12 +01:00
|
|
|
const { t } = this.context;
|
|
|
|
return (
|
|
|
|
<Dialog type="error" className="send__error-dialog">
|
2021-06-22 19:39:44 +02:00
|
|
|
{t(error)}
|
2021-03-03 01:28:12 +01:00
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|