on 05c1914 help sign in
bridge/src/views/Points.js
247 lines 6.2 kB history raw
1import React from 'react'
2import { Row, Col, H1, H2, P } from '../components/Base'
3import { Button } from '../components/Base'
4import * as azimuth from 'azimuth-js'
6import PointList from '../components/PointList'
7import { ROUTE_NAMES } from '../lib/router'
8import {
9 ETH_ZERO_ADDR,
10 addressFromSecp256k1Public,
11 eqAddr
12 } from '../lib/wallet'
14const hasTransferProxy = (cache, point) =>
15 point in cache
16 ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR)
17 : false
19class Points extends React.Component {
21 constructor(props) {
22 super(props)
24 this.state = {
25 points: [],
26 incoming: [],
27 managing: [],
28 voting: [],
29 spawning: [],
30 eclipticOwner: false,
31 loading: true
32 }
33 }
35 componentDidMount() {
36 const { web3, wallet, contracts, addToPointCache } = this.props
38 web3.chain(_ =>
39 contracts.chain(ctrcs =>
40 wallet.chain(async wal => {
41 const pub = wal.publicKey
42 const addr = addressFromSecp256k1Public(pub)
44 const points =
45 await azimuth.azimuth.getOwnedPoints(ctrcs, addr)
47 const incoming =
48 await azimuth.azimuth.getTransferringFor(ctrcs, addr)
50 const managing =
51 await azimuth.azimuth.getManagerFor(ctrcs, addr)
53 const voting =
54 await azimuth.azimuth.getVotingFor(ctrcs, addr)
56 const spawning =
57 await azimuth.azimuth.getSpawningFor(ctrcs, addr)
59 const owner =
60 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 }
78 cachePoints(contracts, addToPointCache, points) {
79 points.forEach(point => {
80 azimuth.azimuth.getPoint(contracts, point)
81 .then(details => addToPointCache({ [point]: details }))
82 })
83 }
85 render() {
86 const { setPointCursor, pushRoute } = this.props
87 const { pointCache } = this.props
89 const { points, incoming, managing, voting, spawning, loading } = this.state
90 const { eclipticOwner } = this.state
92 const lookupPointButton =
93 <Row>
94 <Col>
95 <Button
96 prop-type={'link'}
97 prop-size={'md'}
98 onClick={ () => pushRoute(ROUTE_NAMES.VIEW_SHIP) }
99 >
100 { 'View a point →' }
101 </Button>
102 <P>
103 { "View a point on Azimuth." }
104 </P>
105 </Col>
106 </Row>
108 const createGalaxyButton =
109 eclipticOwner === false
110 ? <div />
111 : <Row>
112 <Col>
113 <Button
114 prop-type={'link'}
115 prop-size={'md'}
116 onClick={ () => pushRoute(ROUTE_NAMES.CREATE_GALAXY) }
117 >
118 { 'Create a galaxy →' }
119 </Button>
120 <P>
121 { "You have the authority to create a new Galaxy and you can do so here." }
122 </P>
123 </Col>
124 </Row>
126 const outgoing = points.filter(point =>
127 hasTransferProxy(pointCache, point)
128 )
130 const outgoingPoints =
131 outgoing.length !== 0
132 ? <React.Fragment>
133 <H2>{ 'Outgoing Transfers' }</H2>
134 <P>
135 { `You own these points until the recipient accepts the incoming
136 transfer. You may cancel the transfer until accepted.` }
137 </P>
138 <PointList
139 setPointCursor={ setPointCursor }
140 routeHandler={ pushRoute }
141 points={ outgoing }
142 />
143 </React.Fragment>
144 : <div />
146 const incomingPoints =
147 incoming.length !== 0
148 ? <React.Fragment>
149 <H2>{ 'Incoming Transfers' }</H2>
150 <P>
151 { `You do not own these points until you accept the incoming transfer.
152 You may reject any incoming transfers.` }
153 </P>
154 <PointList
155 setPointCursor={ setPointCursor }
156 routeHandler={ pushRoute }
157 points={ incoming }
158 />
159 </React.Fragment>
160 : <div />
162 const managingPoints =
163 managing.length !== 0
164 ? <React.Fragment>
165 <H2>{ 'You Are a Management Proxy For' }</H2>
166 <P>
167 { `You can configure or set public keys and conduct sponsorship
168 related operations for these points.` }
169 </P>
170 <PointList
171 setPointCursor={ setPointCursor }
172 routeHandler={ pushRoute }
173 points={ managing }
174 />
175 </React.Fragment>
176 : <div />
178 const votingPoints =
179 voting.length !== 0
180 ? <React.Fragment>
181 <H2>{ 'You Are a Voting Proxy For' }</H2>
182 <P>
183 { `Since you are part of the Galactic Senate, you can cast votes on
184 new Azimuth proposals on behalf of these points.` }
185 </P>
186 <PointList
187 setPointCursor={ setPointCursor }
188 routeHandler={ pushRoute }
189 points={ voting }
190 />
191 </React.Fragment>
192 : <div />
194 const spawningPoints =
195 spawning.length !== 0
196 ? <React.Fragment>
197 <H2>{ 'You Are a Spawn Proxy For' }</H2>
198 <P>
199 { `You can create new child ships under these points.` }
200 </P>
201 <PointList
202 setPointCursor={ setPointCursor }
203 routeHandler={ pushRoute }
204 points={ spawning }
205 />
206 </React.Fragment>
207 : <div />
209 return (
210 <Row>
211 <Col>
212 <H1>{ 'Points' }</H1>
214 <P>{`A point is an identity on the Ethereum blockchain.
215 Points declare keys for ships on the Arvo network.`}</P>
218 { lookupPointButton }
220 { createGalaxyButton }
222 { incomingPoints }
224 { outgoingPoints }
226 <H2>{ 'Your Points' }</H2>
228 <PointList
229 setPointCursor={ setPointCursor }
230 routeHandler={ pushRoute }
231 points={ points }
232 loading={ loading }
233 />
235 { managingPoints }
237 { votingPoints }
239 { spawningPoints }
241 </Col>
242 </Row>
243 )
244 }
247export default Points