on e366ef3 help sign in
bridge/src/views/Point/Actions.js
237 lines 6.7 kB history raw
1import React from 'react';
2import { azimuth } from 'azimuth-js';
3import * as need from '../../lib/need';
5import { ETH_ZERO_ADDR, CURVE_ZERO_ADDR, eqAddr } from '../../lib/wallet';
6import { Row, Col, 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';
12const isPlanet = point =>
13 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
14const isStar = point => azimuth.getPointSize(point) === azimuth.PointSize.Star;
16function Actions(props) {
17 const history = useHistory();
18 const { wallet } = useWallet();
19 const { online, point, pointDetails, invites } = props;
21 const addr = need.address({ wallet });
23 const planet = isPlanet(point);
24 const star = isStar(point);
26 const isOwner = pointDetails.matchWith({
27 Nothing: _ => false,
28 Just: details => eqAddr(details.value.owner, addr),
29 });
30 const isActive = pointDetails.matchWith({
31 Nothing: _ => false,
32 Just: details => details.value.active,
33 });
34 const isActiveOwner = isOwner && isActive;
35 const canSetSpawnProxy = isActiveOwner && !planet;
36 const canSetManagementProxy = isActiveOwner;
38 const canManage =
39 isOwner ||
40 pointDetails.matchWith({
41 Nothing: _ => false,
42 Just: details => eqAddr(details.value.managementProxy, addr),
43 });
44 const canConfigureKeys = canManage && isActive;
46 const canIssueChild = pointDetails.matchWith({
47 Nothing: () => false,
48 Just: details => {
49 const hasPermission = isOwner || eqAddr(details.value.spawnProxy, addr);
51 const isBooted = details.value.keyRevisionNumber > 0;
53 const isNotPlanet = !isPlanet(point);
55 return hasPermission && isBooted && isNotPlanet;
56 },
57 });
59 const hasInvites = invites.matchWith({
60 Nothing: () => false,
61 Just: count => count.value > 0,
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 canGenKeyfile = pointDetails.matchWith({
72 Nothing: () => false,
73 Just: deets => {
74 const hasPermission =
75 eqAddr(deets.value.owner, addr) ||
76 eqAddr(deets.value.managementProxy, addr);
78 const isBooted = deets.value.keyRevisionNumber > 0;
80 return hasPermission && isBooted;
81 },
82 });
84 const canAcceptTransfer = pointDetails.matchWith({
85 Nothing: () => false,
86 Just: deets => eqAddr(deets.value.transferProxy, addr),
87 });
89 const canCancelTransfer = pointDetails.matchWith({
90 Nothing: () => false,
91 Just: deets =>
92 eqAddr(deets.value.owner, addr) &&
93 !eqAddr(deets.value.transferProxy, ETH_ZERO_ADDR),
94 });
96 const displayReminder = pointDetails.matchWith({
97 Nothing: () => false,
98 Just: deets => {
99 return (
100 deets.value.encryptionKey === CURVE_ZERO_ADDR &&
101 deets.value.authenticationKey === CURVE_ZERO_ADDR
102 );
103 },
104 });
106 let inviteAction = null;
107 if (planet) {
108 inviteAction = (
109 <Button
110 disabled={!isActiveOwner || !online || !hasInvites}
111 prop-size={'sm'}
112 prop-type={'link'}
113 onClick={() => history.push(ROUTE_NAMES.INVITES_SEND)}>
114 {'Send invites ('}
115 {invites.matchWith({
116 Nothing: () => '?',
117 Just: count => count.value,
118 })}
119 {')'}
120 </Button>
121 );
122 }
123 if (star) {
124 inviteAction = (
125 <Button
126 disabled={!(isActiveOwner && canIssueChild) || !online}
127 prop-size={'sm'}
128 prop-type={'link'}
129 onClick={() => {
130 history.push(ROUTE_NAMES.INVITES_MANAGE);
131 }}>
132 {'Manage invites'}
133 </Button>
134 );
135 }
137 return (
138 <div>
139 <H2>{'Actions'}</H2>
140 {displayReminder ? (
141 <P>{`Before you can issue child points or generate your Arvo
142 keyfile, you need to set your public keys.`}</P>
143 ) : (
144 ''
145 )}
146 <Row>
147 <Col className={'flex flex-column items-start col-md-4'}>
148 <Button
149 prop-size={'sm'}
150 prop-type={'link'}
151 disabled={(online || planet) && !canIssueChild}
152 onClick={() => {
153 history.push(ROUTE_NAMES.ISSUE_CHILD);
154 }}>
155 {'Issue child'}
156 </Button>
158 <Button
159 prop-size={'sm'}
160 prop-type={'link'}
161 disabled={online && !canAcceptTransfer}
162 onClick={() => {
163 history.push(ROUTE_NAMES.ACCEPT_TRANSFER);
164 }}>
165 {'Accept incoming transfer'}
166 </Button>
168 <Button
169 prop-size={'sm'}
170 prop-type={'link'}
171 disabled={online && !canCancelTransfer}
172 onClick={() => {
173 history.push(ROUTE_NAMES.CANCEL_TRANSFER);
174 }}>
175 {'Cancel outgoing transfer'}
176 </Button>
178 <Button
179 prop-size={'sm'}
180 prop-type={'link'}
181 disabled={online && !canGenKeyfile}
182 onClick={() => {
183 history.push(ROUTE_NAMES.GEN_KEYFILE);
184 }}>
185 {'Generate Arvo keyfile'}
186 </Button>
187 </Col>
188 <Col className={'flex flex-column items-start col-md-4'}>
189 <Button
190 disabled={online && !canSetSpawnProxy}
191 prop-size={'sm'}
192 prop-type={'link'}
193 onClick={() => {
194 history.push(ROUTE_NAMES.SET_SPAWN_PROXY);
195 }}>
196 {'Change spawn proxy'}
197 </Button>
199 <Button
200 disabled={online && !canSetManagementProxy}
201 prop-size={'sm'}
202 prop-type={'link'}
203 onClick={() => {
204 history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY);
205 }}>
206 {'Change management proxy'}
207 </Button>
209 <Button
210 disabled={online && !canConfigureKeys}
211 prop-size={'sm'}
212 prop-type={'link'}
213 onClick={() => {
214 history.push(ROUTE_NAMES.SET_KEYS);
215 }}>
216 {'Set network keys'}
217 </Button>
219 <Button
220 disabled={online && !canTransfer}
221 prop-size={'sm'}
222 prop-type={'link'}
223 onClick={() => {
224 history.push(ROUTE_NAMES.TRANSFER);
225 }}>
226 {'Transfer'}
227 </Button>
228 </Col>
229 <Col className={'flex flex-column items-start col-md-4'}>
230 {inviteAction}
231 </Col>
232 </Row>
233 </div>
234 );
237export default Actions;