on bbf707a help sign in
bridge/src/views/Point/Actions.js
236 lines 6.6 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 { 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 'components/Grid';
13const isPlanet = point =>
14 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
15const isStar = point => azimuth.getPointSize(point) === azimuth.PointSize.Star;
17function Actions(props) {
18 const history = useHistory();
19 const { wallet } = useWallet();
20 const { online, point, pointDetails, invites } = props;
22 const addr = need.addressFromWallet(wallet);
24 const planet = isPlanet(point);
25 const star = isStar(point);
27 const isOwner = pointDetails.matchWith({
28 Nothing: _ => false,
29 Just: details => eqAddr(details.value.owner, addr),
30 });
31 const isActive = pointDetails.matchWith({
32 Nothing: _ => false,
33 Just: details => details.value.active,
34 });
35 const isActiveOwner = isOwner && isActive;
36 const canSetSpawnProxy = isActiveOwner && !planet;
37 const canSetManagementProxy = isActiveOwner;
39 const canManage =
40 isOwner ||
41 pointDetails.matchWith({
42 Nothing: _ => false,
43 Just: details => eqAddr(details.value.managementProxy, addr),
44 });
45 const canConfigureKeys = canManage && isActive;
47 const canIssueChild = pointDetails.matchWith({
48 Nothing: () => false,
49 Just: details => {
50 const hasPermission = isOwner || eqAddr(details.value.spawnProxy, addr);
52 const isBooted = details.value.keyRevisionNumber > 0;
54 const isNotPlanet = !isPlanet(point);
56 return hasPermission && isBooted && isNotPlanet;
57 },
58 });
60 const hasInvites = invites.matchWith({
61 Nothing: () => false,
62 Just: count => count.value > 0,
63 });
65 const canTransfer = pointDetails.matchWith({
66 Nothing: () => false,
67 Just: deets =>
68 eqAddr(deets.value.transferProxy, addr) ||
69 eqAddr(deets.value.owner, addr),
70 });
72 const canGenKeyfile = pointDetails.matchWith({
73 Nothing: () => false,
74 Just: deets => {
75 const hasPermission =
76 eqAddr(deets.value.owner, addr) ||
77 eqAddr(deets.value.managementProxy, addr);
79 const isBooted = deets.value.keyRevisionNumber > 0;
81 return hasPermission && isBooted;
82 },
83 });
85 const canAcceptTransfer = pointDetails.matchWith({
86 Nothing: () => false,
87 Just: deets => eqAddr(deets.value.transferProxy, addr),
88 });
90 const canCancelTransfer = pointDetails.matchWith({
91 Nothing: () => false,
92 Just: deets =>
93 eqAddr(deets.value.owner, addr) &&
94 !eqAddr(deets.value.transferProxy, ETH_ZERO_ADDR),
95 });
97 const displayReminder = pointDetails.matchWith({
98 Nothing: () => false,
99 Just: deets => {
100 return (
101 deets.value.encryptionKey === CURVE_ZERO_ADDR &&
102 deets.value.authenticationKey === CURVE_ZERO_ADDR
103 );
104 },
105 });
107 let inviteAction = null;
108 if (planet) {
109 inviteAction = (
110 <Button
111 disabled={!isActiveOwner || !online || !hasInvites}
112 prop-size={'sm'}
113 prop-type={'link'}
114 onClick={() => history.push(ROUTE_NAMES.INVITES_SEND)}>
115 {'Send invites ('}
116 {invites.matchWith({
117 Nothing: () => '?',
118 Just: count => count.value,
119 })}
120 {')'}
121 </Button>
122 );
123 }
124 if (star) {
125 inviteAction = (
126 <Button
127 disabled={!(isActiveOwner && canIssueChild) || !online}
128 prop-size={'sm'}
129 prop-type={'link'}
130 onClick={() => {
131 history.push(ROUTE_NAMES.INVITES_MANAGE);
132 }}>
133 {'Manage invites'}
134 </Button>
135 );
136 }
138 return (
139 <div>
140 <H2>{'Actions'}</H2>
141 {displayReminder ? (
142 <P>{`Before you can issue child points or generate your Arvo
143 keyfile, you need to set your public keys.`}</P>
144 ) : (
145 ''
146 )}
147 <Grid>
148 <Grid.Item third={1}>
149 <Button
150 prop-size={'sm'}
151 prop-type={'link'}
152 disabled={(online || planet) && !canIssueChild}
153 onClick={() => {
154 history.push(ROUTE_NAMES.ISSUE_CHILD);
155 }}>
156 {'Issue child'}
157 </Button>
159 <Button
160 prop-size={'sm'}
161 prop-type={'link'}
162 disabled={online && !canAcceptTransfer}
163 onClick={() => {
164 history.push(ROUTE_NAMES.ACCEPT_TRANSFER);
165 }}>
166 {'Accept incoming transfer'}
167 </Button>
169 <Button
170 prop-size={'sm'}
171 prop-type={'link'}
172 disabled={online && !canCancelTransfer}
173 onClick={() => {
174 history.push(ROUTE_NAMES.CANCEL_TRANSFER);
175 }}>
176 {'Cancel outgoing transfer'}
177 </Button>
179 <Button
180 prop-size={'sm'}
181 prop-type={'link'}
182 disabled={online && !canGenKeyfile}
183 onClick={() => {
184 history.push(ROUTE_NAMES.GEN_KEYFILE);
185 }}>
186 {'Generate Arvo keyfile'}
187 </Button>
188 </Grid.Item>
189 <Grid.Item third={2}>
190 <Button
191 disabled={online && !canSetSpawnProxy}
192 prop-size={'sm'}
193 prop-type={'link'}
194 onClick={() => {
195 history.push(ROUTE_NAMES.SET_SPAWN_PROXY);
196 }}>
197 {'Change spawn proxy'}
198 </Button>
200 <Button
201 disabled={online && !canSetManagementProxy}
202 prop-size={'sm'}
203 prop-type={'link'}
204 onClick={() => {
205 history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY);
206 }}>
207 {'Change management proxy'}
208 </Button>
210 <Button
211 disabled={online && !canConfigureKeys}
212 prop-size={'sm'}
213 prop-type={'link'}
214 onClick={() => {
215 history.push(ROUTE_NAMES.SET_KEYS);
216 }}>
217 {'Set network keys'}
218 </Button>
220 <Button
221 disabled={online && !canTransfer}
222 prop-size={'sm'}
223 prop-type={'link'}
224 onClick={() => {
225 history.push(ROUTE_NAMES.TRANSFER);
226 }}>
227 {'Transfer'}
228 </Button>
229 </Grid.Item>
230 <Grid.Item third={3}>{inviteAction}</Grid.Item>
231 </Grid>
232 </div>
233 );
236export default Actions;