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

fix: no sentry captures for scans and tx decoding #1736

Merged
merged 4 commits into from
Dec 11, 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
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>
)
}
7 changes: 5 additions & 2 deletions apps/extension/src/ui/state/assetDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const assetDiscoveryBalances$ = from(liveQuery(() => db.assetDiscovery.toArray()
shareReplay(1),
)

export const [useAssetDiscoveryScan, assetDiscoveryScan$] = bind(assetDiscoveryStore.observable)
export const [useAssetDiscoveryScan, assetDiscoveryScan$] = bind(
assetDiscoveryStore.observable.pipe(
throttleTime(100, undefined, { leading: true, trailing: true }),
),
)

export const [useAssetDiscoveryScanProgress, assetDiscoveryScanProgress$] = bind(
combineLatest([
Expand Down Expand Up @@ -58,6 +62,5 @@ export const [useAssetDiscoveryScanProgress, assetDiscoveryScanProgress$] = bind
tokenIds,
}
}),
shareReplay(1),
),
)
2 changes: 0 additions & 2 deletions packages/extension-core/src/domains/assetDiscovery/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import sortBy from "lodash/sortBy"
import { combineLatest, debounceTime, distinctUntilKeyChanged, skip } from "rxjs"
import { PublicClient } from "viem"

import { sentry } from "../../config/sentry"
import { db } from "../../db"
import { chainConnectorEvm } from "../../rpcs/chain-connector-evm"
import { chaindataProvider } from "../../rpcs/chaindata"
Expand Down Expand Up @@ -549,7 +548,6 @@ const getEvmTokenBalancesWithoutAggregator = async (

throw new Error(`Failed to scan ${token.id} (Timeout)`)
} catch (err) {
sentry.captureException(err)
log.error(`Failed to scan ${token.id} for ${address}: `, { err })
return "0"
}
Expand Down
Loading