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-12-01 18:22:08 +01:00
|
|
|
import NicknamePopovers from '../../../components/app/modals/nickname-popovers';
|
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-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';
|
2021-11-03 20:03:54 +01:00
|
|
|
import { ASSET_TYPES } from '../../../ducks/send';
|
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 {
|
2021-12-01 18:22:08 +01:00
|
|
|
state = {
|
|
|
|
showNicknamePopovers: false,
|
|
|
|
};
|
|
|
|
|
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,
|
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-10-29 17:45:50 +02:00
|
|
|
getIsBalanceInsufficient: PropTypes.bool,
|
2021-11-03 20:03:54 +01:00
|
|
|
asset: PropTypes.object,
|
2021-12-01 18:22:08 +01:00
|
|
|
to: PropTypes.string,
|
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-10-29 17:45:50 +02:00
|
|
|
getIsBalanceInsufficient,
|
2021-11-03 20:03:54 +01:00
|
|
|
asset,
|
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;
|
2021-10-29 17:45:50 +02:00
|
|
|
else if (getIsBalanceInsufficient)
|
|
|
|
gasError = INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY;
|
2021-11-03 20:03:54 +01:00
|
|
|
const showHexData =
|
|
|
|
this.props.showHexData && asset.type !== ASSET_TYPES.TOKEN;
|
2021-04-28 20:02:01 +02:00
|
|
|
|
2018-04-11 16:21:54 +02:00
|
|
|
return (
|
|
|
|
<PageContainerContent>
|
2018-04-30 18:09:05 +02:00
|
|
|
<div className="send-v2__form">
|
2021-10-21 18:11:31 +02:00
|
|
|
{gasError ? this.renderError(gasError) : null}
|
|
|
|
{isEthGasPrice
|
|
|
|
? this.renderWarning(ETH_GAS_PRICE_FETCH_WARNING_KEY)
|
|
|
|
: null}
|
|
|
|
{isAssetSendable === false
|
|
|
|
? this.renderError(UNSENDABLE_ASSET_ERROR_KEY)
|
|
|
|
: null}
|
|
|
|
{error ? this.renderError(error) : null}
|
|
|
|
{warning ? this.renderWarning() : null}
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.maybeRenderAddContact()}
|
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}
|
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;
|
2021-12-01 18:22:08 +01:00
|
|
|
const { isOwnedAccount, contact = {}, to } = this.props;
|
|
|
|
const { showNicknamePopovers } = this.state;
|
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 (
|
2021-12-01 18:22:08 +01:00
|
|
|
<>
|
|
|
|
<Dialog
|
|
|
|
type="message"
|
|
|
|
className="send__dialog"
|
|
|
|
onClick={() => this.setState({ showNicknamePopovers: true })}
|
|
|
|
>
|
|
|
|
{t('newAccountDetectedDialogMessage')}
|
|
|
|
</Dialog>
|
|
|
|
{showNicknamePopovers ? (
|
|
|
|
<NicknamePopovers
|
|
|
|
onClose={() => this.setState({ showNicknamePopovers: false })}
|
|
|
|
address={to}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</>
|
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
|
|
|
}
|