on 48be87c help sign in
bridge/src/Bridge.js
106 lines 3.1 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';
21import Modal from 'components/L2/Modal';
22import { useRollerStore } from 'store/rollerStore';
23import { Box } from '@tlon/indigo-react';
25const INITIAL_NETWORK_TYPE = isRopsten
26 ? NETWORK_TYPES.ROPSTEN
27 : isDevelopment && !isMainnet
28 ? NETWORK_TYPES.LOCAL
29 : NETWORK_TYPES.MAINNET;
31// NB(shrugs): modify these variables to change the default local state.
32const SHOULD_STUB_LOCAL = process.env.REACT_APP_STUB_LOCAL === 'true';
33const IS_STUBBED = isDevelopment && SHOULD_STUB_LOCAL;
35const INITIAL_WALLET = IS_STUBBED
36 ? walletFromMnemonic(
37 process.env.REACT_APP_DEV_MNEMONIC,
38 process.env.REACT_APP_HD_PATH
39 )
40 : undefined;
41const INITIAL_MNEMONIC = IS_STUBBED
42 ? Just(process.env.REACT_APP_DEV_MNEMONIC)
43 : Nothing();
44const INITIAL_POINT_CURSOR = IS_STUBBED ? Just(65792) : Nothing();
46function useInitialRoutes() {
47 const [hasDisclaimed] = useHasDisclaimed();
48 const { impliedTicket } = useImpliedTicket();
50 const isActivateUrl = window.location.pathname === '/activate';
52 if (IS_STUBBED) {
53 return [
54 { key: ROUTE_NAMES.LOGIN },
55 // { key: ROUTE_NAMES.POINTS },
56 // { key: ROUTE_NAMES.POINT },
57 ];
58 }
60 if (impliedTicket || isActivateUrl) {
61 return [{ key: ROUTE_NAMES.ACTIVATE }];
62 }
64 if (!hasDisclaimed) {
65 return [{ key: ROUTE_NAMES.DISCLAIMER, data: { next: ROUTE_NAMES.LOGIN } }];
66 }
68 return [{ key: ROUTE_NAMES.LOGIN }];
71function Bridge() {
72 const initialRoutes = useInitialRoutes();
73 const { modalText, setModalText } = useRollerStore();
75 // full reload if the user changes their selected network in Metamask
76 //
77 useEffect(() => {
78 if (window.ethereum) {
79 window.ethereum.on('chainChanged', () => {
80 document.location.reload();
81 });
82 }
83 }, []);
85 return (
86 <WithErrorBoundary render={error => <GlobalErrorBoundary error={error} />}>
87 <Provider
88 views={ROUTES}
89 names={ROUTE_NAMES}
90 initialRoutes={initialRoutes}
91 initialNetworkType={INITIAL_NETWORK_TYPE}
92 initialWallet={INITIAL_WALLET}
93 initialMnemonic={INITIAL_MNEMONIC}
94 initialPointCursor={INITIAL_POINT_CURSOR}>
95 <IndigoApp>
96 <Router />
97 </IndigoApp>
98 <Modal show={modalText !== undefined} hide={() => setModalText()}>
99 <Box width="280px">{modalText}</Box>
100 </Modal>
101 </Provider>
102 </WithErrorBoundary>
103 );
106export default Bridge;