This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add specific error boundary for safe apps (#3932)
* Add specific error boundary for safe apps * Use render props for the error boundary UI
- Loading branch information
Showing
3 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/routes/safe/components/Apps/components/SafeAppsErrorBoundary.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { ReactNode, ErrorInfo } from 'react' | ||
|
||
type SafeAppsErrorBoundaryProps = { | ||
children?: ReactNode | ||
render: () => ReactNode | ||
} | ||
|
||
type SafeAppsErrorBoundaryState = { | ||
hasError: boolean | ||
error?: Error | ||
} | ||
|
||
class SafeAppsErrorBoundary extends React.Component<SafeAppsErrorBoundaryProps, SafeAppsErrorBoundaryState> { | ||
public state: SafeAppsErrorBoundaryState = { | ||
hasError: false, | ||
} | ||
|
||
constructor(props: SafeAppsErrorBoundaryProps) { | ||
super(props) | ||
this.state = { hasError: false } | ||
} | ||
|
||
public componentDidCatch(error: Error, errorInfo: ErrorInfo): void { | ||
console.error('Uncaught error:', error, errorInfo) | ||
} | ||
|
||
public static getDerivedStateFromError(error: Error): SafeAppsErrorBoundaryState { | ||
return { hasError: true, error } | ||
} | ||
|
||
public render(): React.ReactNode { | ||
if (this.state.hasError) { | ||
return this.props.render() | ||
} | ||
|
||
return this.props.children | ||
} | ||
} | ||
|
||
export default SafeAppsErrorBoundary |
78 changes: 78 additions & 0 deletions
78
src/routes/safe/components/Apps/components/SafeAppsLoadError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { useSelector } from 'react-redux' | ||
import { useHistory } from 'react-router-dom' | ||
import { currentSession } from 'src/logic/currentSession/store/selectors' | ||
import styled from 'styled-components' | ||
import { Text, Link, Icon, FixedIcon, Title } from '@gnosis.pm/safe-react-components' | ||
import { generateSafeRoute, SAFE_ROUTES } from 'src/routes/routes' | ||
|
||
const SafeAppsLoadError = (): React.ReactElement => { | ||
const history = useHistory() | ||
const { currentShortName, currentSafeAddress } = useSelector(currentSession) | ||
const handleGoBack = () => { | ||
history.push( | ||
generateSafeRoute(SAFE_ROUTES.APPS, { | ||
safeAddress: currentSafeAddress, | ||
shortName: currentShortName, | ||
}), | ||
) | ||
} | ||
|
||
return ( | ||
<Wrapper> | ||
<Content> | ||
<Title size="md">Safe App could not be loaded.</Title> | ||
<FixedIcon type="networkError" /> | ||
|
||
<div> | ||
<Text size="xl" as="span"> | ||
In case the problem persists, please reach out to us via{' '} | ||
</Text> | ||
<LinkWrapper> | ||
<a target="_blank" href="https://chat.gnosis-safe.io" rel="noopener noreferrer"> | ||
<Text color="primary" size="lg" as="span"> | ||
Discord | ||
</Text> | ||
</a> | ||
<Icon type="externalLink" color="primary" size="sm" /> | ||
</LinkWrapper> | ||
</div> | ||
|
||
<Link size="lg" color="primary" onClick={handleGoBack}> | ||
Go back to the Safe Apps list | ||
</Link> | ||
</Content> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
const Wrapper = styled.div` | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
` | ||
|
||
const Content = styled.div` | ||
width: 400px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
text-align: center; | ||
> * { | ||
margin-top: 10px; | ||
} | ||
` | ||
|
||
const LinkWrapper = styled.div` | ||
display: inline-flex; | ||
margin-bottom: 10px; | ||
> :first-of-type { | ||
margin-right: 5px; | ||
} | ||
` | ||
|
||
export default SafeAppsLoadError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters