on a77fa97 help sign in
bridge/src/views/Points.js
186 lines 5.1 kB history raw
1import React from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { H1, H2, P, Grid } from 'indigo-react';
5import { ROUTE_NAMES } from 'lib/routeNames';
6import { isZeroAddress } from 'lib/wallet';
7import useIsEclipticOwner from 'lib/useIsEclipticOwner';
8import { useSyncKnownPoints } from 'lib/useSyncPoints';
10import { useHistory } from 'store/history';
11import { useWallet } from 'store/wallet';
12import { usePointCache } from 'store/pointCache';
14import View from 'components/View';
15import { ForwardButton } from 'components/Buttons';
16import useLifecycle from 'lib/useLifecycle';
18//TODO new component
19import { usePointCursor } from 'store/pointCursor';
20import * as ob from 'urbit-ob';
21const PointList = function(props) {
22 const { setPointCursor } = usePointCursor();
23 const history = useHistory();
24 const { points, loading } = props;
26 return points.length === 0 ? (
27 <p>{loading ? 'Loading...' : 'No points to display'}</p>
28 ) : (
29 <>
30 {points.map(point => (
31 <P
32 key={point}
33 onClick={() => {
34 setPointCursor(Just(point));
35 history.push(ROUTE_NAMES.POINT);
36 }}>
37 {ob.patp(point)}
38 </P>
39 ))}
40 </>
41 );
42};
44const matchArray = obj =>
45 obj.matchWith({ Nothing: () => [], Just: p => p.value });
47const hasTransferProxy = (details, point) =>
48 !isZeroAddress(details.transferProxy);
50export default function Points() {
51 const { wallet } = useWallet();
52 const history = useHistory();
53 const {
54 getControlledPoints,
55 syncControlledPoints,
56 getDetails,
57 } = usePointCache();
58 const {
59 ownedPoints,
60 incomingPoints,
61 managingPoints,
62 votingPoints,
63 spawningPoints,
64 } = getControlledPoints(wallet);
65 const isEclipticOwner = useIsEclipticOwner();
67 const owned = matchArray(ownedPoints);
68 const incoming = matchArray(incomingPoints);
69 const managing = matchArray(managingPoints);
70 const voting = matchArray(votingPoints);
71 const spawning = matchArray(spawningPoints);
73 // sync controlled points on mount
74 useLifecycle(() => {
75 syncControlledPoints();
76 });
78 // sync display details for known points
79 useSyncKnownPoints([
80 ...owned,
81 ...incoming,
82 ...managing,
83 ...voting,
84 ...spawning,
85 ]);
87 const loading = Nothing.hasInstance(ownedPoints);
89 const outgoing = ownedPoints.filter(point =>
90 getDetails(point).matchWith({
91 Nothing: () => false,
92 Just: p => hasTransferProxy(p.value),
93 })
94 );
96 return (
97 <View>
98 <H1>Points</H1>
100 <P>
101 A point is an identity on the Ethereum blockchain. Points declare keys
102 for ships on the Arvo network.
103 </P>
105 <Grid>
106 <Grid.Divider />
107 <Grid.Item full>
108 <ForwardButton
109 detail="View a point on Azimuth"
110 onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
111 View a point
112 </ForwardButton>
113 </Grid.Item>
114 <Grid.Divider />
115 {isEclipticOwner && (
116 <>
117 <Grid.Item full>
118 <ForwardButton
119 detail="You have the authority to create a new Galaxy."
120 onClick={() => history.push(ROUTE_NAMES.CREATE_GALAXY)}>
121 Create a galaxy
122 </ForwardButton>
123 </Grid.Item>
124 <Grid.Divider />
125 </>
126 )}
127 </Grid>
129 {incoming.length > 0 && (
130 <>
131 <H2>Incoming Transfers</H2>
132 <P>
133 You do not own these points until you accept the incoming transfer.
134 You may reject any incoming transfers.
135 </P>
136 <PointList routeHandler={history.push} points={incoming} />
137 </>
138 )}
140 {outgoing.length > 0 && (
141 <>
142 <H2>Outgoing Transfers</H2>
143 <P>
144 You own these points until the recipient accepts the incoming
145 transfer. You may cancel the transfer until accepted.
146 </P>
147 <PointList routeHandler={history.push} points={outgoing} />
148 </>
149 )}
151 <H2>Your Points</H2>
153 <PointList routeHandler={history.push} points={owned} loading={loading} />
155 {managing.length > 0 && (
156 <>
157 <H2>You Are a Management Proxy For</H2>
158 <P>
159 You can configure or set network keys and conduct sponsorship
160 related operations for these points.
161 </P>
162 <PointList routeHandler={history.push} points={managing} />
163 </>
164 )}
166 {voting.length > 0 && (
167 <>
168 <H2>You Are a Voting Proxy For</H2>
169 <P>
170 Since you are part of the Galactic Senate, you can cast votes on new
171 Azimuth proposals on behalf of these points.
172 </P>
173 <PointList routeHandler={history.push} points={voting} />
174 </>
175 )}
177 {spawning.length > 0 && (
178 <>
179 <H2>You Are a Spawn Proxy For</H2>
180 <P>You can create new child points under these points.</P>
181 <PointList routeHandler={history.push} points={spawning} />
182 </>
183 )}
184 </View>
185 );