1import { azimuth } from 'azimuth-js';
3import { usePointCache } from 'store/pointCache';
4import { useNetwork } from 'store/network';
6import * as need from 'lib/need';
8import { eqAddr, isZeroAddress } from './utils/address';
10const NULL_PERMISSIONS = {
15 isManagementProxy: false,
18 isTransferProxy: false,
20 isManagementProxySet: false,
21 isSpawnProxySet: false,
22 isVotingProxySet: false,
23 isTransferProxySet: false,
30 spawnIsDelegatedSending: false,
34 * @param {string} address
35 * @param {number} point
37export default function usePermissionsForPoint(address, point) {
38 const { getDetails } = usePointCache();
39 const { contracts } = useNetwork();
41 const pointSize = azimuth.getPointSize(point);
42 const isPlanet = pointSize === azimuth.PointSize.Planet;
43 const isStar = pointSize === azimuth.PointSize.Star;
44 const isGalaxy = pointSize === azimuth.PointSize.Galaxy;
45 const isParent = isStar || isGalaxy;
46 const staticPermissions = { isPlanet, isStar, isGalaxy, isParent };
50 ...getDetails(point).matchWith({
51 Nothing: () => NULL_PERMISSIONS,
52 Just: ({ value: details }) => {
53 const _contracts = need.contracts(contracts);
55 const isActive = details.active;
57 const isOwner = eqAddr(address, details.owner);
58 const isActiveOwner = isOwner && isActive;
59 const isManagementProxy = eqAddr(address, details.managementProxy);
60 const isSpawnProxy = eqAddr(address, details.spawnProxy);
61 const isVotingProxy = eqAddr(address, details.votingProxy);
62 const isTransferProxy = eqAddr(address, details.transferProxy);
64 const isManagementProxySet = !isZeroAddress(details.managementProxy);
65 const isSpawnProxySet = !isZeroAddress(details.spawnProxy);
66 const isVotingProxySet = !isZeroAddress(details.votingProxy);
67 const isTransferProxySet = !isZeroAddress(details.transferProxy);
69 const canManage = isOwner || isManagementProxy;
70 const canTransfer = isOwner || isTransferProxy;
73 (isOwner || isSpawnProxy) &&
74 details.keyRevisionNumber > 0;
75 const canVote = isGalaxy && isActive && (isOwner || isVotingProxy);
77 const spawnIsDelegatedSending = eqAddr(
78 _contracts.delegatedSending.address,
102 spawnIsDelegatedSending,
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