on master help sign in
Always calculate "static" "permissions"
4adbdc3Fang
src/lib/usePermissionsForPoint.js+60−61
@@ -8,9 +8,7 @@ import * as need from 'lib/need';
8import { eqAddr, isZeroAddress } from './wallet';
8import { eqAddr, isZeroAddress } from './wallet';
9
9
10const NULL_PERMISSIONS = {
10const NULL_PERMISSIONS = {
11− isPlanet: false,
11+ isActive: false,
12− isStar: false,
13− isGalaxy: false,
14 //
12 //
15 isOwner: false,
13 isOwner: false,
16 isActiveOwner: false,
14 isActiveOwner: false,
@@ -40,69 +38,70 @@ export default function usePermissionsForPoint(address, point) {
40 const { getDetails } = usePointCache();
38 const { getDetails } = usePointCache();
41 const { contracts } = useNetwork();
39 const { contracts } = useNetwork();
42
40
43− return getDetails(point).matchWith({
41+ const pointSize = azimuth.getPointSize(point);
44− Nothing: () => NULL_PERMISSIONS,
42+ const isPlanet = pointSize === azimuth.PointSize.Planet;
45− Just: ({ value: details }) => {
43+ const isStar = pointSize === azimuth.PointSize.Star;
46− const _contracts = need.contracts(contracts);
44+ const isGalaxy = pointSize === azimuth.PointSize.Galaxy;
45+ const isParent = isStar || isGalaxy;
46+ const staticPermissions = { isPlanet, isStar, isGalaxy, isParent };
47
47
48− const pointSize = azimuth.getPointSize(point);
48+ return {
49− const isPlanet = pointSize === azimuth.PointSize.Planet;
49+ ...staticPermissions,
50− const isStar = pointSize === azimuth.PointSize.Star;
50+ ...getDetails(point).matchWith({
51− const isGalaxy = pointSize === azimuth.PointSize.Galaxy;
51+ Nothing: () => NULL_PERMISSIONS,
52− const isParent = isStar || isGalaxy;
52+ Just: ({ value: details }) => {
53+ const _contracts = need.contracts(contracts);
53
54
54− const isActive = details.active;
55+ const isActive = details.active;
55
56
56− const isOwner = eqAddr(address, details.owner);
57+ const isOwner = eqAddr(address, details.owner);
57− const isActiveOwner = isOwner && isActive;
58+ const isActiveOwner = isOwner && isActive;
58− const isManagementProxy = eqAddr(address, details.managementProxy);
59+ const isManagementProxy = eqAddr(address, details.managementProxy);
59− const isSpawnProxy = eqAddr(address, details.spawnProxy);
60+ const isSpawnProxy = eqAddr(address, details.spawnProxy);
60− const isVotingProxy = eqAddr(address, details.votingProxy);
61+ const isVotingProxy = eqAddr(address, details.votingProxy);
61− const isTransferProxy = eqAddr(address, details.transferProxy);
62+ const isTransferProxy = eqAddr(address, details.transferProxy);
62
63
63− const isManagementProxySet = !isZeroAddress(details.managementProxy);
64+ const isManagementProxySet = !isZeroAddress(details.managementProxy);
64− const isSpawnProxySet = !isZeroAddress(details.spawnProxy);
65+ const isSpawnProxySet = !isZeroAddress(details.spawnProxy);
65− const isVotingProxySet = !isZeroAddress(details.votingProxy);
66+ const isVotingProxySet = !isZeroAddress(details.votingProxy);
66− const isTransferProxySet = !isZeroAddress(details.transferProxy);
67+ const isTransferProxySet = !isZeroAddress(details.transferProxy);
67
68
68− const canManage = isOwner || isManagementProxy;
69+ const canManage = isOwner || isManagementProxy;
69− const canTransfer = isOwner || isTransferProxy;
70+ const canTransfer = isOwner || isTransferProxy;
70− const canSpawn =
71+ const canSpawn =
72+ isParent &&
73+ (isOwner || isSpawnProxy) &&
71− isParent && (isOwner || isSpawnProxy) && details.keyRevisionNumber > 0;
74+ details.keyRevisionNumber > 0;
72− const canVote = isGalaxy && isActive && (isOwner || isVotingProxy);
75+ const canVote = isGalaxy && isActive && (isOwner || isVotingProxy);
73
76
74− const spawnIsDelegatedSending = eqAddr(
77+ const spawnIsDelegatedSending = eqAddr(
75− _contracts.delegatedSending.address,
78+ _contracts.delegatedSending.address,
76− details.spawnProxy
79+ details.spawnProxy
77− );
80+ );
78
81
79− return {
82+ return {
80− isPlanet,
81− isStar,
82− isGalaxy,
83− isParent,
84− //
85− isActive,
83+ isActive,
86− //
84+ //
87− isOwner,
85+ isOwner,
88− isActiveOwner,
86+ isActiveOwner,
89− isManagementProxy,
87+ isManagementProxy,
90− isSpawnProxy,
88+ isSpawnProxy,
91− isVotingProxy,
89+ isVotingProxy,
92− isTransferProxy,
90+ isTransferProxy,
93− //
91+ //
94− isManagementProxySet,
92+ isManagementProxySet,
95− isSpawnProxySet,
93+ isSpawnProxySet,
96− isVotingProxySet,
94+ isVotingProxySet,
97− isTransferProxySet,
95+ isTransferProxySet,
98− //
96+ //
99− canManage,
97+ canManage,
100− canTransfer,
98+ canTransfer,
101− canSpawn,
99+ canSpawn,
102− canVote,
100+ canVote,
103− //
101+ //
104− spawnIsDelegatedSending,
102+ spawnIsDelegatedSending,
103+ };
105− };
104+ },
106− },
105+ }),
107− });
106+ };
108}
107}