1import React, { useState, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as need from 'lib/need';
4import { Grid } from 'indigo-react';
6import { ForwardButton } from 'components/Buttons';
7import { matchBlinky } from 'components/Blinky';
9import { ROUTE_NAMES } from 'lib/routeNames';
10import { ETH_ZERO_ADDR } from 'lib/wallet';
12import useLifecycle from 'lib/useLifecycle';
13import { useNetwork } from 'store/network';
14import { useHistory } from 'store/history';
15import { useWallet } from 'store/wallet';
16import { usePointCursor } from 'store/pointCursor';
17import { usePointCache } from 'store/pointCache';
18import ViewHeader from 'components/ViewHeader';
19import usePermissionsForPoint from 'lib/usePermissionsForPoint';
21//TODO consolidate with azimuth-js' getActivationBlock
22const getRekeyDate = async (web3, contracts, point) => {
23 const logs = await contracts.azimuth.getPastEvents('ChangedKeys', {
26 filter: { point: [point] },
28 if (logs.length === 0) {
31 // last log is most recent
32 const block = await web3.eth.getBlock(logs[logs.length - 1].blockNumber);
33 return new Date(block.timestamp * 1000);
37export default function AdminEditPermissions() {
38 const history = useHistory();
39 const { web3, contracts } = useNetwork();
40 const { wallet } = useWallet();
41 const { pointCursor } = usePointCursor();
42 const { getDetails } = usePointCache();
44 const [rekeyDate, setRekeyDate] = useState(Nothing());
46 const point = need.point(pointCursor);
47 const userAddress = need.wallet(wallet).address;
49 const pointDetails = need.details(getDetails(point));
50 const { isOwner, canManage, canSpawn, canVote } = usePermissionsForPoint(
56 getRekeyDate(need.web3(web3), need.contracts(contracts), point).then(
58 if (res === null) setRekeyDate(Just('unknown'));
59 else setRekeyDate(Just(res.toString()));
64 const goSetManagement = useCallback(
65 () => history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY),
69 const goSetSpawn = useCallback(
70 () => history.push(ROUTE_NAMES.SET_SPAWN_PROXY),
74 const goSetVoting = useCallback(
75 () => history.push(ROUTE_NAMES.SET_VOTING_PROXY),
79 const goSetKeys = useCallback(() => history.push(ROUTE_NAMES.SET_KEYS), [
83 const proxyAction = (name, address, onClick) => {
84 if (address === ETH_ZERO_ADDR) {
85 address = 'Not yet set';
90 <ForwardButton disabled={!isOwner} onClick={onClick} detail={address}>
91 {`${name} Proxy Address`}
97 const networkKeysDetail =
98 pointDetails.keyRevisionNumber === 0 ? (
102 {`Revision #${pointDetails.keyRevisionNumber}, since `}
103 {matchBlinky(rekeyDate)}
109 <Grid.Item full as={ViewHeader}>
112 <Grid.Item full as={ForwardButton} detail={pointDetails.owner} disabled>
116 {proxyAction('Management', pointDetails.managementProxy, goSetManagement)}
121 {proxyAction('Spawn', pointDetails.spawnProxy, goSetSpawn)}
128 {proxyAction('Voting', pointDetails.votingProxy, goSetVoting)}
135 disabled={!canManage}
137 detail={networkKeysDetail}>
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list