on 4c8c607 help sign in
164 lines 4.8 kB history raw
1import React, { useCallback } from 'react';
2import { Grid, B } from 'indigo-react';
3import { azimuth } from 'azimuth-js';
4import { Just } from 'folktale/maybe';
6import { ForwardButton } from 'components/Buttons';
7import CopyButton from 'components/CopyButton';
9import { useLocalRouter } from 'lib/LocalRouter';
10import { PROXY_TYPE, proxyTypeToHuman } from 'lib/proxy';
11import * as need from 'lib/need';
12import capitalize from 'lib/capitalize';
13import useCurrentPermissions from 'lib/useCurrentPermissions';
14import convertToInt from 'lib/convertToInt';
16import { usePointCursor } from 'store/pointCursor';
17import { usePointCache } from 'store/pointCache';
18import { useWallet } from 'store/wallet';
20export default function UrbitIDHome() {
21 const { push, names } = useLocalRouter();
22 const { pointCursor } = usePointCursor();
23 const { getDetails } = usePointCache();
24 const { urbitWallet } = useWallet();
26 const goSigil = useCallback(() => push(names.SIGIL_GENERATOR), [push, names]);
28 const goDownloadKeys = useCallback(() => push(names.DOWNLOAD_KEYS), [
29 push,
30 names,
31 ]);
33 const goResetKeys = useCallback(() => push(names.RESET_KEYS), [push, names]);
35 const isMasterTicket = Just.hasInstance(urbitWallet);
36 const point = need.point(pointCursor);
37 const details = need.details(getDetails(point));
38 const { isOwner } = useCurrentPermissions();
39 const networkRevision = convertToInt(details.keyRevisionNumber, 10);
41 const pointSize = azimuth.getPointSize(point);
42 const isParent = pointSize !== azimuth.PointSize.Planet;
43 const isSenate = pointSize === azimuth.PointSize.Galaxy;
45 const goSetProxy = useCallback(
46 proxyType => push(names.SET_PROXY, { proxyType }),
47 [push, names]
48 );
50 const goTransfer = useCallback(() => push(names.TRANSFER), [names, push]);
52 const renderProxyAction = useCallback(
53 (proxyType, address) => {
54 const disabled =
55 !isOwner ||
56 (proxyType === PROXY_TYPE.SPAWN ? networkRevision === 0 : false);
57 return (
58 <>
59 <Grid.Item
60 full
61 as={ForwardButton}
62 disabled={disabled}
63 onClick={() => goSetProxy(proxyType)}>
64 Edit {capitalize(proxyTypeToHuman(proxyType))} Key
65 </Grid.Item>
66 </>
67 );
68 },
69 [goSetProxy, isOwner, networkRevision]
70 );
71 return (
72 <Grid>
73 <Grid.Item full className="mb7 f5">
74 Urbit ID
75 </Grid.Item>
76 <Grid.Divider />
77 <Grid.Item full as={ForwardButton} onClick={goSigil}>
78 Sigil
79 </Grid.Item>
80 <Grid.Divider />
81 <Grid.Item
82 full
83 as={ForwardButton}
84 onClick={goDownloadKeys}
85 disabled={!isMasterTicket}
86 disabledDetail={
87 <B className="wrap ws-normal">
88 · Master Key Authentication required.
89 </B>
90 }>
91 Download Keys
92 </Grid.Item>
93 <Grid.Divider />
94 <Grid.Item
95 full
96 as={ForwardButton}
97 onClick={goResetKeys}
98 disabled={!isOwner}
99 disabledDetail={
100 <B className="wrap ws-normal"> · Ownership key required</B>
101 }
102 detail={
103 isMasterTicket
104 ? 'Reset Master Key and all other keys'
105 : 'Transfer to Master Ticket, resetting all keys'
106 }>
107 {isMasterTicket ? 'Reset Keys' : 'Transfer to Master Ticket'}
108 </Grid.Item>
110 <Grid.Divider />
112 <Grid.Item full className="mv7 f5 gray4">
113 Advanced
114 </Grid.Item>
115 <Grid.Divider />
116 <Grid.Item
117 full
118 as={ForwardButton}
119 accessory={<CopyButton text={details.owner} />}
120 detail={<div className="mt1 mono black">{details.owner}</div>}
121 disabled={!details.owner}>
122 Ownership Address
123 </Grid.Item>
124 <Grid.Divider />
126 {renderProxyAction(PROXY_TYPE.MANAGEMENT, details.managementProxy)}
127 <Grid.Divider />
129 {isParent && renderProxyAction(PROXY_TYPE.SPAWN, details.spawnProxy)}
131 {isParent && networkRevision !== 0 && <Grid.Divider />}
133 {isParent && networkRevision === 0 && (
134 <>
135 <Grid.Item
136 full
137 as={ForwardButton}
138 className="f6"
139 accessory={<span className="underline pointer">Set Keys</span>}>
140 Network Keys Required
141 </Grid.Item>
142 <Grid.Divider />
143 </>
144 )}
146 {isSenate && (
147 <>
148 {renderProxyAction(PROXY_TYPE.VOTING, details.votingProxy)}{' '}
149 <Grid.Divider />
150 </>
151 )}
152 <Grid.Item
153 full
154 as={ForwardButton}
155 onClick={goTransfer}
156 disabled={!isOwner}
157 disabledDetail={
158 <B className="wrap ws-normal"> · Ownership key required</B>
159 }>
160 Transfer this point
161 </Grid.Item>
162 </Grid>
163 );