on c19b2a8 help sign in
bridge/src/views/Admin/AdminEditPermissions.js
130 lines 3.8 kB history raw
1import React, { useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, LinkButton } from 'indigo-react';
4import { azimuth } from 'azimuth-js';
6import { useNetwork } from 'store/network';
7import { usePointCursor } from 'store/pointCursor';
8import { usePointCache } from 'store/pointCache';
10import * as need from 'lib/need';
11import { isZeroAddress } from 'lib/wallet';
12import { PROXY_TYPE, proxyTypeToHuman } from 'lib/proxy';
13import { useLocalRouter } from 'lib/LocalRouter';
14import capitalize from 'lib/capitalize';
15import { eqAddr } from 'lib/wallet';
16import useCurrentPermissions from 'lib/useCurrentPermissions';
18import ViewHeader from 'components/ViewHeader';
19import { ForwardButton } from 'components/Buttons';
20import { matchBlinkyDate } from 'components/Blinky';
21import CopyButton from 'components/CopyButton';
22import convertToInt from 'lib/convertToInt';
24export default function AdminEditPermissions() {
25 const { push, names } = useLocalRouter();
26 const { contracts } = useNetwork();
27 const { pointCursor } = usePointCursor();
28 const { getDetails, getRekeyDate } = usePointCache();
30 const _contracts = need.contracts(contracts);
32 const point = need.point(pointCursor);
33 const pointSize = azimuth.getPointSize(point);
34 const isParent = pointSize !== azimuth.PointSize.Planet;
35 const isSenate = pointSize === azimuth.PointSize.Galaxy;
37 const details = need.details(getDetails(point));
38 const networkRevision = convertToInt(details.keyRevisionNumber, 10);
39 const { canManage, isOwner } = useCurrentPermissions();
41 const goSetProxy = useCallback(
42 proxyType => push(names.SET_PROXY, { proxyType }),
43 [push, names]
44 );
46 const goNetworkingKeys = useCallback(() => push(names.NETWORKING_KEYS), [
47 push,
48 names,
49 ]);
51 const renderProxyAction = (proxyType, address) => {
52 if (isZeroAddress(address)) {
53 address = 'Not set';
54 } else if (eqAddr(address, _contracts.delegatedSending.address)) {
55 address = `${address} (invites contract)`;
56 }
58 return (
59 <>
60 <Grid.Item
61 full
62 as={ForwardButton}
63 disabled={!isOwner}
64 onClick={() => goSetProxy(proxyType)}
65 detail={address}
66 detailClassName="mono"
67 accessory={<LinkButton>Edit</LinkButton>}>
68 {capitalize(proxyTypeToHuman(proxyType))} Proxy Address
69 </Grid.Item>
70 <Grid.Divider />
71 </>
72 );
73 };
75 const renderNetworkKeysDetail = () => {
76 if (networkRevision === 0) {
77 return 'Not yet configured.';
78 }
80 const renderRevision = maybeDate => (
81 <>
82 Revision #{networkRevision}, since {matchBlinkyDate(maybeDate)}
83 </>
84 );
86 return getRekeyDate(point).matchWith({
87 Nothing: () => renderRevision(Nothing()),
88 Just: p =>
89 p.value.matchWith({
90 Ok: r => renderRevision(Just(r.value)),
91 Error: 'Unknown',
92 }),
93 });
94 };
96 return (
97 <Grid>
98 <Grid.Item full as={ViewHeader}>
99 Permissions
100 </Grid.Item>
102 <Grid.Item
103 full
104 as={ForwardButton}
105 detail={details.owner}
106 detailClassName="mono"
107 accessory={<CopyButton text={details.owner} />}>
108 Ownership Address
109 </Grid.Item>
110 <Grid.Divider />
112 {renderProxyAction(PROXY_TYPE.MANAGEMENT, details.managementProxy)}
114 {isParent && renderProxyAction(PROXY_TYPE.SPAWN, details.spawnProxy)}
116 {isSenate && renderProxyAction(PROXY_TYPE.VOTING, details.votingProxy)}
118 <Grid.Item
119 full
120 as={ForwardButton}
121 disabled={!canManage}
122 onClick={goNetworkingKeys}
123 detail={renderNetworkKeysDetail()}
124 accessory={<LinkButton>View</LinkButton>}>
125 Networking Keys
126 </Grid.Item>
127 <Grid.Divider />
128 </Grid>
129 );