@@ -1,16 +1,13 @@
1import React, { useState, useCallback } from 'react';
1import React, { useState, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
2import { Just, Nothing } from 'folktale/maybe';
3import * as need from 'lib/need';
3import * as need from 'lib/need';
4−import { azimuth } from 'azimuth-js';
5import { Grid } from 'indigo-react';
4import { Grid } from 'indigo-react';
7−import View from 'components/View';
8import { ForwardButton } from 'components/Buttons';
6import { ForwardButton } from 'components/Buttons';
9−import FooterButton from 'components/FooterButton';
10import { matchBlinky } from 'components/Blinky';
7import { matchBlinky } from 'components/Blinky';
12import { ROUTE_NAMES } from 'lib/routeNames';
9import { ROUTE_NAMES } from 'lib/routeNames';
13−import { eqAddr } from 'lib/wallet';
10+import { ETH_ZERO_ADDR } from 'lib/wallet';
15import useLifecycle from 'lib/useLifecycle';
12import useLifecycle from 'lib/useLifecycle';
16import { useNetwork } from 'store/network';
13import { useNetwork } from 'store/network';
@@ -18,6 +15,8 @@ import { useHistory } from 'store/history';
18import { useWallet } from 'store/wallet';
15import { useWallet } from 'store/wallet';
19import { usePointCursor } from 'store/pointCursor';
16import { usePointCursor } from 'store/pointCursor';
20import { usePointCache } from 'store/pointCache';
17import { usePointCache } from 'store/pointCache';
18+import ViewHeader from 'components/ViewHeader';
19+import usePermissionsForPoint from 'lib/usePermissionsForPoint';
22//TODO consolidate with azimuth-js' getActivationBlock
21//TODO consolidate with azimuth-js' getActivationBlock
23const getRekeyDate = async (web3, contracts, point) => {
22const getRekeyDate = async (web3, contracts, point) => {
@@ -35,19 +34,24 @@ const getRekeyDate = async (web3, contracts, point) => {
38−export default function Permissions() {
37+export default function AdminEditPermissions() {
39 const history = useHistory();
38 const history = useHistory();
40 const { web3, contracts } = useNetwork();
39 const { web3, contracts } = useNetwork();
41 const { wallet } = useWallet();
40 const { wallet } = useWallet();
42 const { pointCursor } = usePointCursor();
41 const { pointCursor } = usePointCursor();
43− const { pointCache } = usePointCache();
42+ const { getDetails } = usePointCache();
45 const [rekeyDate, setRekeyDate] = useState(Nothing());
44 const [rekeyDate, setRekeyDate] = useState(Nothing());
47 const point = need.point(pointCursor);
46 const point = need.point(pointCursor);
48− const pointSize = azimuth.getPointSize(point);
49 const userAddress = need.wallet(wallet).address;
47 const userAddress = need.wallet(wallet).address;
49+ const pointDetails = need.details(getDetails(point));
50+ const { isOwner, canManage, canSpawn, canVote } = usePermissionsForPoint(
51 useLifecycle(() => {
55 useLifecycle(() => {
52 getRekeyDate(need.web3(web3), need.contracts(contracts), point).then(
56 getRekeyDate(need.web3(web3), need.contracts(contracts), point).then(
@@ -76,43 +80,21 @@ export default function Permissions() {
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) => {
83 const proxyAction = (name, address, onClick) => {
86− if (address === '0x0000000000000000000000000000000000000000')
84+ if (address === ETH_ZERO_ADDR) {
87− address = 'Unset';
85+ address = 'Not yet set';
89 <Grid.Item full>
89 <Grid.Item full>
90 <ForwardButton disabled={!isOwner} onClick={onClick} detail={address}>
90 <ForwardButton disabled={!isOwner} onClick={onClick} detail={address}>
91− {`${name} proxy address`}
91+ {`${name} Proxy Address`}
92 </ForwardButton>
92 </ForwardButton>
93 </Grid.Item>
93 </Grid.Item>
97− let spawnProxyAction = null;
97+ const networkKeysDetail =
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 ? (
98 pointDetails.keyRevisionNumber === 0 ? (
117 'Not yet configured'
99 'Not yet configured'
@@ -123,31 +105,39 @@ export default function Permissions() {
127− <Grid className="pt2">
109+ <Grid.Item full as={ViewHeader}>
128− <Grid.Item full as={ForwardButton} disabled detail={pointDetails.owner}>
112+ <Grid.Item full as={ForwardButton} detail={pointDetails.owner} disabled>
129− Ownership address
113+ Ownership Address
130− </Grid.Item>
114+ </Grid.Item>
131− {proxyAction(
115+ <Grid.Divider />
133− pointDetails.managementProxy,
116+ {proxyAction('Management', pointDetails.managementProxy, goSetManagement)}
134− goSetManagement
117+ <Grid.Divider />
136− {spawnProxyAction}
119+ {canSpawn && (
137− {votingProxyAction}
120+ <>
121+ {proxyAction('Spawn', pointDetails.spawnProxy, goSetSpawn)}
128+ {proxyAction('Voting', pointDetails.votingProxy, goSetVoting)}
138− <Grid.Item
132+ <Grid.Item
140− as={ForwardButton}
134+ as={ForwardButton}
141− disabled={!canManage}
135+ disabled={!canManage}
142− onClick={goSetKeys}
136+ onClick={goSetKeys}
143− detail={netKeysText}>
137+ detail={networkKeysDetail}>
144− Network keys
138+ Network keys
145− </Grid.Item>
139+ </Grid.Item>
146− </Grid>
140+ <Grid.Divider />
148− <FooterButton detail="Transfer this identity to a new owner" disabled>