on 4c8c607 help sign in
bridge/src/views/UrbitID.js
88 lines 2.3 kB history raw
1import React from 'react';
2import { Grid } from 'indigo-react';
4import { useHistory } from 'store/history';
6import useCurrentPointName from 'lib/useCurrentPointName';
7import useRouter from 'lib/useRouter';
8import { LocalRouterProvider } from 'lib/LocalRouter';
10import View from 'components/View';
11import Crumbs from 'components/Crumbs';
12import NavHeader from 'components/NavHeader';
14import UrbitIDHome from './UrbitID/Home';
15import SigilGenerator from './UrbitID/SigilGenerator';
16import DownloadKeys from './UrbitID/DownloadKeys';
17import SetProxy from './UrbitID/SetProxy';
18import ResetKeys from './UrbitID/ResetKeys';
19import Transfer from './UrbitID/Transfer';
21const NAMES = {
22 HOME: 'HOME',
23 SIGIL_GENERATOR: 'SIGIL_GENERATOR',
24 DOWNLOAD_KEYS: 'DOWNLOAD_KEYS',
25 SET_PROXY: 'SET_PROXY',
26 RESET_KEYS: 'RESET_KEYS',
27 TRANSFER: 'TRANSFER',
28};
30const VIEWS = {
31 [NAMES.HOME]: UrbitIDHome,
32 [NAMES.SIGIL_GENERATOR]: SigilGenerator,
33 [NAMES.DOWNLOAD_KEYS]: DownloadKeys,
34 [NAMES.RESET_KEYS]: ResetKeys,
35 [NAMES.SET_PROXY]: SetProxy,
36 [NAMES.TRANSFER]: Transfer,
37};
39const humanizeName = name => {
40 switch (name) {
41 case NAMES.SIGIL_GENERATOR:
42 return 'Sigil';
43 case NAMES.DOWNLOAD_KEYS:
44 return 'Download Keys';
45 case NAMES.SET_PROXY:
46 return 'Set Key';
47 case NAMES.RESET_KEYS:
48 return 'Reset Keys';
49 case NAMES.TRANSFER:
50 return 'Transfer';
51 default:
52 return undefined;
53 }
54};
56export default function UrbitID() {
57 const history = useHistory();
58 const name = useCurrentPointName();
60 const { Route, ...router } = useRouter({
61 names: NAMES,
62 views: VIEWS,
63 initialRoutes: [{ key: NAMES.HOME }],
64 });
66 const last = router.peek().key;
67 const homeAction = last === NAMES.HOME ? undefined : () => history.pop();
68 const lastCrumb = homeAction ? [{ text: humanizeName(last) }] : [];
70 return (
71 <View pop={router.pop} inset>
72 <NavHeader>
73 <Crumbs
74 routes={[
75 { text: name, action: () => history.pop() },
76 { text: 'Urbit ID', action: homeAction },
77 ...lastCrumb,
78 ]}
79 />
80 </NavHeader>
82 <LocalRouterProvider value={router}>
83 <Grid className="mb4"></Grid>
84 <Route />
85 </LocalRouterProvider>
86 </View>
87 );