Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error boundary #1696

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions extension/src/popup/components/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { useTranslation } from "react-i18next";

import IconFail from "popup/assets/icon-fail.svg";
import { Button } from "@stellar/design-system";
import { navigateTo } from "popup/helpers/navigate";
import { ROUTES } from "popup/constants/routes";

import "./styles.scss";

Expand Down Expand Up @@ -51,10 +49,8 @@ export const UnhandledError = ({
errorString: string;
}) => {
const { t } = useTranslation();
// expected to work outside of <Router />
const isOnAccount = window.location.hash === "#/account";
return (
<React.Fragment>
<div className="UnexpectedError">
<View.AppHeader pageTitle={t("Error")} />
<View.Content>
<div className="UnexpectedError__content">
Expand All @@ -67,28 +63,19 @@ export const UnhandledError = ({
<div className="UnexpectedError__error-string">{errorString}</div>
</View.Content>
<View.Footer>
{isOnAccount ? (
<Button
isFullWidth
variant="tertiary"
size="md"
onClick={window.close}
>
{t("Close")}
</Button>
) : (
<Button
isFullWidth
variant="tertiary"
size="md"
onClick={() => {
navigateTo(ROUTES.account);
}}
>
{t("Got it")}
</Button>
)}
<Button
isFullWidth
variant="tertiary"
size="md"
onClick={() => {
// https://stackoverflow.com/questions/57854/how-can-i-close-a-browser-window-without-receiving-the-do-you-want-to-close-thi
window.open("", "_self", "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh interesting!

window.close();
}}
>
{t("Close")}
</Button>
</View.Footer>
</React.Fragment>
</div>
);
};
16 changes: 13 additions & 3 deletions extension/src/popup/components/ErrorBoundary/styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
.UnexpectedError {
width: 100%;
height: 100%;
min-width: 360px;
min-height: 600px;

.View__inset {
border: 0;
}

button {
margin-bottom: 0.5rem;
}

&__content {
flex-grow: 1;
display: flex;
Expand Down Expand Up @@ -101,18 +114,15 @@
}

&__error-code {
font-size: 0.75rem;
line-height: 1.25rem;
}

&__error-block {
margin-top: auto;
font-size: 0.875rem;
text-align: center;
}

&__error-string {
font-size: 0.5rem;
color: var(--sds-clr-gray-12);
margin-top: 0.5rem;
text-align: center;
Expand Down