on aee35bb help sign in
bridge/src/views/Points.js
245 lines 6.4 kB history raw
1import React from 'react';
2import { H1, H2, P } from '../components/old/Base';
3import { Button } from '../components/old/Base';
4import * as azimuth from 'azimuth-js';
6import PointList from '../components/old/PointList';
7import { NETWORK_TYPES } from '../lib/network';
8import { ROUTE_NAMES } from '../lib/routeNames';
9import { withHistory } from '../store/history';
10import { ETH_ZERO_ADDR, eqAddr } from '../lib/wallet';
11import { withNetwork } from '../store/network';
12import { compose } from '../lib/lib';
13import { withWallet } from '../store/wallet';
14import { withPointCache } from '../store/pointCache';
15import View from 'components/View';
16import Grid from 'components/Grid';
18const hasTransferProxy = (cache, point) =>
19 point in cache ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR) : false;
21class Points extends React.Component {
22 constructor(props) {
23 super(props);
25 const { networkType } = props;
26 const loading = networkType !== NETWORK_TYPES.OFFLINE;
28 this.state = {
29 points: [],
30 incoming: [],
31 managing: [],
32 voting: [],
33 spawning: [],
34 eclipticOwner: false,
35 loading: loading,
36 };
37 }
39 componentDidMount() {
40 const { web3, wallet, contracts, addToPointCache } = this.props;
42 web3.chain(_ =>
43 contracts.chain(ctrcs =>
44 wallet.chain(async wal => {
45 const addr = wal.address;
47 const points = await azimuth.azimuth.getOwnedPoints(ctrcs, addr);
49 const incoming = await azimuth.azimuth.getTransferringFor(
50 ctrcs,
51 addr
52 );
54 const managing = await azimuth.azimuth.getManagerFor(ctrcs, addr);
56 const voting = await azimuth.azimuth.getVotingFor(ctrcs, addr);
58 const spawning = await azimuth.azimuth.getSpawningFor(ctrcs, addr);
60 const owner = await azimuth.ecliptic.owner(ctrcs);
62 const eclipticOwner = eqAddr(addr, owner);
64 this.setState({
65 points,
66 incoming,
67 managing,
68 voting,
69 spawning,
70 eclipticOwner,
71 loading: false,
72 });
74 this.cachePoints(ctrcs, addToPointCache, points);
75 })
76 )
77 );
78 }
80 cachePoints(contracts, addToPointCache, points) {
81 points.forEach(point => {
82 azimuth.azimuth
83 .getPoint(contracts, point)
84 .then(details => addToPointCache({ [point]: details }));
85 });
86 }
88 render() {
89 const { history, pointCache } = this.props;
91 const {
92 points,
93 incoming,
94 managing,
95 voting,
96 spawning,
97 loading,
98 eclipticOwner,
99 } = this.state;
101 const lookupPointButton = (
102 <Grid>
103 <Grid.Item full>
104 <Button
105 prop-type={'link'}
106 prop-size={'md'}
107 onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
108 {'View a point →'}
109 </Button>
110 <P>{'View a point on Azimuth.'}</P>
111 </Grid.Item>
112 </Grid>
113 );
115 const createGalaxyButton =
116 eclipticOwner === false ? (
117 <div />
118 ) : (
119 <Grid>
120 <Grid.Item full>
121 <Button
122 prop-type={'link'}
123 prop-size={'md'}
124 onClick={() => history.push(ROUTE_NAMES.CREATE_GALAXY)}>
125 {'Create a galaxy →'}
126 </Button>
127 <P>
128 {
129 'You have the authority to create a new Galaxy and you can do so here.'
130 }
131 </P>
132 </Grid.Item>
133 </Grid>
134 );
136 const outgoing = points.filter(point =>
137 hasTransferProxy(pointCache, point)
138 );
140 const outgoingPoints =
141 outgoing.length !== 0 ? (
142 <React.Fragment>
143 <H2>{'Outgoing Transfers'}</H2>
144 <P>
145 {`You own these points until the recipient accepts the incoming
146 transfer. You may cancel the transfer until accepted.`}
147 </P>
148 <PointList routeHandler={history.push} points={outgoing} />
149 </React.Fragment>
150 ) : (
151 <div />
152 );
154 const incomingPoints =
155 incoming.length !== 0 ? (
156 <React.Fragment>
157 <H2>{'Incoming Transfers'}</H2>
158 <P>
159 {`You do not own these points until you accept the incoming transfer.
160 You may reject any incoming transfers.`}
161 </P>
162 <PointList routeHandler={history.push} points={incoming} />
163 </React.Fragment>
164 ) : (
165 <div />
166 );
168 const managingPoints =
169 managing.length !== 0 ? (
170 <React.Fragment>
171 <H2>{'You Are a Management Proxy For'}</H2>
172 <P>
173 {`You can configure or set network keys and conduct sponsorship
174 related operations for these points.`}
175 </P>
176 <PointList routeHandler={history.push} points={managing} />
177 </React.Fragment>
178 ) : (
179 <div />
180 );
182 const votingPoints =
183 voting.length !== 0 ? (
184 <React.Fragment>
185 <H2>{'You Are a Voting Proxy For'}</H2>
186 <P>
187 {`Since you are part of the Galactic Senate, you can cast votes on
188 new Azimuth proposals on behalf of these points.`}
189 </P>
190 <PointList routeHandler={history.push} points={voting} />
191 </React.Fragment>
192 ) : (
193 <div />
194 );
196 const spawningPoints =
197 spawning.length !== 0 ? (
198 <React.Fragment>
199 <H2>{'You Are a Spawn Proxy For'}</H2>
200 <P>{`You can create new child ships under these points.`}</P>
201 <PointList routeHandler={history.push} points={spawning} />
202 </React.Fragment>
203 ) : (
204 <div />
205 );
207 return (
208 <View>
209 <H1>{'Points'}</H1>
211 <P>{`A point is an identity on the Ethereum blockchain.
212 Points declare keys for ships on the Arvo network.`}</P>
214 {lookupPointButton}
216 {createGalaxyButton}
218 {incomingPoints}
220 {outgoingPoints}
222 <H2>{'Your Points'}</H2>
224 <PointList
225 routeHandler={history.push}
226 points={points}
227 loading={loading}
228 />
230 {managingPoints}
232 {votingPoints}
234 {spawningPoints}
235 </View>
236 );
237 }
240export default compose(
241 withNetwork,
242 withHistory,
243 withWallet,
244 withPointCache
245)(Points);