on c262e73 help sign in
bridge/src/views/Point/Actions.js
210 lines 5.9 kB history raw
1import React from 'react';
2import { azimuth } from 'azimuth-js';
3import * as need from '../../lib/need';
5import { CURVE_ZERO_ADDR, 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';
15const isPlanet = point =>
16 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
18function Actions() {
19 const history = useHistory();
20 const { wallet } = useWallet();
21 const { pointCursor } = usePointCursor();
22 const point = need.point(pointCursor);
23 const { getDetails } = usePointCache();
24 const pointDetails = getDetails(point);
26 const addr = need.addressFromWallet(wallet);
28 const planet = isPlanet(point);
30 const isOwner = pointDetails.matchWith({
31 Nothing: _ => false,
32 Just: details => eqAddr(details.value.owner, addr),
33 });
34 const isActive = pointDetails.matchWith({
35 Nothing: _ => false,
36 Just: details => details.value.active,
37 });
38 const isActiveOwner = isOwner && isActive;
39 const canSetSpawnProxy = isActiveOwner && !planet;
40 const canSetManagementProxy = isActiveOwner;
42 const canManage =
43 isOwner ||
44 pointDetails.matchWith({
45 Nothing: _ => false,
46 Just: details => eqAddr(details.value.managementProxy, addr),
47 });
48 const canConfigureKeys = canManage && isActive;
50 const canIssueChild = pointDetails.matchWith({
51 Nothing: () => false,
52 Just: details => {
53 const hasPermission = isOwner || eqAddr(details.value.spawnProxy, addr);
55 const isBooted = details.value.keyRevisionNumber > 0;
57 const isNotPlanet = !isPlanet(point);
59 return hasPermission && isBooted && isNotPlanet;
60 },
61 });
63 const canTransfer = pointDetails.matchWith({
64 Nothing: () => false,
65 Just: deets =>
66 eqAddr(deets.value.transferProxy, addr) ||
67 eqAddr(deets.value.owner, addr),
68 });
70 const canGenKeyfile = pointDetails.matchWith({
71 Nothing: () => false,
72 Just: deets => {
73 const hasPermission =
74 eqAddr(deets.value.owner, addr) ||
75 eqAddr(deets.value.managementProxy, addr);
77 const isBooted = deets.value.keyRevisionNumber > 0;
79 return hasPermission && isBooted;
80 },
81 });
83 const canAcceptTransfer = pointDetails.matchWith({
84 Nothing: () => false,
85 Just: deets => eqAddr(deets.value.transferProxy, addr),
86 });
88 const canCancelTransfer = pointDetails.matchWith({
89 Nothing: () => false,
90 Just: deets =>
91 eqAddr(deets.value.owner, addr) &&
92 !isZeroAddress(deets.value.transferProxy),
93 });
95 const displayReminder = pointDetails.matchWith({
96 Nothing: () => false,
97 Just: deets => {
98 return (
99 deets.value.encryptionKey === CURVE_ZERO_ADDR &&
100 deets.value.authenticationKey === CURVE_ZERO_ADDR
101 );
102 },
103 });
105 return (
106 <div>
107 <H2>{'Actions'}</H2>
108 {displayReminder ? (
109 <P>{`Before you can issue child points or generate your Arvo
110 keyfile, you need to set your public keys.`}</P>
111 ) : (
112 ''
113 )}
114 <Grid>
115 <Grid.Item third={1}>
116 <Button
117 prop-size={'sm'}
118 prop-type={'link'}
119 disabled={planet && !canIssueChild}
120 onClick={() => {
121 history.push(ROUTE_NAMES.ISSUE_CHILD);
122 }}>
123 {'Issue child'}
124 </Button>
126 <Button
127 prop-size={'sm'}
128 prop-type={'link'}
129 disabled={!canAcceptTransfer}
130 onClick={() => {
131 history.push(ROUTE_NAMES.ACCEPT_TRANSFER);
132 }}>
133 {'Accept incoming transfer'}
134 </Button>
136 <Button
137 prop-size={'sm'}
138 prop-type={'link'}
139 disabled={!canCancelTransfer}
140 onClick={() => {
141 history.push(ROUTE_NAMES.CANCEL_TRANSFER);
142 }}>
143 {'Cancel outgoing transfer'}
144 </Button>
146 <Button
147 prop-size={'sm'}
148 prop-type={'link'}
149 disabled={!canGenKeyfile}
150 onClick={() => {
151 history.push(ROUTE_NAMES.GEN_KEYFILE);
152 }}>
153 {'Generate Arvo keyfile'}
154 </Button>
155 </Grid.Item>
156 <Grid.Item third={2}>
157 <Button
158 disabled={!canSetSpawnProxy}
159 prop-size={'sm'}
160 prop-type={'link'}
161 onClick={() => {
162 history.push(ROUTE_NAMES.SET_SPAWN_PROXY);
163 }}>
164 {'Change spawn proxy'}
165 </Button>
167 <Button
168 disabled={!canSetManagementProxy}
169 prop-size={'sm'}
170 prop-type={'link'}
171 onClick={() => {
172 history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY);
173 }}>
174 {'Change management proxy'}
175 </Button>
177 <Button
178 disabled={!canConfigureKeys}
179 prop-size={'sm'}
180 prop-type={'link'}
181 onClick={() => {
182 history.push(ROUTE_NAMES.SET_KEYS);
183 }}>
184 {'Set network keys'}
185 </Button>
187 <Button
188 disabled={!canTransfer}
189 prop-size={'sm'}
190 prop-type={'link'}
191 onClick={() => {
192 history.push(ROUTE_NAMES.TRANSFER);
193 }}>
194 {'Transfer'}
195 </Button>
196 <Button
197 prop-size={'sm'}
198 prop-type={'link'}
199 onClick={() => {
200 history.push(ROUTE_NAMES.INVITES_MANAGE);
201 }}>
202 {'Invite'}
203 </Button>
204 </Grid.Item>
205 </Grid>
206 </div>
207 );
210export default Actions;