1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00
metamask-extension/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.js
Alex Donesky 4826c8c95e
Feat/collectibles send flow (#13048)
* Add collectibles send flow
2022-01-10 10:23:53 -06:00

177 lines
5.1 KiB
JavaScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Tabs, Tab } from '../../../ui/tabs';
import ErrorMessage from '../../../ui/error-message';
import ActionableMessage from '../../../ui/actionable-message/actionable-message';
import { PageContainerFooter } from '../../../ui/page-container';
import { ConfirmPageContainerSummary, ConfirmPageContainerWarning } from '.';
export default class ConfirmPageContainerContent extends Component {
static contextTypes = {
t: PropTypes.func.isRequired,
};
static propTypes = {
action: PropTypes.string,
dataComponent: PropTypes.node,
dataHexComponent: PropTypes.node,
detailsComponent: PropTypes.node,
errorKey: PropTypes.string,
errorMessage: PropTypes.string,
hasSimulationError: PropTypes.bool,
hideSubtitle: PropTypes.bool,
identiconAddress: PropTypes.string,
nonce: PropTypes.string,
subtitleComponent: PropTypes.node,
title: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
image: PropTypes.string,
titleComponent: PropTypes.node,
warning: PropTypes.string,
origin: PropTypes.string.isRequired,
ethGasPriceWarning: PropTypes.string,
// Footer
onCancelAll: PropTypes.func,
onCancel: PropTypes.func,
cancelText: PropTypes.string,
onSubmit: PropTypes.func,
setUserAcknowledgedGasMissing: PropTypes.func,
submitText: PropTypes.string,
disabled: PropTypes.bool,
hideUserAcknowledgedGasMissing: PropTypes.bool,
unapprovedTxCount: PropTypes.number,
rejectNText: PropTypes.string,
hideTitle: PropTypes.bool,
supportsEIP1559V2: PropTypes.bool,
};
renderContent() {
const { detailsComponent, dataComponent } = this.props;
if (detailsComponent && dataComponent) {
return this.renderTabs();
}
return detailsComponent || dataComponent;
}
renderTabs() {
const { t } = this.context;
const { detailsComponent, dataComponent, dataHexComponent } = this.props;
return (
<Tabs>
<Tab
className="confirm-page-container-content__tab"
name={t('details')}
>
{detailsComponent}
</Tab>
<Tab className="confirm-page-container-content__tab" name={t('data')}>
{dataComponent}
</Tab>
{dataHexComponent && (
<Tab
className="confirm-page-container-content__tab"
name={t('dataHex')}
>
{dataHexComponent}
</Tab>
)}
</Tabs>
);
}
render() {
const {
action,
errorKey,
errorMessage,
hasSimulationError,
title,
image,
titleComponent,
subtitleComponent,
hideSubtitle,
identiconAddress,
nonce,
detailsComponent,
dataComponent,
warning,
onCancelAll,
onCancel,
cancelText,
onSubmit,
submitText,
disabled,
unapprovedTxCount,
rejectNText,
origin,
ethGasPriceWarning,
hideTitle,
setUserAcknowledgedGasMissing,
hideUserAcknowledgedGasMissing,
supportsEIP1559V2,
} = this.props;
const primaryAction = hideUserAcknowledgedGasMissing
? null
: {
label: this.context.t('tryAnywayOption'),
onClick: setUserAcknowledgedGasMissing,
};
return (
<div className="confirm-page-container-content">
{warning ? <ConfirmPageContainerWarning warning={warning} /> : null}
{ethGasPriceWarning && (
<ConfirmPageContainerWarning warning={ethGasPriceWarning} />
)}
{hasSimulationError && (
<div className="confirm-page-container-content__error-container">
<ActionableMessage
type="danger"
primaryAction={primaryAction}
message={this.context.t('simulationErrorMessage')}
/>
</div>
)}
<ConfirmPageContainerSummary
className={classnames({
'confirm-page-container-summary--border':
!detailsComponent || !dataComponent,
})}
action={action}
title={title}
image={image}
titleComponent={titleComponent}
subtitleComponent={subtitleComponent}
hideSubtitle={hideSubtitle}
identiconAddress={identiconAddress}
nonce={nonce}
origin={origin}
hideTitle={hideTitle}
/>
{this.renderContent()}
{!supportsEIP1559V2 &&
!hasSimulationError &&
(errorKey || errorMessage) && (
<div className="confirm-page-container-content__error-container">
<ErrorMessage errorMessage={errorMessage} errorKey={errorKey} />
</div>
)}
<PageContainerFooter
onCancel={onCancel}
cancelText={cancelText}
onSubmit={onSubmit}
submitText={submitText}
disabled={disabled}
>
{unapprovedTxCount > 1 ? (
<a onClick={onCancelAll}>{rejectNText}</a>
) : null}
</PageContainerFooter>
</div>
);
}
}