From 6a049e74ced75b50e05af345c131a8edcaf65e23 Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Thu, 14 Jul 2022 17:25:33 +0200 Subject: [PATCH] refactor(ledger): group routes with feature --- .../jwt-signing/ledger-sign-jwt.routes.tsx | 21 +++++ .../ledger-request-keys.routes.tsx | 19 ++++ .../tx-signing/ledger-sign-tx.routes.tsx | 29 +++++++ src/app/routes/app-routes.tsx | 86 +++---------------- 4 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt.routes.tsx create mode 100644 src/app/features/ledger/flows/request-keys/ledger-request-keys.routes.tsx create mode 100644 src/app/features/ledger/flows/tx-signing/ledger-sign-tx.routes.tsx diff --git a/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt.routes.tsx b/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt.routes.tsx new file mode 100644 index 00000000000..6444fd91bef --- /dev/null +++ b/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt.routes.tsx @@ -0,0 +1,21 @@ +import { Route } from 'react-router-dom'; + +import { RouteUrls } from '@shared/route-urls'; +import { LedgerSignJwtContainer } from './ledger-sign-jwt-container'; +import { ConnectLedgerSignJwt } from './steps/connect-ledger-sign-jwt'; +import { ConnectLedgerSignJwtError } from './steps/connect-ledger-sign-jwt-error'; +import { ConnectLedgerSignJwtSuccess } from './steps/connect-ledger-sign-jwt-success'; +import { LedgerJwtSigningRejected } from './steps/transaction-rejected'; +import { SignJwtHash } from './steps/sign-jwt-hash'; +import { LedgerDisconnected } from '../tx-signing/steps/ledger-disconnected'; + +export const ledgerJwtSigningRoutes = ( + }> + } /> + } /> + } /> + } /> + } /> + } /> + +); diff --git a/src/app/features/ledger/flows/request-keys/ledger-request-keys.routes.tsx b/src/app/features/ledger/flows/request-keys/ledger-request-keys.routes.tsx new file mode 100644 index 00000000000..4d5d819e454 --- /dev/null +++ b/src/app/features/ledger/flows/request-keys/ledger-request-keys.routes.tsx @@ -0,0 +1,19 @@ +import { Route } from 'react-router-dom'; + +import { RouteUrls } from '@shared/route-urls'; +import { LedgerRequestKeysContainer } from './ledger-request-keys-container'; +import { ConnectLedgerRequestKeys } from './steps/connect-ledger-request-keys'; +import { PullingKeysFromDevice } from './steps/pulling-keys-from-device'; +import { ConnectLedgerRequestKeysError } from './steps/connect-ledger-request-keys-error'; +import { UnsupportedBrowserLayout } from '../../steps/unsupported-browser.layout'; +import { ConnectLedgerOnboardingSuccess } from './steps/connect-ledger-request-keys-success'; + +export const ledgerRequestKeysRoutes = ( + }> + } /> + } /> + } /> + } /> + } /> + +); diff --git a/src/app/features/ledger/flows/tx-signing/ledger-sign-tx.routes.tsx b/src/app/features/ledger/flows/tx-signing/ledger-sign-tx.routes.tsx new file mode 100644 index 00000000000..b4573800b26 --- /dev/null +++ b/src/app/features/ledger/flows/tx-signing/ledger-sign-tx.routes.tsx @@ -0,0 +1,29 @@ +import { Route } from 'react-router-dom'; + +import { RouteUrls } from '@shared/route-urls'; +import { LedgerSignTxContainer } from './ledger-sign-tx-container'; +import { ConnectLedgerSignTx } from './steps/connect-ledger-sign-tx'; +import { VerifyingPublicKeysMatch } from './steps/verifying-public-keys-match'; +import { ConnectLedgerSignTxError } from './steps/connect-ledger-sign-tx-error'; +import { ConnectLedgerSignTxSuccess } from './steps/connect-ledger-sign-tx-success'; +import { SignLedgerTransaction } from './steps/sign-ledger-transaction'; +import { LedgerDisconnected } from './steps/ledger-disconnected'; +import { LedgerTransactionRejected } from './steps/transaction-rejected'; +import { LedgerPublicKeyMismatch } from './steps/public-key-mismatch'; +import { UnsupportedBrowserLayout } from '../../steps/unsupported-browser.layout'; +import { LedgerDeviceInvalidTx } from './steps/device-invalid-tx'; + +export const ledgerTxSigningRoutes = ( + }> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + +); diff --git a/src/app/routes/app-routes.tsx b/src/app/routes/app-routes.tsx index ee4ef35e21a..07e81b49297 100644 --- a/src/app/routes/app-routes.tsx +++ b/src/app/routes/app-routes.tsx @@ -1,4 +1,4 @@ -import { Suspense, useEffect, useMemo } from 'react'; +import { Suspense, useEffect } from 'react'; import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom'; import { RouteUrls } from '@shared/route-urls'; @@ -12,10 +12,7 @@ import { SignatureRequest } from '@app/pages/signature-request/signature-request import { SignIn } from '@app/pages/onboarding/sign-in/sign-in'; import { ReceiveTokens } from '@app/pages/receive-tokens/receive-tokens'; import { AddNetwork } from '@app/pages/add-network/add-network'; -import { ConnectLedgerRequestKeys } from '@app/features/ledger/flows/request-keys/steps/connect-ledger-request-keys'; -import { ConnectLedgerRequestKeysError } from '@app/features/ledger/flows/request-keys/steps/connect-ledger-request-keys-error'; -import { ConnectLedgerOnboardingSuccess } from '@app/features/ledger/flows/request-keys/steps/connect-ledger-request-keys-success'; -import { LedgerDisconnected } from '@app/features/ledger/flows/tx-signing/steps/ledger-disconnected'; + import { SetPasswordPage } from '@app/pages/onboarding/set-password/set-password'; import { SendTokensForm } from '@app/pages/send-tokens/send-tokens'; import { ViewSecretKey } from '@app/pages/view-secret-key/view-secret-key'; @@ -27,33 +24,20 @@ import { AllowDiagnosticsPage } from '@app/pages/allow-diagnostics/allow-diagnos import { FundPage } from '@app/pages/fund/fund'; import { BackUpSecretKeyPage } from '@app/pages/onboarding/back-up-secret-key/back-up-secret-key'; import { WelcomePage } from '@app/pages/onboarding/welcome/welcome'; -import { LedgerRequestKeysContainer } from '@app/features/ledger/flows/request-keys/ledger-request-keys-container'; -import { SignLedgerTransaction } from '@app/features/ledger/flows/tx-signing/steps/sign-ledger-transaction'; + import { useHasStateRehydrated } from '@app/store'; import { UnauthorizedRequest } from '@app/pages/unauthorized-request/unauthorized-request'; -import { ConnectLedgerSignTxError } from '@app/features/ledger/flows/tx-signing/steps/connect-ledger-sign-tx-error'; -import { ConnectLedgerSignTxSuccess } from '@app/features/ledger/flows/tx-signing/steps/connect-ledger-sign-tx-success'; -import { LedgerSignTxContainer } from '@app/features/ledger/flows/tx-signing/ledger-sign-tx-container'; -import { ConnectLedgerSignTx } from '@app/features/ledger/flows/tx-signing/steps/connect-ledger-sign-tx'; -import { LedgerTransactionRejected } from '@app/features/ledger/flows/tx-signing/steps/transaction-rejected'; -import { LedgerPublicKeyMismatch } from '@app/features/ledger/flows/tx-signing/steps/public-key-mismatch'; -import { VerifyingPublicKeysMatch } from '@app/features/ledger/flows/tx-signing/steps/verifying-public-keys-match'; -import { PullingKeysFromDevice } from '@app/features/ledger/flows/request-keys/steps/pulling-keys-from-device'; -import { UnsupportedBrowserLayout } from '@app/features/ledger/steps/unsupported-browser.layout'; -import { LedgerSignJwtContainer } from '@app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container'; -import { SignJwtHash } from '@app/features/ledger/flows/jwt-signing/steps/sign-jwt-hash'; -import { ConnectLedgerSignJwt } from '@app/features/ledger/flows/jwt-signing/steps/connect-ledger-sign-jwt'; -import { ConnectLedgerSignJwtError } from '@app/features/ledger/flows/jwt-signing/steps/connect-ledger-sign-jwt-error'; -import { ConnectLedgerSignJwtSuccess } from '@app/features/ledger/flows/jwt-signing/steps/connect-ledger-sign-jwt-success'; -import { LedgerJwtSigningRejected } from '@app/features/ledger/flows/jwt-signing/steps/transaction-rejected'; + import { IncreaseFeeDrawer } from '@app/features/increase-fee-drawer/increase-fee-drawer'; -import { LedgerDeviceInvalidTx } from '@app/features/ledger/flows/tx-signing/steps/device-invalid-tx'; +import { ledgerJwtSigningRoutes } from '@app/features/ledger/flows/jwt-signing/ledger-sign-jwt.routes'; +import { ledgerTxSigningRoutes } from '@app/features/ledger/flows/tx-signing/ledger-sign-tx.routes'; +import { ledgerRequestKeysRoutes } from '@app/features/ledger/flows/request-keys/ledger-request-keys.routes'; import { useOnWalletLock } from './hooks/use-on-wallet-lock'; import { useOnSignOut } from './hooks/use-on-sign-out'; import { OnboardingGate } from './onboarding-gate'; -export function AppRoutes(): JSX.Element | null { +export function AppRoutes() { const { pathname } = useLocation(); const navigate = useNavigate(); const analytics = useAnalytics(); @@ -61,44 +45,9 @@ export function AppRoutes(): JSX.Element | null { useOnWalletLock(() => navigate(RouteUrls.Unlock)); useOnSignOut(() => window.close()); - useEffect(() => { - void analytics.page('view', `${pathname}`); - }, [analytics, pathname]); + useEffect(() => void analytics.page('view', `${pathname}`), [analytics, pathname]); const hasStateRehydrated = useHasStateRehydrated(); - - const ledgerTxSigningRoutes = useMemo( - () => ( - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - ), - [] - ); - - const ledgerJwtSigningRoutes = useMemo( - () => ( - }> - } /> - } /> - } /> - } /> - } /> - } /> - - ), - [] - ); - if (!hasStateRehydrated) return ; return ( @@ -129,22 +78,7 @@ export function AppRoutes(): JSX.Element | null { } > - }> - } /> - } /> - } - /> - } - /> - } - /> - + {ledgerRequestKeysRoutes}