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';
|
2022-07-14 00:15:38 +02:00
|
|
|
import ActionableMessage from '../../../components/ui/actionable-message';
|
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-10-29 17:45:50 +02:00
|
|
|
INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY,
|
2021-04-28 20:02:01 +02:00
|
|
|
} from '../../../helpers/constants/error-keys';
|
2022-03-16 23:15:03 +01:00
|
|
|
import { ASSET_TYPES } from '../../../../shared/constants/transaction';
|
2022-07-14 00:15:38 +02:00
|
|
|
import { CONTRACT_ADDRESS_LINK } from '../../../helpers/constants/common';
|
2022-11-28 17:41:42 +01:00
|
|
|
import GasDisplay from '../gas-display';
|
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 = {
|
2018-08-16 09:43:13 +02:00
|
|
|
showHexData: 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-10-29 17:45:50 +02:00
|
|
|
getIsBalanceInsufficient: PropTypes.bool,
|
2021-11-03 20:03:54 +01:00
|
|
|
asset: PropTypes.object,
|
2022-01-19 19:42:41 +01:00
|
|
|
assetError: PropTypes.string,
|
2022-07-14 00:15:38 +02:00
|
|
|
recipient: PropTypes.object,
|
|
|
|
acknowledgeRecipientWarning: PropTypes.func,
|
|
|
|
recipientWarningAcknowledged: 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-09-30 13:57:59 +02:00
|
|
|
networkOrAccountNotSupports1559,
|
2021-10-29 17:45:50 +02:00
|
|
|
getIsBalanceInsufficient,
|
2021-11-03 20:03:54 +01:00
|
|
|
asset,
|
2022-01-19 19:42:41 +01:00
|
|
|
assetError,
|
2022-07-14 00:15:38 +02:00
|
|
|
recipient,
|
|
|
|
recipientWarningAcknowledged,
|
2021-04-28 20:02:01 +02:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
let gasError;
|
2022-01-06 23:56:51 +01:00
|
|
|
if (gasIsExcessive) {
|
|
|
|
gasError = GAS_PRICE_EXCESSIVE_ERROR_KEY;
|
|
|
|
} else if (noGasPrice) {
|
|
|
|
gasError = GAS_PRICE_FETCH_FAILURE_ERROR_KEY;
|
|
|
|
} else if (getIsBalanceInsufficient) {
|
2021-10-29 17:45:50 +02:00
|
|
|
gasError = INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY;
|
2022-01-06 23:56:51 +01:00
|
|
|
}
|
2021-11-03 20:03:54 +01:00
|
|
|
const showHexData =
|
2022-01-10 17:23:53 +01:00
|
|
|
this.props.showHexData &&
|
|
|
|
asset.type !== ASSET_TYPES.TOKEN &&
|
2022-11-15 19:49:42 +01:00
|
|
|
asset.type !== ASSET_TYPES.NFT;
|
2021-04-28 20:02:01 +02:00
|
|
|
|
2022-07-14 00:15:38 +02:00
|
|
|
const showKnownRecipientWarning =
|
|
|
|
recipient.warning === 'knownAddressRecipient';
|
|
|
|
|
2018-04-11 16:21:54 +02:00
|
|
|
return (
|
|
|
|
<PageContainerContent>
|
2018-04-30 18:09:05 +02:00
|
|
|
<div className="send-v2__form">
|
2022-01-19 19:42:41 +01:00
|
|
|
{assetError ? this.renderError(assetError) : null}
|
2021-10-21 18:11:31 +02:00
|
|
|
{isEthGasPrice
|
|
|
|
? this.renderWarning(ETH_GAS_PRICE_FETCH_WARNING_KEY)
|
|
|
|
: null}
|
|
|
|
{error ? this.renderError(error) : null}
|
|
|
|
{warning ? this.renderWarning() : null}
|
2022-07-14 00:15:38 +02:00
|
|
|
{showKnownRecipientWarning && !recipientWarningAcknowledged
|
|
|
|
? this.renderRecipientWarning()
|
|
|
|
: null}
|
2021-06-23 23:35:25 +02:00
|
|
|
<SendAssetRow />
|
|
|
|
<SendAmountRow />
|
2021-10-21 18:11:31 +02:00
|
|
|
{networkOrAccountNotSupports1559 ? <SendGasRow /> : null}
|
2021-11-03 20:03:54 +01:00
|
|
|
{showHexData ? <SendHexDataRow /> : null}
|
2022-11-28 17:41:42 +01:00
|
|
|
<GasDisplay gasError={gasError} />
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-07-14 00:15:38 +02:00
|
|
|
renderRecipientWarning() {
|
|
|
|
const { acknowledgeRecipientWarning } = this.props;
|
|
|
|
const { t } = this.context;
|
|
|
|
return (
|
2022-12-06 17:49:08 +01:00
|
|
|
<div className="send__warning-container" data-testid="send-warning">
|
2022-07-14 00:15:38 +02:00
|
|
|
<ActionableMessage
|
|
|
|
type="danger"
|
|
|
|
useIcon
|
|
|
|
iconFillColor="#d73a49"
|
|
|
|
primaryActionV2={{
|
|
|
|
label: t('tooltipApproveButton'),
|
|
|
|
onClick: acknowledgeRecipientWarning,
|
|
|
|
}}
|
|
|
|
message={t('sendingToTokenContractWarning', [
|
|
|
|
<a
|
|
|
|
key="contractWarningSupport"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
className="send__warning-container__link"
|
|
|
|
href={CONTRACT_ADDRESS_LINK}
|
|
|
|
>
|
|
|
|
{t('learnMoreUpperCase')}
|
|
|
|
</a>,
|
|
|
|
])}
|
|
|
|
roundedButtons
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|