on bc37544 help sign in
bridge/src/views/Points.js
161 lines 4.5 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.Divider />
82 <Grid.Item full>
83 <ForwardButton
84 detail="View a point on Azimuth"
85 onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
86 View a point
87 </ForwardButton>
88 </Grid.Item>
89 <Grid.Divider />
90 {isEclipticOwner && (
91 <>
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.Divider />
100 </>
101 )}
102 </Grid>
104 {incoming.length > 0 && (
105 <>
106 <H2>Incoming Transfers</H2>
107 <P>
108 You do not own these points until you accept the incoming transfer.
109 You may reject any incoming transfers.
110 </P>
111 <PointList routeHandler={history.push} points={incoming} />
112 </>
113 )}
115 {outgoing.length > 0 && (
116 <>
117 <H2>Outgoing Transfers</H2>
118 <P>
119 You own these points until the recipient accepts the incoming
120 transfer. You may cancel the transfer until accepted.
121 </P>
122 <PointList routeHandler={history.push} points={outgoing} />
123 </>
124 )}
126 <H2>Your Points</H2>
128 <PointList routeHandler={history.push} points={owned} loading={loading} />
130 {managing.length > 0 && (
131 <>
132 <H2>You Are a Management Proxy For</H2>
133 <P>
134 You can configure or set network keys and conduct sponsorship
135 related operations for these points.
136 </P>
137 <PointList routeHandler={history.push} points={managing} />
138 </>
139 )}
141 {voting.length > 0 && (
142 <>
143 <H2>You Are a Voting Proxy For</H2>
144 <P>
145 Since you are part of the Galactic Senate, you can cast votes on new
146 Azimuth proposals on behalf of these points.
147 </P>
148 <PointList routeHandler={history.push} points={voting} />
149 </>
150 )}
152 {spawning.length > 0 && (
153 <>
154 <H2>You Are a Spawn Proxy For</H2>
155 <P>You can create new child points under these points.</P>
156 <PointList routeHandler={history.push} points={spawning} />
157 </>
158 )}
159 </View>
160 );