1import React, { useState, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as need from 'lib/need';
4import { azimuth } from 'azimuth-js';
5import { Grid } from 'indigo-react';
7import View from 'components/View';
8import { ForwardButton } from 'components/Buttons';
9import FooterButton from 'components/FooterButton';
10import { matchBlinky } from 'components/Blinky';
12import { ROUTE_NAMES } from 'lib/routeNames';
13import { eqAddr } from 'lib/wallet';
15import useLifecycle from 'lib/useLifecycle';
16import { useNetwork } from 'store/network';
17import { useHistory } from 'store/history';
18import { useWallet } from 'store/wallet';
19import { usePointCursor } from 'store/pointCursor';
20import { usePointCache } from 'store/pointCache';
22//TODO consolidate with azimuth-js' getActivationBlock
23const getRekeyDate = async (web3, contracts, point) => {
24 const logs = await contracts.azimuth.getPastEvents('ChangedKeys', {
27 filter: { point: [point] },
29 if (logs.length === 0) {
32 // last log is most recent
33 const block = await web3.eth.getBlock(logs[logs.length - 1].blockNumber);
34 return new Date(block.timestamp * 1000);
38export default function Permissions() {
39 const history = useHistory();
40 const { web3, contracts } = useNetwork();
41 const { wallet } = useWallet();
42 const { pointCursor } = usePointCursor();
43 const { pointCache } = usePointCache();
45 const [rekeyDate, setRekeyDate] = useState(Nothing());
47 const point = need.point(pointCursor);
48 const pointSize = azimuth.getPointSize(point);
49 const userAddress = need.wallet(wallet).address;
52 getRekeyDate(need.web3(web3), need.contracts(contracts), point).then(
54 if (res === null) setRekeyDate(Just('unknown'));
55 else setRekeyDate(Just(res.toString()));
60 const goSetManagement = useCallback(
61 () => history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY),
65 const goSetSpawn = useCallback(
66 () => history.push(ROUTE_NAMES.SET_SPAWN_PROXY),
70 const goSetVoting = useCallback(
71 () => history.push(ROUTE_NAMES.SET_VOTING_PROXY),
75 const goSetKeys = useCallback(() => history.push(ROUTE_NAMES.SET_KEYS), [
79 const pointDetails = need.fromPointCache(pointCache, point);
81 const isOwner = eqAddr(userAddress, pointDetails.owner);
83 isOwner || eqAddr(userAddress, pointDetails.managementProxy);
85 const proxyAction = (name, address, onClick) => {
86 if (address === '0x0000000000000000000000000000000000000000')
90 <ForwardButton disabled={!isOwner} onClick={onClick} detail={address}>
91 {`${name} proxy address`}
97 let spawnProxyAction = null;
98 if (pointSize !== azimuth.PointSize.Planet) {
99 spawnProxyAction = proxyAction(
101 pointDetails.spawnProxy,
106 let votingProxyAction = null;
107 if (pointSize === azimuth.PointSize.Galaxy) {
108 votingProxyAction = proxyAction(
110 pointDetails.votingProxy,
116 pointDetails.keyRevisionNumber === 0 ? (
120 {`Revision #${pointDetails.keyRevisionNumber}, since `}
121 {matchBlinky(rekeyDate)}
127 <Grid className="pt2">
128 <Grid.Item full as={ForwardButton} disabled detail={pointDetails.owner}>
133 pointDetails.managementProxy,
141 disabled={!canManage}
143 detail={netKeysText}>
148 <FooterButton detail="Transfer this identity to a new owner" disabled>
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