on fd7895b help sign in
bridge/src/Bridge.js
99 lines 2.8 kB history raw
1import React from 'react';
2import { useEffect } from 'react';
3import { Just, Nothing } from 'folktale/maybe';
4import { IndigoApp } from 'indigo-react';
6import Router from 'components/Router';
8import Provider from 'store/Provider';
10import { ROUTE_NAMES } from 'lib/routeNames';
11import { ROUTES } from 'lib/router';
12import { NETWORK_TYPES } from 'lib/network';
13import { walletFromMnemonic } from 'lib/wallet';
14import { isDevelopment, isMainnet, isRopsten } from 'lib/flags';
15import useImpliedTicket from 'lib/useImpliedTicket';
16import useHasDisclaimed from 'lib/useHasDisclaimed';
18import 'style/index.scss';
19import WithErrorBoundary from 'components/WithErrorBoundary';
20import GlobalErrorBoundary from 'components/GlobalErrorBoundary';
22const INITIAL_NETWORK_TYPE = isRopsten
23 ? NETWORK_TYPES.ROPSTEN
24 : isDevelopment && !isMainnet
25 ? NETWORK_TYPES.LOCAL
26 : NETWORK_TYPES.MAINNET;
28// NB(shrugs): modify these variables to change the default local state.
29const SHOULD_STUB_LOCAL = process.env.REACT_APP_STUB_LOCAL === 'true';
30const IS_STUBBED = isDevelopment && SHOULD_STUB_LOCAL;
32const INITIAL_WALLET = IS_STUBBED
33 ? walletFromMnemonic(
34 process.env.REACT_APP_DEV_MNEMONIC,
35 process.env.REACT_APP_HD_PATH
36 )
37 : undefined;
38const INITIAL_MNEMONIC = IS_STUBBED
39 ? Just(process.env.REACT_APP_DEV_MNEMONIC)
40 : Nothing();
41const INITIAL_POINT_CURSOR = IS_STUBBED ? Just(65792) : Nothing();
43function useInitialRoutes() {
44 const [hasDisclaimed] = useHasDisclaimed();
45 const { impliedTicket } = useImpliedTicket();
47 const isActivateUrl = window.location.pathname === '/activate';
49 if (IS_STUBBED) {
50 return [
51 { key: ROUTE_NAMES.LOGIN },
52 // { key: ROUTE_NAMES.POINTS },
53 // { key: ROUTE_NAMES.POINT },
54 ];
55 }
57 if (impliedTicket || isActivateUrl) {
58 return [{ key: ROUTE_NAMES.ACTIVATE }];
59 }
61 if (!hasDisclaimed) {
62 return [{ key: ROUTE_NAMES.DISCLAIMER, data: { next: ROUTE_NAMES.LOGIN } }];
63 }
65 return [{ key: ROUTE_NAMES.LOGIN }];
68function Bridge() {
69 const initialRoutes = useInitialRoutes();
71 // full reload if the user changes their selected network in Metamask
72 //
73 useEffect(() => {
74 if (window.ethereum) {
75 window.ethereum.on('chainChanged', () => {
76 document.location.reload();
77 });
78 }
79 }, []);
81 return (
82 <WithErrorBoundary render={error => <GlobalErrorBoundary error={error} />}>
83 <Provider
84 views={ROUTES}
85 names={ROUTE_NAMES}
86 initialRoutes={initialRoutes}
87 initialNetworkType={INITIAL_NETWORK_TYPE}
88 initialWallet={INITIAL_WALLET}
89 initialMnemonic={INITIAL_MNEMONIC}
90 initialPointCursor={INITIAL_POINT_CURSOR}>
91 <IndigoApp>
92 <Router />
93 </IndigoApp>
94 </Provider>
95 </WithErrorBoundary>
96 );
99export default Bridge;