@@ -4,19 +4,21 @@ import * as need from 'lib/need';
4import { Grid } from 'indigo-react';
4import { Grid } from 'indigo-react';
6import { ForwardButton } from 'components/Buttons';
6import { ForwardButton } from 'components/Buttons';
7−import { matchBlinky } from 'components/Blinky';
7+import { matchBlinky, matchBlinkyDate } from 'components/Blinky';
9−import { ROUTE_NAMES } from 'lib/routeNames';
10import { ETH_ZERO_ADDR } from 'lib/wallet';
9import { ETH_ZERO_ADDR } from 'lib/wallet';
12import useLifecycle from 'lib/useLifecycle';
11import useLifecycle from 'lib/useLifecycle';
13import { useNetwork } from 'store/network';
12import { useNetwork } from 'store/network';
14−import { useHistory } from 'store/history';
15import { useWallet } from 'store/wallet';
13import { useWallet } from 'store/wallet';
16import { usePointCursor } from 'store/pointCursor';
14import { usePointCursor } from 'store/pointCursor';
17import { usePointCache } from 'store/pointCache';
15import { usePointCache } from 'store/pointCache';
18import ViewHeader from 'components/ViewHeader';
16import ViewHeader from 'components/ViewHeader';
19import usePermissionsForPoint from 'lib/usePermissionsForPoint';
17import 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';
21//TODO consolidate with azimuth-js' getActivationBlock
23//TODO consolidate with azimuth-js' getActivationBlock
22const getRekeyDate = async (web3, contracts, point) => {
24const getRekeyDate = async (web3, contracts, point) => {
@@ -35,7 +37,7 @@ const getRekeyDate = async (web3, contracts, point) => {
37export default function AdminEditPermissions() {
39export default function AdminEditPermissions() {
38− const history = useHistory();
40+ const { push, names } = useLocalRouter();
39 const { web3, contracts } = useNetwork();
41 const { web3, contracts } = useNetwork();
40 const { wallet } = useWallet();
42 const { wallet } = useWallet();
41 const { pointCursor } = usePointCursor();
43 const { pointCursor } = usePointCursor();
@@ -46,8 +48,8 @@ export default function AdminEditPermissions() {
46 const point = need.point(pointCursor);
48 const point = need.point(pointCursor);
47 const userAddress = need.wallet(wallet).address;
49 const userAddress = need.wallet(wallet).address;
49− const pointDetails = need.details(getDetails(point));
51+ const details = need.details(getDetails(point));
50− const { isOwner, canManage, canSpawn, canVote } = usePermissionsForPoint(
52+ const { canManage, canTransfer, canSpawn, canVote } = usePermissionsForPoint(
51 userAddress,
53 userAddress,
@@ -55,52 +57,49 @@ export default function AdminEditPermissions() {
55 useLifecycle(() => {
57 useLifecycle(() => {
56 getRekeyDate(need.web3(web3), need.contracts(contracts), point).then(
58 getRekeyDate(need.web3(web3), need.contracts(contracts), point).then(
58− if (res === null) setRekeyDate(Just('unknown'));
60+ if (res === null) setRekeyDate(Just(new Date()));
59− else setRekeyDate(Just(res.toString()));
61+ else setRekeyDate(Just(res));
64− const goSetManagement = useCallback(
66+ const goToProxy = useCallback(
65− () => history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY),
67+ proxyType => push(names.SET_PROXY, { proxyType }),
66− [history]
68+ [push, names]
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), [
71+ const goSetKeys = useCallback(() => push(names.SET_KEYS), [push, names]);
83− const proxyAction = (name, address, onClick) => {
73+ const proxyAction = (proxyType, address, enabled) => {
84 if (address === ETH_ZERO_ADDR) {
74 if (address === ETH_ZERO_ADDR) {
85 address = 'Not yet set';
75 address = 'Not yet set';
78+ const detail = enabled
80+ : `You do not have permission to change the ${proxyTypeToHuman(
89 <Grid.Item full>
85 <Grid.Item full>
90− <ForwardButton disabled={!isOwner} onClick={onClick} detail={address}>
86+ <ForwardButton
91− {`${name} Proxy Address`}
87+ disabled={!enabled}
88+ onClick={() => goToProxy(proxyType)}
90+ {capitalize(proxyTypeToHuman(proxyType))} Proxy Address
92 </ForwardButton>
91 </ForwardButton>
93 </Grid.Item>
92 </Grid.Item>
97 const networkKeysDetail =
96 const networkKeysDetail =
98− pointDetails.keyRevisionNumber === 0 ? (
97+ details.keyRevisionNumber === 0 ? (
99 'Not yet configured'
98 'Not yet configured'
102− {`Revision #${pointDetails.keyRevisionNumber}, since `}
101+ Revision #{details.keyRevisionNumber}, since{' '}
103− {matchBlinky(rekeyDate)}
102+ {matchBlinkyDate(rekeyDate)}
@@ -109,33 +108,31 @@ export default function AdminEditPermissions() {
109 <Grid.Item full as={ViewHeader}>
108 <Grid.Item full as={ViewHeader}>
110 Permissions
109 Permissions
111 </Grid.Item>
110 </Grid.Item>
112− <Grid.Item full as={ForwardButton} detail={pointDetails.owner} disabled>
112+ <Grid.Item full as={ForwardButton} detail={details.owner} disabled>
113 Ownership Address
113 Ownership Address
114 </Grid.Item>
114 </Grid.Item>
115 <Grid.Divider />
115 <Grid.Divider />
116− {proxyAction('Management', pointDetails.managementProxy, goSetManagement)}
117+ {proxyAction(PROXY_TYPE.MANAGEMENT, details.managementProxy, canManage)}
120+ {proxyAction(PROXY_TYPE.SPAWN, details.spawnProxy, canSpawn)}
123+ {proxyAction(PROXY_TYPE.TRANSFER, details.transferProxy, canTransfer)}
126+ {proxyAction(PROXY_TYPE.VOTING, details.votingProxy, canVote)}
117 <Grid.Divider />
127 <Grid.Divider />
121− {proxyAction('Spawn', pointDetails.spawnProxy, goSetSpawn)}
128− {proxyAction('Voting', pointDetails.votingProxy, goSetVoting)}
132 <Grid.Item
129 <Grid.Item
134 as={ForwardButton}
131 as={ForwardButton}
135 disabled={!canManage}
132 disabled={!canManage}
136 onClick={goSetKeys}
133 onClick={goSetKeys}
137 detail={networkKeysDetail}>
134 detail={networkKeysDetail}>
138− Network keys
135+ Network Keys
139 </Grid.Item>
136 </Grid.Item>
140 <Grid.Divider />
137 <Grid.Divider />