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