519c411db0
* feat: sync and update with all changes from fork * refactor: extract clipboard copy logic into custom hook * fix: correct spelling of DEFAULT_REFRESH_FREQUENCY_MS in Stamps and WalletBalance providers * refactor(ui-tests): replace fixed sleeps with condition-based waits * fix: handle null values for size and granteeCount in infoGroups * fix(lint): add newline at end of file in useClipboardCopy hook * fix(ui-tests): page.goto URL * refactor: update import paths for useClipboardCopy --------- Co-authored-by: Ferenc Sárai <sarai.ferenc@gmail.com>
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import { Component, ErrorInfo, ReactElement } from 'react'
|
|
|
|
interface Props {
|
|
children: ReactElement
|
|
errorReporting?: (err: Error) => void
|
|
}
|
|
|
|
interface State {
|
|
error: Error | null
|
|
}
|
|
|
|
export default class ErrorBoundary extends Component<Props, State> {
|
|
private errorReporting?: (err: Error) => void
|
|
|
|
constructor(props: Props) {
|
|
super(props)
|
|
this.errorReporting = props.errorReporting
|
|
this.state = { error: null }
|
|
}
|
|
|
|
static getDerivedStateFromError(error: Error): { error: Error } {
|
|
// Update state so the next render will show the fallback UI.
|
|
return { error }
|
|
}
|
|
|
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
|
if (this.errorReporting) {
|
|
this.errorReporting(error)
|
|
}
|
|
|
|
// eslint-disable-next-line no-console
|
|
console.error({ error, errorInfo })
|
|
}
|
|
|
|
render(): ReactElement {
|
|
if (this.state.error) {
|
|
// You can render any custom fallback UI
|
|
return <h1>Something went wrong. Error: {this.state.error.message}</h1>
|
|
}
|
|
|
|
return this.props.children
|
|
}
|
|
}
|