2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { Tabs, Tab } from '../../../ui/tabs';
|
2022-02-23 16:03:01 +01:00
|
|
|
import Button from '../../../ui/button';
|
2021-11-22 13:13:30 +01:00
|
|
|
import ActionableMessage from '../../../ui/actionable-message/actionable-message';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { PageContainerFooter } from '../../../ui/page-container';
|
2022-02-23 16:03:01 +01:00
|
|
|
import ErrorMessage from '../../../ui/error-message';
|
|
|
|
import { INSUFFICIENT_FUNDS_ERROR_KEY } from '../../../../helpers/constants/error-keys';
|
|
|
|
import Typography from '../../../ui/typography';
|
|
|
|
import { TYPOGRAPHY } from '../../../../helpers/constants/design-system';
|
|
|
|
import { TRANSACTION_TYPES } from '../../../../../shared/constants/transaction';
|
|
|
|
import { MAINNET_CHAIN_ID } from '../../../../../shared/constants/network';
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import { ConfirmPageContainerSummary, ConfirmPageContainerWarning } from '.';
|
2020-08-18 16:10:56 +02:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
export default class ConfirmPageContainerContent extends Component {
|
2021-06-13 00:25:24 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
static propTypes = {
|
|
|
|
action: PropTypes.string,
|
|
|
|
dataComponent: PropTypes.node,
|
2021-12-01 18:22:08 +01:00
|
|
|
dataHexComponent: PropTypes.node,
|
2018-07-06 20:58:41 +02:00
|
|
|
detailsComponent: PropTypes.node,
|
|
|
|
errorKey: PropTypes.string,
|
|
|
|
errorMessage: PropTypes.string,
|
2021-11-22 13:13:30 +01:00
|
|
|
hasSimulationError: PropTypes.bool,
|
2018-07-06 20:58:41 +02:00
|
|
|
hideSubtitle: PropTypes.bool,
|
2018-06-23 08:52:45 +02:00
|
|
|
identiconAddress: PropTypes.string,
|
|
|
|
nonce: PropTypes.string,
|
2018-10-17 01:03:29 +02:00
|
|
|
subtitleComponent: PropTypes.node,
|
2018-07-06 20:58:41 +02:00
|
|
|
title: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2022-01-10 17:23:53 +01:00
|
|
|
image: PropTypes.string,
|
2018-10-17 01:03:29 +02:00
|
|
|
titleComponent: PropTypes.node,
|
2018-06-23 08:52:45 +02:00
|
|
|
warning: PropTypes.string,
|
2021-01-28 18:59:45 +01:00
|
|
|
origin: PropTypes.string.isRequired,
|
2021-04-28 20:02:01 +02:00
|
|
|
ethGasPriceWarning: PropTypes.string,
|
2020-08-18 16:10:56 +02:00
|
|
|
// Footer
|
|
|
|
onCancelAll: PropTypes.func,
|
|
|
|
onCancel: PropTypes.func,
|
|
|
|
cancelText: PropTypes.string,
|
|
|
|
onSubmit: PropTypes.func,
|
2021-11-24 18:02:53 +01:00
|
|
|
setUserAcknowledgedGasMissing: PropTypes.func,
|
2020-08-18 16:10:56 +02:00
|
|
|
submitText: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool,
|
2021-11-24 18:02:53 +01:00
|
|
|
hideUserAcknowledgedGasMissing: PropTypes.bool,
|
2020-08-18 16:10:56 +02:00
|
|
|
unapprovedTxCount: PropTypes.number,
|
|
|
|
rejectNText: PropTypes.string,
|
2021-11-29 17:08:24 +01:00
|
|
|
hideTitle: PropTypes.bool,
|
|
|
|
supportsEIP1559V2: PropTypes.bool,
|
2022-01-15 04:12:20 +01:00
|
|
|
hasTopBorder: PropTypes.bool,
|
2022-02-23 16:03:01 +01:00
|
|
|
currentTransaction: PropTypes.string,
|
|
|
|
nativeCurrency: PropTypes.string,
|
|
|
|
networkName: PropTypes.string,
|
|
|
|
showBuyModal: PropTypes.func,
|
2022-03-02 16:26:53 +01:00
|
|
|
toAddress: PropTypes.string,
|
|
|
|
transactionType: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderContent() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { detailsComponent, dataComponent } = this.props;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
if (detailsComponent && dataComponent) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return this.renderTabs();
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return detailsComponent || dataComponent;
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderTabs() {
|
2021-06-13 00:25:24 +02:00
|
|
|
const { t } = this.context;
|
2021-12-01 18:22:08 +01:00
|
|
|
const { detailsComponent, dataComponent, dataHexComponent } = this.props;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Tabs>
|
2021-06-13 00:25:24 +02:00
|
|
|
<Tab
|
|
|
|
className="confirm-page-container-content__tab"
|
|
|
|
name={t('details')}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{detailsComponent}
|
2018-06-23 08:52:45 +02:00
|
|
|
</Tab>
|
2021-06-13 00:25:24 +02:00
|
|
|
<Tab className="confirm-page-container-content__tab" name={t('data')}>
|
2020-11-03 00:41:28 +01:00
|
|
|
{dataComponent}
|
2018-06-23 08:52:45 +02:00
|
|
|
</Tab>
|
2021-12-07 16:12:34 +01:00
|
|
|
{dataHexComponent && (
|
|
|
|
<Tab
|
|
|
|
className="confirm-page-container-content__tab"
|
|
|
|
name={t('dataHex')}
|
|
|
|
>
|
|
|
|
{dataHexComponent}
|
|
|
|
</Tab>
|
|
|
|
)}
|
2018-06-23 08:52:45 +02:00
|
|
|
</Tabs>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
|
|
|
action,
|
2018-07-06 20:58:41 +02:00
|
|
|
errorKey,
|
|
|
|
errorMessage,
|
2021-11-22 13:13:30 +01:00
|
|
|
hasSimulationError,
|
2018-06-23 08:52:45 +02:00
|
|
|
title,
|
2022-01-10 17:23:53 +01:00
|
|
|
image,
|
2018-10-17 01:03:29 +02:00
|
|
|
titleComponent,
|
|
|
|
subtitleComponent,
|
2018-06-23 08:52:45 +02:00
|
|
|
hideSubtitle,
|
|
|
|
identiconAddress,
|
|
|
|
nonce,
|
|
|
|
detailsComponent,
|
|
|
|
dataComponent,
|
|
|
|
warning,
|
2020-08-18 16:10:56 +02:00
|
|
|
onCancelAll,
|
|
|
|
onCancel,
|
|
|
|
cancelText,
|
|
|
|
onSubmit,
|
|
|
|
submitText,
|
|
|
|
disabled,
|
|
|
|
unapprovedTxCount,
|
|
|
|
rejectNText,
|
2021-01-28 18:59:45 +01:00
|
|
|
origin,
|
2021-04-28 20:02:01 +02:00
|
|
|
ethGasPriceWarning,
|
2021-11-05 10:12:23 +01:00
|
|
|
hideTitle,
|
2021-11-24 18:02:53 +01:00
|
|
|
setUserAcknowledgedGasMissing,
|
|
|
|
hideUserAcknowledgedGasMissing,
|
2021-11-29 17:08:24 +01:00
|
|
|
supportsEIP1559V2,
|
2022-01-15 04:12:20 +01:00
|
|
|
hasTopBorder,
|
2022-02-23 16:03:01 +01:00
|
|
|
currentTransaction,
|
|
|
|
nativeCurrency,
|
|
|
|
networkName,
|
|
|
|
showBuyModal,
|
2022-03-02 16:26:53 +01:00
|
|
|
toAddress,
|
|
|
|
transactionType,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2021-11-24 18:02:53 +01:00
|
|
|
const primaryAction = hideUserAcknowledgedGasMissing
|
2021-11-22 13:13:30 +01:00
|
|
|
? null
|
|
|
|
: {
|
|
|
|
label: this.context.t('tryAnywayOption'),
|
2021-11-24 18:02:53 +01:00
|
|
|
onClick: setUserAcknowledgedGasMissing,
|
2021-11-22 13:13:30 +01:00
|
|
|
};
|
2022-02-23 16:03:01 +01:00
|
|
|
const { t } = this.context;
|
|
|
|
|
|
|
|
const showInsuffienctFundsError =
|
|
|
|
supportsEIP1559V2 &&
|
|
|
|
!hasSimulationError &&
|
|
|
|
(errorKey || errorMessage) &&
|
|
|
|
errorKey === INSUFFICIENT_FUNDS_ERROR_KEY &&
|
|
|
|
currentTransaction.type === TRANSACTION_TYPES.SIMPLE_SEND;
|
2021-11-22 13:13:30 +01:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
return (
|
2022-01-15 04:12:20 +01:00
|
|
|
<div
|
|
|
|
className={classnames('confirm-page-container-content', {
|
|
|
|
'confirm-page-container-content--with-top-border': hasTopBorder,
|
|
|
|
})}
|
|
|
|
>
|
2021-10-21 18:11:31 +02:00
|
|
|
{warning ? <ConfirmPageContainerWarning warning={warning} /> : null}
|
2021-04-28 20:02:01 +02:00
|
|
|
{ethGasPriceWarning && (
|
|
|
|
<ConfirmPageContainerWarning warning={ethGasPriceWarning} />
|
|
|
|
)}
|
2021-11-22 13:13:30 +01:00
|
|
|
{hasSimulationError && (
|
|
|
|
<div className="confirm-page-container-content__error-container">
|
|
|
|
<ActionableMessage
|
|
|
|
type="danger"
|
|
|
|
primaryAction={primaryAction}
|
2022-02-23 16:03:01 +01:00
|
|
|
message={t('simulationErrorMessage')}
|
2021-11-22 13:13:30 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2021-01-28 18:17:26 +01:00
|
|
|
<ConfirmPageContainerSummary
|
|
|
|
className={classnames({
|
|
|
|
'confirm-page-container-summary--border':
|
|
|
|
!detailsComponent || !dataComponent,
|
|
|
|
})}
|
|
|
|
action={action}
|
|
|
|
title={title}
|
2022-01-10 17:23:53 +01:00
|
|
|
image={image}
|
2021-01-28 18:17:26 +01:00
|
|
|
titleComponent={titleComponent}
|
|
|
|
subtitleComponent={subtitleComponent}
|
|
|
|
hideSubtitle={hideSubtitle}
|
|
|
|
identiconAddress={identiconAddress}
|
|
|
|
nonce={nonce}
|
2021-01-28 18:59:45 +01:00
|
|
|
origin={origin}
|
2021-11-05 10:12:23 +01:00
|
|
|
hideTitle={hideTitle}
|
2022-03-02 16:26:53 +01:00
|
|
|
toAddress={toAddress}
|
|
|
|
transactionType={transactionType}
|
2021-01-28 18:17:26 +01:00
|
|
|
/>
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderContent()}
|
2021-11-29 17:08:24 +01:00
|
|
|
{!supportsEIP1559V2 &&
|
|
|
|
!hasSimulationError &&
|
2022-02-23 16:03:01 +01:00
|
|
|
(errorKey || errorMessage) &&
|
|
|
|
currentTransaction.type !== TRANSACTION_TYPES.SIMPLE_SEND && (
|
2021-11-29 17:08:24 +01:00
|
|
|
<div className="confirm-page-container-content__error-container">
|
|
|
|
<ErrorMessage errorMessage={errorMessage} errorKey={errorKey} />
|
|
|
|
</div>
|
|
|
|
)}
|
2022-02-23 16:03:01 +01:00
|
|
|
{showInsuffienctFundsError && (
|
|
|
|
<div className="confirm-page-container-content__error-container">
|
|
|
|
{currentTransaction.chainId === MAINNET_CHAIN_ID ? (
|
|
|
|
<ActionableMessage
|
|
|
|
className="actionable-message--warning"
|
|
|
|
message={
|
|
|
|
<Typography variant={TYPOGRAPHY.H7} align="left">
|
|
|
|
{t('insufficientCurrency', [nativeCurrency, networkName])}
|
|
|
|
<Button
|
|
|
|
key="link"
|
|
|
|
type="secondary"
|
|
|
|
className="confirm-page-container-content__link"
|
|
|
|
onClick={showBuyModal}
|
|
|
|
>
|
|
|
|
{t('buyEth')}
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
{t('orDeposit')}
|
|
|
|
</Typography>
|
|
|
|
}
|
|
|
|
useIcon
|
|
|
|
iconFillColor="#d73a49"
|
|
|
|
type="danger"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<ActionableMessage
|
|
|
|
className="actionable-message--warning"
|
|
|
|
message={
|
|
|
|
<Typography variant={TYPOGRAPHY.H7} align="left">
|
|
|
|
{t('insufficientCurrency', [nativeCurrency, networkName])}
|
|
|
|
{t('buyOther', [nativeCurrency])}
|
|
|
|
</Typography>
|
|
|
|
}
|
|
|
|
useIcon
|
|
|
|
iconFillColor="#d73a49"
|
|
|
|
type="danger"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2020-08-18 16:10:56 +02:00
|
|
|
<PageContainerFooter
|
|
|
|
onCancel={onCancel}
|
|
|
|
cancelText={cancelText}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
submitText={submitText}
|
|
|
|
disabled={disabled}
|
|
|
|
>
|
2021-10-21 18:11:31 +02:00
|
|
|
{unapprovedTxCount > 1 ? (
|
|
|
|
<a onClick={onCancelAll}>{rejectNText}</a>
|
|
|
|
) : null}
|
2020-08-18 16:10:56 +02:00
|
|
|
</PageContainerFooter>
|
2018-06-23 08:52:45 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|