From cf9f313e4c1722f25919a4e5c4ddae69a09420b9 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Wed, 6 Dec 2023 05:31:40 -0800 Subject: [PATCH] feat(trading): error boundaries for panes, sidebars, pages (#5438) --- .eslintrc.json | 1 + apps/trading/client-pages/fees/fees.tsx | 17 ++-- .../client-pages/liquidity/liquidity.tsx | 28 ++++--- .../client-pages/market/trade-grid.tsx | 63 +++++++++++---- .../client-pages/market/trade-panels.tsx | 21 +++-- .../client-pages/markets/markets-page.tsx | 13 ++- .../client-pages/portfolio/portfolio.tsx | 33 ++++++-- .../client-pages/referrals/referrals.tsx | 5 +- apps/trading/client-pages/rewards/rewards.tsx | 15 ++-- .../error-boundary/error-boundary.spec.tsx | 79 +++++++++++++++++++ .../error-boundary/error-boundary.tsx | 53 +++++++++++++ .../components/error-boundary/index.ts | 1 + apps/trading/components/sidebar/sidebar.tsx | 35 +++++--- libs/logger/src/hooks/use-logger.ts | 1 + libs/logger/src/lib/local-logger.spec.ts | 5 +- libs/logger/src/lib/local-logger.ts | 4 +- 16 files changed, 302 insertions(+), 72 deletions(-) create mode 100644 apps/trading/components/error-boundary/error-boundary.spec.tsx create mode 100644 apps/trading/components/error-boundary/error-boundary.tsx create mode 100644 apps/trading/components/error-boundary/index.ts diff --git a/.eslintrc.json b/.eslintrc.json index e58c2f737..a77e58402 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -77,6 +77,7 @@ "fixStyle": "inline-type-imports" } ], + "@typescript-eslint/no-useless-constructor": 0, "curly": ["error", "multi-line"] } }, diff --git a/apps/trading/client-pages/fees/fees.tsx b/apps/trading/client-pages/fees/fees.tsx index 134c26a1a..1cee72cba 100644 --- a/apps/trading/client-pages/fees/fees.tsx +++ b/apps/trading/client-pages/fees/fees.tsx @@ -1,8 +1,9 @@ +import { useEffect } from 'react'; +import { titlefy } from '@vegaprotocol/utils'; +import { ErrorBoundary } from '../../components/error-boundary'; import { FeesContainer } from '../../components/fees-container'; import { useT } from '../../lib/use-t'; import { usePageTitleStore } from '../../stores'; -import { titlefy } from '@vegaprotocol/utils'; -import { useEffect } from 'react'; export const Fees = () => { const t = useT(); @@ -10,13 +11,17 @@ export const Fees = () => { const { updateTitle } = usePageTitleStore((store) => ({ updateTitle: store.updateTitle, })); + useEffect(() => { updateTitle(titlefy([title])); }, [updateTitle, title]); + return ( -
-

{title}

- -
+ +
+

{title}

+ +
+
); }; diff --git a/apps/trading/client-pages/liquidity/liquidity.tsx b/apps/trading/client-pages/liquidity/liquidity.tsx index 2e4f98a7b..cf72e647c 100644 --- a/apps/trading/client-pages/liquidity/liquidity.tsx +++ b/apps/trading/client-pages/liquidity/liquidity.tsx @@ -6,6 +6,7 @@ import { useEffect, useState } from 'react'; import { useParams } from 'react-router-dom'; import { LiquidityContainer } from '../../components/liquidity-container'; import { useT } from '../../lib/use-t'; +import { ErrorBoundary } from '../../components/error-boundary'; const enum LiquidityTabs { Active = 'active', @@ -58,19 +59,28 @@ export const LiquidityViewContainer = ({ name={t('My liquidity provision')} hidden={!pubKey} > - + + + - + + + - + + + diff --git a/apps/trading/client-pages/market/trade-grid.tsx b/apps/trading/client-pages/market/trade-grid.tsx index 91840752d..239791dec 100644 --- a/apps/trading/client-pages/market/trade-grid.tsx +++ b/apps/trading/client-pages/market/trade-grid.tsx @@ -20,6 +20,7 @@ import { } from '../../components/market-banner'; import { FLAGS } from '@vegaprotocol/environment'; import { useT } from '../../lib/use-t'; +import { ErrorBoundary } from '../../components/error-boundary'; interface TradeGridProps { market: Market | null; @@ -62,28 +63,38 @@ const MainGrid = memo( name={t('Chart')} menu={} > - + + + - + + + - + + + {market && market.tradableInstrument.instrument.product.__typename === 'Perpetual' ? ( - + + + ) : null} {market && market.tradableInstrument.instrument.product.__typename === 'Perpetual' ? ( - + + + ) : null} @@ -96,10 +107,14 @@ const MainGrid = memo( - + + + - + + + @@ -118,31 +133,43 @@ const MainGrid = memo( name={t('Positions')} menu={} > - + + + } > - + + + - + + + - + + + } > - + + + {FLAGS.STOP_ORDERS ? ( - + + + ) : null} @@ -153,7 +180,11 @@ const MainGrid = memo( name={t('Collateral')} menu={} > - + + + diff --git a/apps/trading/client-pages/market/trade-panels.tsx b/apps/trading/client-pages/market/trade-panels.tsx index 6e9849a8e..364365881 100644 --- a/apps/trading/client-pages/market/trade-panels.tsx +++ b/apps/trading/client-pages/market/trade-panels.tsx @@ -1,19 +1,20 @@ -import type { PinnedAsset } from '@vegaprotocol/accounts'; -import type { Market } from '@vegaprotocol/markets'; +import { type PinnedAsset } from '@vegaprotocol/accounts'; +import { type Market } from '@vegaprotocol/markets'; import { OracleBanner } from '@vegaprotocol/markets'; -import type { TradingView } from './trade-views'; -import { TradingViews } from './trade-views'; import { useState } from 'react'; import AutoSizer from 'react-virtualized-auto-sizer'; import classNames from 'classnames'; +import { FLAGS } from '@vegaprotocol/environment'; +import { Splash } from '@vegaprotocol/ui-toolkit'; +import { useT } from '../../lib/use-t'; import { MarketSuccessorBanner, MarketSuccessorProposalBanner, MarketTerminationBanner, } from '../../components/market-banner'; -import { FLAGS } from '@vegaprotocol/environment'; -import { useT } from '../../lib/use-t'; -import { Splash } from '@vegaprotocol/ui-toolkit'; +import { ErrorBoundary } from '../../components/error-boundary'; +import { type TradingView } from './trade-views'; +import { TradingViews } from './trade-views'; interface TradePanelsProps { market: Market | null; @@ -34,7 +35,11 @@ export const TradePanels = ({ market, pinnedAsset }: TradePanelsProps) => { // Watch out here, we don't know what component is being rendered // so watch out for clashes in props - return ; + return ( + + ; + + ); }; const renderMenu = () => { diff --git a/apps/trading/client-pages/markets/markets-page.tsx b/apps/trading/client-pages/markets/markets-page.tsx index f38924556..a39cf9a82 100644 --- a/apps/trading/client-pages/markets/markets-page.tsx +++ b/apps/trading/client-pages/markets/markets-page.tsx @@ -15,6 +15,7 @@ import { useLinks, } from '@vegaprotocol/environment'; import { useT } from '../../lib/use-t'; +import { ErrorBoundary } from '../../components/error-boundary'; export const MarketsPage = () => { const t = useT(); @@ -34,7 +35,9 @@ export const MarketsPage = () => {
- + + + { } > - + + + - + + +
diff --git a/apps/trading/client-pages/portfolio/portfolio.tsx b/apps/trading/client-pages/portfolio/portfolio.tsx index ad17b1cf5..a63f5af2f 100644 --- a/apps/trading/client-pages/portfolio/portfolio.tsx +++ b/apps/trading/client-pages/portfolio/portfolio.tsx @@ -25,6 +25,7 @@ import { DepositsMenu } from '../../components/deposits-menu'; import { WithdrawalsMenu } from '../../components/withdrawals-menu'; import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id'; import { useT } from '../../lib/use-t'; +import { ErrorBoundary } from '../../components/error-boundary'; const WithdrawalsIndicator = () => { const { ready } = useIncompleteWithdrawals(); @@ -72,19 +73,29 @@ export const Portfolio = () => { name={t('Positions')} menu={} > - + + + - + + + - + + + - + + + - + + + @@ -101,10 +112,14 @@ export const Portfolio = () => { name={t('Collateral')} menu={} > - + + + }> - + + + { indicator={} menu={} > - + + + diff --git a/apps/trading/client-pages/referrals/referrals.tsx b/apps/trading/client-pages/referrals/referrals.tsx index ac06f7257..19c530887 100644 --- a/apps/trading/client-pages/referrals/referrals.tsx +++ b/apps/trading/client-pages/referrals/referrals.tsx @@ -18,6 +18,7 @@ import { usePageTitleStore } from '../../stores'; import { useEffect } from 'react'; import { titlefy } from '@vegaprotocol/utils'; import { useT } from '../../lib/use-t'; +import { ErrorBoundary } from '../../components/error-boundary'; const Nav = () => { const t = useT(); @@ -65,7 +66,7 @@ export const Referrals = () => { }, [updateTitle, t]); return ( - <> + {showNav &&