Skip to content

Commit

Permalink
fix: dont use sentry's error boundary for tx decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKheops committed Dec 10, 2024
1 parent 998b2ea commit e6e44f4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
43 changes: 43 additions & 0 deletions apps/extension/src/@talisman/components/FallbackErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { log } from "extension-shared"
import { Component, ErrorInfo, ReactNode } from "react"

interface FallbackErrorBoundaryProps {
children: ReactNode
fallback: ReactNode
}

interface FallbackErrorBoundaryState {
hasError: boolean
}

/**
* Error boundary that catches errors in its children and renders a fallback UI.
* Use this if you don't want to use the Sentry error boundary.
*/
export class FallbackErrorBoundary extends Component<
FallbackErrorBoundaryProps,
FallbackErrorBoundaryState
> {
constructor(props: FallbackErrorBoundaryProps) {
super(props)
this.state = { hasError: false }
}

static getDerivedStateFromError(_: Error): FallbackErrorBoundaryState {
// Update state so the next render will show the fallback UI.
return { hasError: true }
}

componentDidCatch(error: Error, info: ErrorInfo): void {
log.warn("FallbackErrorBoundary caught an error", { error, info })
}

render() {
if (this.state.hasError) {
// Render the provided fallback UI
return this.props.fallback
}

return this.props.children
}
}
8 changes: 3 additions & 5 deletions apps/extension/src/ui/domains/Sign/Ethereum/EthSignBody.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErrorBoundary, FallbackRender } from "@sentry/react"
import { FC } from "react"

import { FallbackErrorBoundary } from "@talisman/components/FallbackErrorBoundary"
import { DecodedEvmTransaction } from "@ui/domains/Ethereum/util/decodeEvmTransaction"

import { SignViewBodyShimmer } from "../Views/SignViewBodyShimmer"
Expand Down Expand Up @@ -71,18 +71,16 @@ const getComponentFromKnownContractCall = (decodedTx: DecodedEvmTransaction) =>
}
}

const Fallback: FallbackRender = () => <EthSignBodyDefault />

export const EthSignBody: FC<EthSignBodyProps> = ({ decodedTx, isReady }) => {
if (!isReady || !decodedTx) return <SignViewBodyShimmer />

const Component = getComponentFromKnownContractCall(decodedTx)

if (Component)
return (
<ErrorBoundary fallback={Fallback}>
<FallbackErrorBoundary fallback={<EthSignBodyDefault />}>
<Component />
</ErrorBoundary>
</FallbackErrorBoundary>
)

return <EthSignBodyDefault />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErrorBoundary } from "@sentry/react"
import { FC } from "react"

import { FallbackErrorBoundary } from "@talisman/components/FallbackErrorBoundary"
import { DecodedCall } from "@ui/util/scaleApi"

import { SUMMARY_COMPONENTS } from "../summary/calls"
Expand All @@ -22,8 +22,8 @@ export const SubSignDecodedCallButtonContent: DecodedCallComponent<
if (!Component) return <ContentFallback decodedCall={props.decodedCall} />

return (
<ErrorBoundary fallback={<ContentFallback decodedCall={props.decodedCall} />}>
<FallbackErrorBoundary fallback={<ContentFallback decodedCall={props.decodedCall} />}>
<Component {...props} mode={props.mode} />
</ErrorBoundary>
</FallbackErrorBoundary>
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ErrorBoundary } from "@sentry/react"
import { LoaderIcon } from "@talismn/icons"
import { classNames, encodeAnyAddress } from "@talismn/util"
import DOMPurify from "dompurify"
Expand All @@ -12,6 +11,7 @@ import { FC, Suspense, useMemo } from "react"
import { useTranslation } from "react-i18next"

import { CodeBlock } from "@talisman/components/CodeBlock"
import { FallbackErrorBoundary } from "@talisman/components/FallbackErrorBoundary"
import { DecodedCall, ScaleApi } from "@ui/util/scaleApi"

import { SubSignDecodedCallSummaryBlock } from "./SubSignDecodedCallSummaryBlock"
Expand All @@ -21,15 +21,15 @@ export const SubSignDecodedCallContent: FC<{
sapi: ScaleApi
payload: SignerPayloadJSON
}> = ({ decodedCall, sapi, payload }) => (
<ErrorBoundary fallback={() => <ErrorFallback decodedCall={decodedCall} sapi={sapi} />}>
<FallbackErrorBoundary fallback={<ErrorFallback decodedCall={decodedCall} sapi={sapi} />}>
<Suspense fallback={<LoadingShimmer />}>
<div className="text-body-secondary flex flex-col gap-4 text-sm">
{/* Summary can suspense to fetch additional data, and break if a chain uses incompatible types */}
<SubSignDecodedCallSummaryBlock decodedCall={decodedCall} sapi={sapi} payload={payload} />
<DefaultView decodedCall={decodedCall} sapi={sapi} />
</div>
</Suspense>
</ErrorBoundary>
</FallbackErrorBoundary>
)

const ErrorFallback: FC<{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorBoundary } from "@sentry/react"
import { FallbackErrorBoundary } from "@talisman/components/FallbackErrorBoundary"

import { SUMMARY_COMPONENTS } from "../summary/calls"
import { DecodedCallComponent } from "../types"
Expand All @@ -10,8 +10,8 @@ export const SubSignDecodedCallSummaryBlock: DecodedCallComponent<unknown> = (pr
if (!Component) return null

return (
<ErrorBoundary>
<FallbackErrorBoundary fallback={null}>
<Component {...props} mode="block" />
</ErrorBoundary>
</FallbackErrorBoundary>
)
}

0 comments on commit e6e44f4

Please sign in to comment.