on dffcebf help sign in
bridge/src/views/Point/Actions.js
188 lines 5.3 kB history raw
1import React from 'react';
2import { azimuth } from 'azimuth-js';
3import * as need from '../../lib/need';
5import { isZeroAddress, eqAddr } from '../../lib/wallet';
6import { H2, P } from '../../components/old/Base';
7import { Button } from '../../components/old/Base';
8import { ROUTE_NAMES } from '../../lib/routeNames';
9import { useHistory } from '../../store/history';
10import { useWallet } from '../../store/wallet';
11import { Grid } from 'indigo-react';
12import { usePointCursor } from 'store/pointCursor';
13import { usePointCache } from 'store/pointCache';
14import { CURVE_ZERO_ADDR } from 'lib/keys';
16const isPlanet = point =>
17 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
19function Actions() {
20 const history = useHistory();
21 const { wallet } = useWallet();
22 const { pointCursor } = usePointCursor();
23 const point = need.point(pointCursor);
24 const { getDetails } = usePointCache();
25 const pointDetails = getDetails(point);
27 const addr = need.addressFromWallet(wallet);
29 const planet = isPlanet(point);
31 const isOwner = pointDetails.matchWith({
32 Nothing: _ => false,
33 Just: details => eqAddr(details.value.owner, addr),
34 });
35 const isActive = pointDetails.matchWith({
36 Nothing: _ => false,
37 Just: details => details.value.active,
38 });
39 const isActiveOwner = isOwner && isActive;
40 const canSetSpawnProxy = isActiveOwner && !planet;
41 const canSetManagementProxy = isActiveOwner;
43 const canManage =
44 isOwner ||
45 pointDetails.matchWith({
46 Nothing: _ => false,
47 Just: details => eqAddr(details.value.managementProxy, addr),
48 });
49 const canConfigureKeys = canManage && isActive;
51 const canIssueChild = pointDetails.matchWith({
52 Nothing: () => false,
53 Just: details => {
54 const hasPermission = isOwner || eqAddr(details.value.spawnProxy, addr);
56 const isBooted = details.value.keyRevisionNumber > 0;
58 const isNotPlanet = !isPlanet(point);
60 return hasPermission && isBooted && isNotPlanet;
61 },
62 });
64 const canTransfer = pointDetails.matchWith({
65 Nothing: () => false,
66 Just: deets =>
67 eqAddr(deets.value.transferProxy, addr) ||
68 eqAddr(deets.value.owner, addr),
69 });
71 const canAcceptTransfer = pointDetails.matchWith({
72 Nothing: () => false,
73 Just: deets => eqAddr(deets.value.transferProxy, addr),
74 });
76 const canCancelTransfer = pointDetails.matchWith({
77 Nothing: () => false,
78 Just: deets =>
79 eqAddr(deets.value.owner, addr) &&
80 !isZeroAddress(deets.value.transferProxy),
81 });
83 const displayReminder = pointDetails.matchWith({
84 Nothing: () => false,
85 Just: deets => {
86 return (
87 deets.value.encryptionKey === CURVE_ZERO_ADDR &&
88 deets.value.authenticationKey === CURVE_ZERO_ADDR
89 );
90 },
91 });
93 return (
94 <div>
95 <H2>{'Actions'}</H2>
96 {displayReminder ? (
97 <P>{`Before you can issue child points or generate your Arvo
98 keyfile, you need to set your public keys.`}</P>
99 ) : (
100 ''
101 )}
102 <Grid>
103 <Grid.Item third={1}>
104 <Button
105 prop-size={'sm'}
106 prop-type={'link'}
107 disabled={planet && !canIssueChild}
108 onClick={() => {
109 history.push(ROUTE_NAMES.ISSUE_CHILD);
110 }}>
111 {'Issue child'}
112 </Button>
114 <Button
115 prop-size={'sm'}
116 prop-type={'link'}
117 disabled={!canAcceptTransfer}
118 onClick={() => {
119 history.push(ROUTE_NAMES.ACCEPT_TRANSFER);
120 }}>
121 {'Accept incoming transfer'}
122 </Button>
124 <Button
125 prop-size={'sm'}
126 prop-type={'link'}
127 disabled={!canCancelTransfer}
128 onClick={() => {
129 history.push(ROUTE_NAMES.CANCEL_TRANSFER);
130 }}>
131 {'Cancel outgoing transfer'}
132 </Button>
133 </Grid.Item>
134 <Grid.Item third={2}>
135 <Button
136 disabled={!canSetSpawnProxy}
137 prop-size={'sm'}
138 prop-type={'link'}
139 onClick={() => {
140 history.push(ROUTE_NAMES.SET_SPAWN_PROXY);
141 }}>
142 {'Change spawn proxy'}
143 </Button>
145 <Button
146 disabled={!canSetManagementProxy}
147 prop-size={'sm'}
148 prop-type={'link'}
149 onClick={() => {
150 history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY);
151 }}>
152 {'Change management proxy'}
153 </Button>
155 <Button
156 disabled={!canConfigureKeys}
157 prop-size={'sm'}
158 prop-type={'link'}
159 onClick={() => {
160 history.push(ROUTE_NAMES.SET_KEYS);
161 }}>
162 {'Set network keys'}
163 </Button>
165 <Button
166 disabled={!canTransfer}
167 prop-size={'sm'}
168 prop-type={'link'}
169 onClick={() => {
170 history.push(ROUTE_NAMES.TRANSFER);
171 }}>
172 {'Transfer'}
173 </Button>
174 <Button
175 prop-size={'sm'}
176 prop-type={'link'}
177 onClick={() => {
178 history.push(ROUTE_NAMES.INVITES_MANAGE);
179 }}>
180 {'Invite'}
181 </Button>
182 </Grid.Item>
183 </Grid>
184 </div>
185 );
188export default Actions;