on dffcebf help sign in
bridge/src/views/Points.js
159 lines 4.4 kB history raw
1import React from 'react';
2import { 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 PointList from 'components/old/PointList';
15import View from 'components/View';
16import { ForwardButton } from 'components/Buttons';
17import useLifecycle from 'lib/useLifecycle';
19const matchArray = obj =>
20 obj.matchWith({ Nothing: () => [], Just: p => p.value });
22const hasTransferProxy = (details, point) =>
23 !isZeroAddress(details.transferProxy);
25export default function Points() {
26 const { wallet } = useWallet();
27 const history = useHistory();
28 const {
29 getControlledPoints,
30 syncControlledPoints,
31 getDetails,
32 } = usePointCache();
33 const {
34 ownedPoints,
35 incomingPoints,
36 managingPoints,
37 votingPoints,
38 spawningPoints,
39 } = getControlledPoints(wallet);
40 const isEclipticOwner = useIsEclipticOwner();
42 const owned = matchArray(ownedPoints);
43 const incoming = matchArray(incomingPoints);
44 const managing = matchArray(managingPoints);
45 const voting = matchArray(votingPoints);
46 const spawning = matchArray(spawningPoints);
48 // sync controlled points on mount
49 useLifecycle(() => {
50 syncControlledPoints();
51 });
53 // sync display details for known points
54 useSyncKnownPoints([
55 ...owned,
56 ...incoming,
57 ...managing,
58 ...voting,
59 ...spawning,
60 ]);
62 const loading = Nothing.hasInstance(ownedPoints);
64 const outgoing = ownedPoints.filter(point =>
65 getDetails(point).matchWith({
66 Nothing: () => false,
67 Just: p => hasTransferProxy(p.value),
68 })
69 );
71 return (
72 <View>
73 <H1>Points</H1>
75 <P>
76 A point is an identity on the Ethereum blockchain. Points declare keys
77 for ships on the Arvo network.
78 </P>
80 <Grid>
81 <Grid.Item full>
82 <ForwardButton
83 detail="View a point on Azimuth"
84 onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
85 View a point
86 </ForwardButton>
87 </Grid.Item>
88 </Grid>
90 {isEclipticOwner && (
91 <Grid>
92 <Grid.Item full>
93 <ForwardButton
94 detail="You have the authority to create a new Galaxy."
95 onClick={() => history.push(ROUTE_NAMES.CREATE_GALAXY)}>
96 Create a galaxy
97 </ForwardButton>
98 </Grid.Item>
99 </Grid>
100 )}
102 {incoming.length > 0 && (
103 <>
104 <H2>Incoming Transfers</H2>
105 <P>
106 You do not own these points until you accept the incoming transfer.
107 You may reject any incoming transfers.
108 </P>
109 <PointList routeHandler={history.push} points={incoming} />
110 </>
111 )}
113 {outgoing.length > 0 && (
114 <>
115 <H2>Outgoing Transfers</H2>
116 <P>
117 You own these points until the recipient accepts the incoming
118 transfer. You may cancel the transfer until accepted.
119 </P>
120 <PointList routeHandler={history.push} points={outgoing} />
121 </>
122 )}
124 <H2>Your Points</H2>
126 <PointList routeHandler={history.push} points={owned} loading={loading} />
128 {managing.length > 0 && (
129 <>
130 <H2>You Are a Management Proxy For</H2>
131 <P>
132 You can configure or set network keys and conduct sponsorship
133 related operations for these points.
134 </P>
135 <PointList routeHandler={history.push} points={managing} />
136 </>
137 )}
139 {voting.length > 0 && (
140 <>
141 <H2>You Are a Voting Proxy For</H2>
142 <P>
143 Since you are part of the Galactic Senate, you can cast votes on new
144 Azimuth proposals on behalf of these points.
145 </P>
146 <PointList routeHandler={history.push} points={voting} />
147 </>
148 )}
150 {spawning.length > 0 && (
151 <>
152 <H2>You Are a Spawn Proxy For</H2>
153 <P>You can create new child points under these points.</P>
154 <PointList routeHandler={history.push} points={spawning} />
155 </>
156 )}
157 </View>
158 );