@@ -1,16 +1,13 @@
11import React, { useState, useCallback } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import * as need from 'lib/need';
4−import { azimuth } from 'azimuth-js';
54import { Grid } from 'indigo-react';
65
7−import View from 'components/View';
86import { ForwardButton } from 'components/Buttons';
9−import FooterButton from 'components/FooterButton';
107import { matchBlinky } from 'components/Blinky';
118
129import { ROUTE_NAMES } from 'lib/routeNames';
13−import { eqAddr } from 'lib/wallet';
10+import { ETH_ZERO_ADDR } from 'lib/wallet';
1411
1512import useLifecycle from 'lib/useLifecycle';
1613import { useNetwork } from 'store/network';
@@ -18,6 +15,8 @@ import { useHistory } from 'store/history';
1815import { useWallet } from 'store/wallet';
1916import { usePointCursor } from 'store/pointCursor';
2017import { usePointCache } from 'store/pointCache';
18+import ViewHeader from 'components/ViewHeader';
19+import usePermissionsForPoint from 'lib/usePermissionsForPoint';
2120
2221//TODO consolidate with azimuth-js' getActivationBlock
2322const getRekeyDate = async (web3, contracts, point) => {
@@ -35,19 +34,24 @@ const getRekeyDate = async (web3, contracts, point) => {
3534 }
3635};
3736
38−export default function Permissions() {
37+export default function AdminEditPermissions() {
3938 const history = useHistory();
4039 const { web3, contracts } = useNetwork();
4140 const { wallet } = useWallet();
4241 const { pointCursor } = usePointCursor();
43− const { pointCache } = usePointCache();
42+ const { getDetails } = usePointCache();
4443
4544 const [rekeyDate, setRekeyDate] = useState(Nothing());
4645
4746 const point = need.point(pointCursor);
48− const pointSize = azimuth.getPointSize(point);
4947 const userAddress = need.wallet(wallet).address;
5048
49+ const pointDetails = need.details(getDetails(point));
50+ const { isOwner, canManage, canSpawn, canVote } = usePermissionsForPoint(
51+ userAddress,
52+ point
53+ );
54+
5155 useLifecycle(() => {
5256 getRekeyDate(need.web3(web3), need.contracts(contracts), point).then(
5357 res => {
@@ -76,43 +80,21 @@ export default function Permissions() {
7680 history,
7781 ]);
7882
79− const pointDetails = need.fromPointCache(pointCache, point);
80−
81− const isOwner = eqAddr(userAddress, pointDetails.owner);
82− const canManage =
83− isOwner || eqAddr(userAddress, pointDetails.managementProxy);
84−
8583 const proxyAction = (name, address, onClick) => {
86− if (address === '0x0000000000000000000000000000000000000000')
87− address = 'Unset';
84+ if (address === ETH_ZERO_ADDR) {
85+ address = 'Not yet set';
86+ }
87+
8888 return (
8989 <Grid.Item full>
9090 <ForwardButton disabled={!isOwner} onClick={onClick} detail={address}>
91− {`${name} proxy address`}
91+ {`${name} Proxy Address`}
9292 </ForwardButton>
9393 </Grid.Item>
9494 );
9595 };
9696
97− let spawnProxyAction = null;
98− if (pointSize !== azimuth.PointSize.Planet) {
99− spawnProxyAction = proxyAction(
100− 'Spawn',
101− pointDetails.spawnProxy,
102− goSetSpawn
103− );
104− }
105−
106− let votingProxyAction = null;
107− if (pointSize === azimuth.PointSize.Galaxy) {
108− votingProxyAction = proxyAction(
109− 'Voting',
110− pointDetails.votingProxy,
111− goSetVoting
112− );
113− }
114−
115− const netKeysText =
97+ const networkKeysDetail =
11698 pointDetails.keyRevisionNumber === 0 ? (
11799 'Not yet configured'
118100 ) : (
@@ -123,31 +105,39 @@ export default function Permissions() {
123105 );
124106
125107 return (
126− <View>
127− <Grid className="pt2">
128− <Grid.Item full as={ForwardButton} disabled detail={pointDetails.owner}>
129− Ownership address
130− </Grid.Item>
131− {proxyAction(
132− 'Management',
133− pointDetails.managementProxy,
134− goSetManagement
135− )}
136− {spawnProxyAction}
137− {votingProxyAction}
138− <Grid.Item
139− full
140− as={ForwardButton}
141− disabled={!canManage}
142− onClick={goSetKeys}
143− detail={netKeysText}>
144− Network keys
145− </Grid.Item>
146− </Grid>
147−
148− <FooterButton detail="Transfer this identity to a new owner" disabled>
149− Transfer
150− </FooterButton>
151− </View>
108+ <Grid>
109+ <Grid.Item full as={ViewHeader}>
110+ Permissions
111+ </Grid.Item>
112+ <Grid.Item full as={ForwardButton} detail={pointDetails.owner} disabled>
113+ Ownership Address
114+ </Grid.Item>
115+ <Grid.Divider />
116+ {proxyAction('Management', pointDetails.managementProxy, goSetManagement)}
117+ <Grid.Divider />
118+
119+ {canSpawn && (
120+ <>
121+ {proxyAction('Spawn', pointDetails.spawnProxy, goSetSpawn)}
122+ <Grid.Divider />
123+ </>
124+ )}
125+
126+ {canVote && (
127+ <>
128+ {proxyAction('Voting', pointDetails.votingProxy, goSetVoting)}
129+ <Grid.Divider />
130+ </>
131+ )}
132+ <Grid.Item
133+ full
134+ as={ForwardButton}
135+ disabled={!canManage}
136+ onClick={goSetKeys}
137+ detail={networkKeysDetail}>
138+ Network keys
139+ </Grid.Item>
140+ <Grid.Divider />
141+ </Grid>
152142 );
153143}