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 './wallet';
10const NULL_PERMISSIONS = {
17 isManagementProxy: false,
20 isTransferProxy: false,
22 isManagementProxySet: false,
23 isSpawnProxySet: false,
24 isVotingProxySet: false,
25 isTransferProxySet: false,
32 spawnIsDelegatedSending: false,
36 * @param {string} address
37 * @param {number} point
39export default function usePermissionsForPoint(address, point) {
40 const { getDetails } = usePointCache();
41 const { contracts } = useNetwork();
43 return getDetails(point).matchWith({
44 Nothing: () => NULL_PERMISSIONS,
45 Just: ({ value: details }) => {
46 const _contracts = need.contracts(contracts);
48 const pointSize = azimuth.getPointSize(point);
49 const isPlanet = pointSize === azimuth.PointSize.Planet;
50 const isStar = pointSize === azimuth.PointSize.Star;
51 const isGalaxy = pointSize === azimuth.PointSize.Galaxy;
52 const isParent = isStar || isGalaxy;
54 const isActive = details.active;
56 const isOwner = eqAddr(address, details.owner);
57 const isActiveOwner = isOwner && isActive;
58 const isManagementProxy = eqAddr(address, details.managementProxy);
59 const isSpawnProxy = eqAddr(address, details.spawnProxy);
60 const isVotingProxy = eqAddr(address, details.votingProxy);
61 const isTransferProxy = eqAddr(address, details.transferProxy);
63 const isManagementProxySet = !isZeroAddress(details.managementProxy);
64 const isSpawnProxySet = !isZeroAddress(details.spawnProxy);
65 const isVotingProxySet = !isZeroAddress(details.votingProxy);
66 const isTransferProxySet = !isZeroAddress(details.transferProxy);
68 const canManage = isOwner || isManagementProxy;
69 const canTransfer = isOwner || isTransferProxy;
71 isParent && (isOwner || isSpawnProxy) && details.keyRevisionNumber > 0;
72 const canVote = isGalaxy && isActive && (isOwner || isVotingProxy);
74 const spawnIsDelegatedSending = eqAddr(
75 _contracts.delegatedSending.address,
104 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