on abbbcbc help sign in
bridge/src/views/Point/Actions.js
187 lines 5.3 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 canAcceptTransfer = pointDetails.matchWith({
71 Nothing: () => false,
72 Just: deets => eqAddr(deets.value.transferProxy, addr),
73 });
75 const canCancelTransfer = pointDetails.matchWith({
76 Nothing: () => false,
77 Just: deets =>
78 eqAddr(deets.value.owner, addr) &&
79 !isZeroAddress(deets.value.transferProxy),
80 });
82 const displayReminder = pointDetails.matchWith({
83 Nothing: () => false,
84 Just: deets => {
85 return (
86 deets.value.encryptionKey === CURVE_ZERO_ADDR &&
87 deets.value.authenticationKey === CURVE_ZERO_ADDR
88 );
89 },
90 });
92 return (
93 <div>
94 <H2>{'Actions'}</H2>
95 {displayReminder ? (
96 <P>{`Before you can issue child points or generate your Arvo
97 keyfile, you need to set your public keys.`}</P>
98 ) : (
99 ''
100 )}
101 <Grid>
102 <Grid.Item third={1}>
103 <Button
104 prop-size={'sm'}
105 prop-type={'link'}
106 disabled={planet && !canIssueChild}
107 onClick={() => {
108 history.push(ROUTE_NAMES.ISSUE_CHILD);
109 }}>
110 {'Issue child'}
111 </Button>
113 <Button
114 prop-size={'sm'}
115 prop-type={'link'}
116 disabled={!canAcceptTransfer}
117 onClick={() => {
118 history.push(ROUTE_NAMES.ACCEPT_TRANSFER);
119 }}>
120 {'Accept incoming transfer'}
121 </Button>
123 <Button
124 prop-size={'sm'}
125 prop-type={'link'}
126 disabled={!canCancelTransfer}
127 onClick={() => {
128 history.push(ROUTE_NAMES.CANCEL_TRANSFER);
129 }}>
130 {'Cancel outgoing transfer'}
131 </Button>
132 </Grid.Item>
133 <Grid.Item third={2}>
134 <Button
135 disabled={!canSetSpawnProxy}
136 prop-size={'sm'}
137 prop-type={'link'}
138 onClick={() => {
139 history.push(ROUTE_NAMES.SET_SPAWN_PROXY);
140 }}>
141 {'Change spawn proxy'}
142 </Button>
144 <Button
145 disabled={!canSetManagementProxy}
146 prop-size={'sm'}
147 prop-type={'link'}
148 onClick={() => {
149 history.push(ROUTE_NAMES.SET_MANAGEMENT_PROXY);
150 }}>
151 {'Change management proxy'}
152 </Button>
154 <Button
155 disabled={!canConfigureKeys}
156 prop-size={'sm'}
157 prop-type={'link'}
158 onClick={() => {
159 history.push(ROUTE_NAMES.SET_KEYS);
160 }}>
161 {'Set network keys'}
162 </Button>
164 <Button
165 disabled={!canTransfer}
166 prop-size={'sm'}
167 prop-type={'link'}
168 onClick={() => {
169 history.push(ROUTE_NAMES.TRANSFER);
170 }}>
171 {'Transfer'}
172 </Button>
173 <Button
174 prop-size={'sm'}
175 prop-type={'link'}
176 onClick={() => {
177 history.push(ROUTE_NAMES.INVITES_MANAGE);
178 }}>
179 {'Invite'}
180 </Button>
181 </Grid.Item>
182 </Grid>
183 </div>
184 );
187export default Actions;