2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../shared/constants/app';
|
2022-01-06 01:55:20 +01:00
|
|
|
import { SUPPORT_REQUEST_LINK } from '../../helpers/constants/common';
|
2022-08-11 19:33:33 +02:00
|
|
|
import {
|
2023-04-03 17:31:04 +02:00
|
|
|
MetaMetricsContextProp,
|
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsEventName,
|
2022-08-11 19:33:33 +02:00
|
|
|
} from '../../../shared/constants/metametrics';
|
2020-01-24 22:11:02 +01:00
|
|
|
|
|
|
|
class ErrorPage extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
2022-08-11 19:33:33 +02:00
|
|
|
trackEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-24 22:11:02 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
error: PropTypes.object.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-24 22:11:02 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderErrorDetail(content) {
|
2020-01-24 22:11:02 +01:00
|
|
|
return (
|
|
|
|
<li>
|
2020-11-03 00:41:28 +01:00
|
|
|
<p>{content}</p>
|
2020-01-24 22:11:02 +01:00
|
|
|
</li>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-24 22:11:02 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderErrorStack(title, stack) {
|
2020-01-24 22:11:02 +01:00
|
|
|
return (
|
|
|
|
<li>
|
2020-11-03 00:41:28 +01:00
|
|
|
<span>{title}</span>
|
|
|
|
<pre className="error-page__stack">{stack}</pre>
|
2020-01-24 22:11:02 +01:00
|
|
|
</li>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-24 22:11:02 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { error } = this.props;
|
|
|
|
const { t } = this.context;
|
2020-01-24 22:11:02 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP;
|
2021-03-03 18:15:24 +01:00
|
|
|
const supportLink = (
|
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
key="metamaskSupportLink"
|
|
|
|
rel="noopener noreferrer"
|
2022-01-06 01:55:20 +01:00
|
|
|
href={SUPPORT_REQUEST_LINK}
|
2022-08-11 19:33:33 +02:00
|
|
|
onClick={() => {
|
|
|
|
this.context.trackEvent(
|
|
|
|
{
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Error,
|
|
|
|
event: MetaMetricsEventName.SupportLinkClicked,
|
2022-08-11 19:33:33 +02:00
|
|
|
properties: {
|
|
|
|
url: SUPPORT_REQUEST_LINK,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-04-03 17:31:04 +02:00
|
|
|
contextPropsIntoEventProperties: [
|
|
|
|
MetaMetricsContextProp.PageTitle,
|
|
|
|
],
|
2022-08-11 19:33:33 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}}
|
2021-03-03 18:15:24 +01:00
|
|
|
>
|
|
|
|
<span className="error-page__link-text">{this.context.t('here')}</span>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
const message = isPopup
|
|
|
|
? t('errorPagePopupMessage', [supportLink])
|
|
|
|
: t('errorPageMessage', [supportLink]);
|
2020-01-24 22:11:02 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="error-page">
|
2020-11-03 00:41:28 +01:00
|
|
|
<h1 className="error-page__header">{t('errorPageTitle')}</h1>
|
2021-03-03 18:15:24 +01:00
|
|
|
<h2 className="error-page__subheader">{message}</h2>
|
2020-01-24 22:11:02 +01:00
|
|
|
<section className="error-page__details">
|
|
|
|
<details>
|
2020-11-03 00:41:28 +01:00
|
|
|
<summary>{t('errorDetails')}</summary>
|
2020-01-24 22:11:02 +01:00
|
|
|
<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}
|
2020-01-24 22:11:02 +01:00
|
|
|
</ul>
|
|
|
|
</details>
|
|
|
|
</section>
|
|
|
|
</section>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-24 22:11:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default ErrorPage;
|