1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-05 07:24:56 +01:00
metamask-extension/ui/pages/error/error.component.js

80 lines
2.1 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { getEnvironmentType } from '../../../app/scripts/lib/util';
import { ENVIRONMENT_TYPE_POPUP } from '../../../shared/constants/app';
class ErrorPage extends PureComponent {
static contextTypes = {
t: PropTypes.func.isRequired,
};
static propTypes = {
error: PropTypes.object.isRequired,
};
2020-11-03 00:41:28 +01:00
renderErrorDetail(content) {
return (
<li>
2020-11-03 00:41:28 +01:00
<p>{content}</p>
</li>
);
}
2020-11-03 00:41:28 +01:00
renderErrorStack(title, stack) {
return (
<li>
2020-11-03 00:41:28 +01:00
<span>{title}</span>
<pre className="error-page__stack">{stack}</pre>
</li>
);
}
2020-11-03 00:41:28 +01:00
render() {
const { error } = this.props;
const { t } = this.context;
const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP;
const supportLink = (
<a
target="_blank"
key="metamaskSupportLink"
rel="noopener noreferrer"
href="https://metamask.zendesk.com/hc/en-us/requests/new"
>
<span className="error-page__link-text">{this.context.t('here')}</span>
</a>
);
const message = isPopup
? t('errorPagePopupMessage', [supportLink])
: t('errorPageMessage', [supportLink]);
return (
<section className="error-page">
2020-11-03 00:41:28 +01:00
<h1 className="error-page__header">{t('errorPageTitle')}</h1>
<h2 className="error-page__subheader">{message}</h2>
<section className="error-page__details">
<details>
2020-11-03 00:41:28 +01:00
<summary>{t('errorDetails')}</summary>
<ul>
2020-11-03 00:41:28 +01:00
{error.message
? this.renderErrorDetail(t('errorMessage', [error.message]))
: null}
{error.code
? this.renderErrorDetail(t('errorCode', [error.code]))
: null}
{error.name
? this.renderErrorDetail(t('errorName', [error.name]))
: null}
{error.stack
? this.renderErrorStack(t('errorStack'), error.stack)
: null}
</ul>
</details>
</section>
</section>
);
}
}
export default ErrorPage;