@@ -5,7 +5,7 @@ import { Grid } from 'indigo-react';
55import { azimuth } from 'azimuth-js';
66
77import { ForwardButton } from 'components/Buttons';
8−import { matchBlinky, matchBlinkyDate } from 'components/Blinky';
8+import { matchBlinkyDate } from 'components/Blinky';
99
1010import { ETH_ZERO_ADDR } from 'lib/wallet';
1111
@@ -18,38 +18,20 @@ import ViewHeader from 'components/ViewHeader';
1818import usePermissionsForPoint from 'lib/usePermissionsForPoint';
1919import { PROXY_TYPE, proxyTypeToHuman } from 'lib/proxy';
2020import { useLocalRouter } from 'lib/LocalRouter';
21−import { formatDots } from 'lib/dateFormat';
2221import capitalize from 'lib/capitalize';
2322import { eqAddr } from 'lib/wallet';
24−
25−//TODO consolidate with azimuth-js' getActivationBlock
26−const getRekeyDate = async (web3, contracts, point) => {
27− const logs = await contracts.azimuth.getPastEvents('ChangedKeys', {
28− fromBlock: 0,
29− toBlock: 'latest',
30− filter: { point: [point] },
31− });
32− if (logs.length === 0) {
33− return null;
34− } else {
35− // last log is most recent
36− const block = await web3.eth.getBlock(logs[logs.length - 1].blockNumber);
37− return new Date(block.timestamp * 1000);
38− }
39−};
23+import MiniBackButton from 'components/MiniBackButton';
24+import FooterButton from 'components/FooterButton';
4025
4126export default function AdminEditPermissions() {
42− const { push, names } = useLocalRouter();
43− const { web3, contracts } = useNetwork();
27+ const { pop, push, names } = useLocalRouter();
28+ const { contracts } = useNetwork();
4429 const { wallet } = useWallet();
4530 const { pointCursor } = usePointCursor();
46− const { getDetails } = usePointCache();
31+ const { getDetails, getRekeyDate } = usePointCache();
4732
48− const _web3 = need.web3(web3);
4933 const _contracts = need.contracts(contracts);
5034
51− const [rekeyDate, setRekeyDate] = useState(Nothing());
52−
5335 const point = need.point(pointCursor);
5436 const pointSize = azimuth.getPointSize(point);
5537 const isParent = pointSize !== azimuth.PointSize.Planet;
@@ -57,42 +39,33 @@ export default function AdminEditPermissions() {
5739 const userAddress = need.wallet(wallet).address;
5840
5941 const details = need.details(getDetails(point));
42+ const networkRevision = parseInt(details.keyRevisionNumber, 10);
6043 const { canManage, isOwner } = usePermissionsForPoint(userAddress, point);
6144
62− useLifecycle(() => {
63− getRekeyDate(_web3, _contracts, point).then(res => {
64− if (res === null) setRekeyDate(Just(new Date()));
65− else setRekeyDate(Just(res));
66− });
67− });
68−
69− const goToProxy = useCallback(
45+ const goSetProxy = useCallback(
7046 proxyType => push(names.SET_PROXY, { proxyType }),
7147 [push, names]
7248 );
7349
74− const goSetKeys = useCallback(() => push(names.SET_KEYS), [push, names]);
50+ const goNetworkingKeys = useCallback(() => push(names.NETWORKING_KEYS), [
51+ push,
52+ names,
53+ ]);
7554
76− const proxyAction = (proxyType, address, enabled) => {
55+ const renderProxyAction = (proxyType, address) => {
7756 if (eqAddr(address, ETH_ZERO_ADDR)) {
7857 address = 'Not set';
7958 } else if (eqAddr(address, _contracts.delegatedSending.address)) {
80− address = address + ' (invites contract)';
59+ address = `${address} (invites contract)`;
8160 }
8261
83− const detail = enabled
84− ? address
85− : `You do not have permission to change the ${proxyTypeToHuman(
86− proxyType
87− )} proxy.`;
88−
8962 return (
9063 <>
9164 <Grid.Item full>
9265 <ForwardButton
93− disabled={!enabled}
94− onClick={() => goToProxy(proxyType)}
95− detail={detail}>
66+ disabled={!isOwner}
67+ onClick={() => goSetProxy(proxyType)}
68+ detail={address}>
9669 {capitalize(proxyTypeToHuman(proxyType))} Proxy Address
9770 </ForwardButton>
9871 </Grid.Item>
@@ -101,18 +74,30 @@ export default function AdminEditPermissions() {
10174 );
10275 };
10376
104− const networkKeysDetail =
105− details.keyRevisionNumber === 0 ? (
106− 'Not yet configured'
107− ) : (
77+ const renderNetworkKeysDetail = () => {
78+ if (networkRevision === 0) {
79+ return 'Not yet configured.';
80+ }
81+
82+ const renderRevision = maybeDate => (
10883 <>
109− Revision #{details.keyRevisionNumber}, since{' '}
110− {matchBlinkyDate(rekeyDate)}
84+ Revision #{networkRevision}, since {matchBlinkyDate(maybeDate)}
11185 </>
11286 );
11387
88+ return getRekeyDate(point).matchWith({
89+ Nothing: () => renderRevision(Nothing()),
90+ Just: p =>
91+ p.value.matchWith({
92+ Ok: r => renderRevision(Just(r.value)),
93+ Error: 'Unknown',
94+ }),
95+ });
96+ };
97+
11498 return (
11599 <Grid>
100+ <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
116101 <Grid.Item full as={ViewHeader}>
117102 Permissions
118103 </Grid.Item>
@@ -122,19 +107,19 @@ export default function AdminEditPermissions() {
122107 </Grid.Item>
123108 <Grid.Divider />
124109
125− {proxyAction(PROXY_TYPE.MANAGEMENT, details.managementProxy, isOwner)}
110+ {renderProxyAction(PROXY_TYPE.MANAGEMENT, details.managementProxy)}
126111
127− {isParent && proxyAction(PROXY_TYPE.SPAWN, details.spawnProxy, isOwner)}
112+ {isParent && renderProxyAction(PROXY_TYPE.SPAWN, details.spawnProxy)}
128113
129− {isSenate && proxyAction(PROXY_TYPE.VOTING, details.votingProxy, isOwner)}
114+ {isSenate && renderProxyAction(PROXY_TYPE.VOTING, details.votingProxy)}
130115
131116 <Grid.Item
132117 full
133118 as={ForwardButton}
134119 disabled={!canManage}
135− onClick={goSetKeys}
136− detail={networkKeysDetail}>
137− Network Keys
120+ onClick={goNetworkingKeys}
121+ detail={renderNetworkKeysDetail()}>
122+ Networking Keys
138123 </Grid.Item>
139124 <Grid.Divider />
140125 </Grid>