1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.js

137 lines
3.8 KiB
JavaScript
Raw Normal View History

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 { PageContainerFooter } from '../../../ui/page-container';
import { ConfirmPageContainerSummary, ConfirmPageContainerWarning } from '.';
export default class ConfirmPageContainerContent extends Component {
2021-06-13 00:25:24 +02:00
static contextTypes = {
t: PropTypes.func.isRequired,
};
static propTypes = {
action: PropTypes.string,
dataComponent: PropTypes.node,
2018-07-06 20:58:41 +02:00
detailsComponent: PropTypes.node,
errorKey: PropTypes.string,
errorMessage: PropTypes.string,
hideSubtitle: PropTypes.bool,
identiconAddress: PropTypes.string,
nonce: PropTypes.string,
2018-08-30 04:13:25 +02:00
assetImage: PropTypes.string,
subtitleComponent: PropTypes.node,
2018-07-06 20:58:41 +02:00
title: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
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,
submitText: PropTypes.string,
disabled: PropTypes.bool,
unapprovedTxCount: PropTypes.number,
rejectNText: PropTypes.string,
};
2020-11-03 00:41:28 +01:00
renderContent() {
const { detailsComponent, dataComponent } = this.props;
if (detailsComponent && dataComponent) {
return this.renderTabs();
}
return detailsComponent || dataComponent;
}
2020-11-03 00:41:28 +01:00
renderTabs() {
2021-06-13 00:25:24 +02:00
const { t } = this.context;
const { detailsComponent, dataComponent } = this.props;
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}
</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}
</Tab>
</Tabs>
);
}
2020-11-03 00:41:28 +01:00
render() {
const {
action,
2018-07-06 20:58:41 +02:00
errorKey,
errorMessage,
title,
titleComponent,
subtitleComponent,
hideSubtitle,
identiconAddress,
nonce,
2018-08-30 04:13:25 +02:00
assetImage,
detailsComponent,
dataComponent,
warning,
onCancelAll,
onCancel,
cancelText,
onSubmit,
submitText,
disabled,
unapprovedTxCount,
rejectNText,
origin,
ethGasPriceWarning,
} = this.props;
return (
<div className="confirm-page-container-content">
2020-11-03 00:41:28 +01:00
{warning && <ConfirmPageContainerWarning warning={warning} />}
{ethGasPriceWarning && (
<ConfirmPageContainerWarning warning={ethGasPriceWarning} />
)}
<ConfirmPageContainerSummary
className={classnames({
'confirm-page-container-summary--border':
!detailsComponent || !dataComponent,
})}
action={action}
title={title}
titleComponent={titleComponent}
subtitleComponent={subtitleComponent}
hideSubtitle={hideSubtitle}
identiconAddress={identiconAddress}
nonce={nonce}
assetImage={assetImage}
origin={origin}
/>
2020-11-03 00:41:28 +01:00
{this.renderContent()}
{(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}
submitButtonType="confirm"
disabled={disabled}
>
2020-11-03 00:41:28 +01:00
{unapprovedTxCount > 1 && <a onClick={onCancelAll}>{rejectNText}</a>}
</PageContainerFooter>
</div>
);
}
}