@@ -4,19 +4,21 @@ import * as need from 'lib/need';
44import { Grid } from 'indigo-react';
55
66import { ForwardButton } from 'components/Buttons';
7−import { matchBlinky } from 'components/Blinky';
7+import { matchBlinky, matchBlinkyDate } from 'components/Blinky';
88
9−import { ROUTE_NAMES } from 'lib/routeNames';
109import { ETH_ZERO_ADDR } from 'lib/wallet';
1110
1211import useLifecycle from 'lib/useLifecycle';
1312import { useNetwork } from 'store/network';
14−import { useHistory } from 'store/history';
1513import { useWallet } from 'store/wallet';
1614import { usePointCursor } from 'store/pointCursor';
1715import { usePointCache } from 'store/pointCache';
1816import ViewHeader from 'components/ViewHeader';
1917import usePermissionsForPoint from 'lib/usePermissionsForPoint';
18+import { PROXY_TYPE, proxyTypeToHuman } from 'lib/proxy';
19+import { useLocalRouter } from 'lib/LocalRouter';
20+import { formatDots } from 'lib/dateFormat';
21+import capitalize from 'lib/capitalize';
2022
2123//TODO consolidate with azimuth-js' getActivationBlock
2224const getRekeyDate = async (web3, contracts, point) => {
@@ -35,7 +37,7 @@ const getRekeyDate = async (web3, contracts, point) => {
3537};
3638
3739export default function AdminEditPermissions() {
38− const history = useHistory();
40+ const { push, names } = useLocalRouter();
3941 const { web3, contracts } = useNetwork();
4042 const { wallet } = useWallet();
4143 const { pointCursor } = usePointCursor();
@@ -46,8 +48,8 @@ export default function AdminEditPermissions() {
4648 const point = need.point(pointCursor);
4749 const userAddress = need.wallet(wallet).address;
4850
49− const pointDetails = need.details(getDetails(point));
50− const { isOwner, canManage, canSpawn, canVote } = usePermissionsForPoint(
51+ const details = need.details(getDetails(point));
52+ const { canManage, canTransfer, canSpawn, canVote } = usePermissionsForPoint(
5153 userAddress,
5254 point
5355 );
@@ -55,52 +57,49 @@ export default function AdminEditPermissions() {
5557 useLifecycle(() => {
5658 getRekeyDate(need.web3(web3), need.contracts(contracts), point).then(
5759 res => {
58− if (res === null) setRekeyDate(Just('unknown'));
59− else setRekeyDate(Just(res.toString()));
60+ if (res === null) setRekeyDate(Just(new Date()));
61+ else setRekeyDate(Just(res));
6062 }
6163 );
6264 });
6365
64− const goSetManagement = useCallback(
65− () => history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY),
66− [history]
66+ const goToProxy = useCallback(
67+ proxyType => push(names.SET_PROXY, { proxyType }),
68+ [push, names]
6769 );
6870
69− const goSetSpawn = useCallback(
70− () => history.push(ROUTE_NAMES.SET_SPAWN_PROXY),
71− [history]
72− );
73−
74− const goSetVoting = useCallback(
75− () => history.push(ROUTE_NAMES.SET_VOTING_PROXY),
76− [history]
77− );
78−
79− const goSetKeys = useCallback(() => history.push(ROUTE_NAMES.SET_KEYS), [
80− history,
81− ]);
71+ const goSetKeys = useCallback(() => push(names.SET_KEYS), [push, names]);
8272
83− const proxyAction = (name, address, onClick) => {
73+ const proxyAction = (proxyType, address, enabled) => {
8474 if (address === ETH_ZERO_ADDR) {
8575 address = 'Not yet set';
8676 }
8777
78+ const detail = enabled
79+ ? address
80+ : `You do not have permission to change the ${proxyTypeToHuman(
81+ proxyType
82+ )} proxy.`;
83+
8884 return (
8985 <Grid.Item full>
90− <ForwardButton disabled={!isOwner} onClick={onClick} detail={address}>
91− {`${name} Proxy Address`}
86+ <ForwardButton
87+ disabled={!enabled}
88+ onClick={() => goToProxy(proxyType)}
89+ detail={detail}>
90+ {capitalize(proxyTypeToHuman(proxyType))} Proxy Address
9291 </ForwardButton>
9392 </Grid.Item>
9493 );
9594 };
9695
9796 const networkKeysDetail =
98− pointDetails.keyRevisionNumber === 0 ? (
97+ details.keyRevisionNumber === 0 ? (
9998 'Not yet configured'
10099 ) : (
101100 <>
102− {`Revision #${pointDetails.keyRevisionNumber}, since `}
103− {matchBlinky(rekeyDate)}
101+ Revision #{details.keyRevisionNumber}, since{' '}
102+ {matchBlinkyDate(rekeyDate)}
104103 </>
105104 );
106105
@@ -109,33 +108,31 @@ export default function AdminEditPermissions() {
109108 <Grid.Item full as={ViewHeader}>
110109 Permissions
111110 </Grid.Item>
112− <Grid.Item full as={ForwardButton} detail={pointDetails.owner} disabled>
111+
112+ <Grid.Item full as={ForwardButton} detail={details.owner} disabled>
113113 Ownership Address
114114 </Grid.Item>
115115 <Grid.Divider />
116− {proxyAction('Management', pointDetails.managementProxy, goSetManagement)}
116+
117+ {proxyAction(PROXY_TYPE.MANAGEMENT, details.managementProxy, canManage)}
118+ <Grid.Divider />
119+
120+ {proxyAction(PROXY_TYPE.SPAWN, details.spawnProxy, canSpawn)}
121+ <Grid.Divider />
122+
123+ {proxyAction(PROXY_TYPE.TRANSFER, details.transferProxy, canTransfer)}
124+ <Grid.Divider />
125+
126+ {proxyAction(PROXY_TYPE.VOTING, details.votingProxy, canVote)}
117127 <Grid.Divider />
118128
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− )}
132129 <Grid.Item
133130 full
134131 as={ForwardButton}
135132 disabled={!canManage}
136133 onClick={goSetKeys}
137134 detail={networkKeysDetail}>
138− Network keys
135+ Network Keys
139136 </Grid.Item>
140137 <Grid.Divider />
141138 </Grid>