From af14a0986ac18992747c9233affc2425bcb50597 Mon Sep 17 00:00:00 2001 From: Kheops <26880866+0xKheops@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:50:43 +0900 Subject: [PATCH] fix: no sentry captures for scans and tx decoding (#1736) * fix: throttle reads on asset discovery store * fix: remove useless shareReplay * fix: remove "failed to scan" sentry capture * fix: dont use sentry's error boundary for tx decoding --- .../components/FallbackErrorBoundary.tsx | 43 +++++++++++++++++++ .../ui/domains/Sign/Ethereum/EthSignBody.tsx | 8 ++-- .../SubSignDecodedCallButtonContent.tsx | 6 +-- .../decode/SubSignDecodedCallContent.tsx | 6 +-- .../decode/SubSignDecodedCallSummaryBlock.tsx | 6 +-- apps/extension/src/ui/state/assetDiscovery.ts | 7 ++- .../src/domains/assetDiscovery/scanner.ts | 2 - 7 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 apps/extension/src/@talisman/components/FallbackErrorBoundary.tsx diff --git a/apps/extension/src/@talisman/components/FallbackErrorBoundary.tsx b/apps/extension/src/@talisman/components/FallbackErrorBoundary.tsx new file mode 100644 index 0000000000..a4f1c8502e --- /dev/null +++ b/apps/extension/src/@talisman/components/FallbackErrorBoundary.tsx @@ -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 + } +} diff --git a/apps/extension/src/ui/domains/Sign/Ethereum/EthSignBody.tsx b/apps/extension/src/ui/domains/Sign/Ethereum/EthSignBody.tsx index 143a46e70e..896ba9bf07 100644 --- a/apps/extension/src/ui/domains/Sign/Ethereum/EthSignBody.tsx +++ b/apps/extension/src/ui/domains/Sign/Ethereum/EthSignBody.tsx @@ -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" @@ -71,8 +71,6 @@ const getComponentFromKnownContractCall = (decodedTx: DecodedEvmTransaction) => } } -const Fallback: FallbackRender = () => - export const EthSignBody: FC = ({ decodedTx, isReady }) => { if (!isReady || !decodedTx) return @@ -80,9 +78,9 @@ export const EthSignBody: FC = ({ decodedTx, isReady }) => { if (Component) return ( - + }> - + ) return diff --git a/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallButtonContent.tsx b/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallButtonContent.tsx index bf241b9430..074cd51f20 100644 --- a/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallButtonContent.tsx +++ b/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallButtonContent.tsx @@ -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" @@ -22,8 +22,8 @@ export const SubSignDecodedCallButtonContent: DecodedCallComponent< if (!Component) return return ( - }> + }> - + ) } diff --git a/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallContent.tsx b/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallContent.tsx index 7688ee1930..cca7afc124 100644 --- a/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallContent.tsx +++ b/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallContent.tsx @@ -1,4 +1,3 @@ -import { ErrorBoundary } from "@sentry/react" import { LoaderIcon } from "@talismn/icons" import { classNames, encodeAnyAddress } from "@talismn/util" import DOMPurify from "dompurify" @@ -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" @@ -21,7 +21,7 @@ export const SubSignDecodedCallContent: FC<{ sapi: ScaleApi payload: SignerPayloadJSON }> = ({ decodedCall, sapi, payload }) => ( - }> + }> }>
{/* Summary can suspense to fetch additional data, and break if a chain uses incompatible types */} @@ -29,7 +29,7 @@ export const SubSignDecodedCallContent: FC<{
-
+ ) const ErrorFallback: FC<{ diff --git a/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallSummaryBlock.tsx b/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallSummaryBlock.tsx index 8df3e39423..501d6d0780 100644 --- a/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallSummaryBlock.tsx +++ b/apps/extension/src/ui/domains/Sign/Substrate/decode/SubSignDecodedCallSummaryBlock.tsx @@ -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" @@ -10,8 +10,8 @@ export const SubSignDecodedCallSummaryBlock: DecodedCallComponent = (pr if (!Component) return null return ( - + - + ) } diff --git a/apps/extension/src/ui/state/assetDiscovery.ts b/apps/extension/src/ui/state/assetDiscovery.ts index d7640625a3..d5ce00fa85 100644 --- a/apps/extension/src/ui/state/assetDiscovery.ts +++ b/apps/extension/src/ui/state/assetDiscovery.ts @@ -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([ @@ -58,6 +62,5 @@ export const [useAssetDiscoveryScanProgress, assetDiscoveryScanProgress$] = bind tokenIds, } }), - shareReplay(1), ), ) diff --git a/packages/extension-core/src/domains/assetDiscovery/scanner.ts b/packages/extension-core/src/domains/assetDiscovery/scanner.ts index 3f36c2f037..48882bf009 100644 --- a/packages/extension-core/src/domains/assetDiscovery/scanner.ts +++ b/packages/extension-core/src/domains/assetDiscovery/scanner.ts @@ -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" @@ -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" }