All files / app routes.tsx

0% Statements 0/36
0% Branches 0/6
0% Functions 0/6
0% Lines 0/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138                                                                                                                                                                                                                                                                                   
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import routes from './constants/routes.json';
import { App } from './pages/app';
import { Home } from './pages/home/home';
import {
  Terms,
  Welcome,
  CreateWallet,
  RestoreWallet,
  GeneratingSecret,
  ConnectLedger,
  SecretKey,
  VerifyKey,
  SetPassword,
} from './pages/onboarding';
import { Diagnostics } from './pages/onboarding/01-diagnostics/diagnostics';
import { Settings } from './pages/settings/settings';
import { StackingDelegation } from './pages/stacking/delegated-stacking/pooled-stacking';
import { DirectStacking } from './pages/stacking/direct-stacking/direct-stacking';
import { ChooseStackingMethod } from './pages/start-stacking/start-stacking';
import { selectAddress } from './store/keys/keys.reducer';
import * as Sentry from '@sentry/react';
import { useHasUserGivenDiagnosticPermissions } from '@store/settings';
import { initSegment } from '@utils/init-segment';
import React, { useEffect, useState } from 'react';
import { useStore } from 'react-redux';
import { Switch, Route, Redirect } from 'react-router-dom';
 
initSegment();
 
Sentry.setContext('network', { network: process.env.STX_NETWORK });
 
export const routerConfig = [
  {
    path: routes.HOME,
    component: Home,
  },
  {
    path: routes.HOME_REQUEST_DIAGNOSTICS,
    component: Home,
  },
  {
    path: routes.TERMS,
    component: Terms,
  },
  {
    path: routes.REQUEST_DIAGNOSTICS,
    component: Diagnostics,
  },
  {
    path: routes.WELCOME,
    component: Welcome,
  },
  {
    path: routes.CREATE,
    component: CreateWallet,
  },
  {
    path: routes.RESTORE,
    component: RestoreWallet,
  },
  {
    path: routes.GENERATING,
    component: GeneratingSecret,
  },
  {
    path: routes.CONNECT_LEDGER,
    component: ConnectLedger,
  },
  {
    path: routes.SECRET_KEY,
    component: SecretKey,
  },
  {
    path: routes.VERIFY_KEY,
    component: VerifyKey,
  },
  {
    path: routes.SET_PASSWORD,
    component: SetPassword,
  },
  {
    path: routes.SETTINGS,
    component: Settings,
  },
  {
    path: routes.CHOOSE_STACKING_METHOD,
    component: ChooseStackingMethod,
  },
  {
    path: routes.DELEGATED_STACKING,
    component: StackingDelegation,
  },
  {
    path: routes.STACKING,
    component: DirectStacking,
  },
];
 
const getAppStartingRoute = (address?: string) => (address ? routes.HOME : routes.TERMS);
 
export function Routes() {
  // `useStore` required as we only want the value on initial render
  const store = useStore();
  const diagnosticPermission = useHasUserGivenDiagnosticPermissions();
  const [userDisabledDiagnosticsInCurrentSession, setUserDisabledDiagnosticsInCurrentSession] =
    useState(false);
 
  useEffect(() => {
    Iif (process.env.SENTRY_DSN && diagnosticPermission) {
      Sentry.init({
        dsn: process.env.SENTRY_DSN,
        beforeSend(event) {
          Iif (userDisabledDiagnosticsInCurrentSession) return null;
          return event;
        },
      });
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
 
  useEffect(() => {
    setUserDisabledDiagnosticsInCurrentSession(!diagnosticPermission);
  }, [diagnosticPermission]);
 
  const address = selectAddress(store.getState());
  return (
    <App>
      <Switch>
        {routerConfig.map((route, i) => (
          <Route key={i} exact {...route} />
        ))}
      </Switch>
      <Redirect to={getAppStartingRoute(address)} />
    </App>
  );
}