on 616e621 help sign in
bridge/src/views/Points.js
244 lines 6.1 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 }
32 }
34 componentDidMount() {
35 const { web3, wallet, contracts, addToPointCache } = this.props
37 web3.chain(_ =>
38 contracts.chain(ctrcs =>
39 wallet.chain(async wal => {
40 const pub = wal.publicKey
41 const addr = addressFromSecp256k1Public(pub)
43 const points =
44 await azimuth.azimuth.getOwnedPoints(ctrcs, addr)
46 const incoming =
47 await azimuth.azimuth.getTransferringFor(ctrcs, addr)
49 const managing =
50 await azimuth.azimuth.getManagerFor(ctrcs, addr)
52 const voting =
53 await azimuth.azimuth.getVotingFor(ctrcs, addr)
55 const spawning =
56 await azimuth.azimuth.getSpawningFor(ctrcs, addr)
58 const owner =
59 await azimuth.ecliptic.owner(ctrcs)
61 const eclipticOwner = eqAddr(addr, owner)
63 this.setState({
64 points,
65 incoming,
66 managing,
67 voting,
68 spawning,
69 eclipticOwner
70 })
72 this.cachePoints(ctrcs, addToPointCache, points)
73 })))
74 }
76 cachePoints(contracts, addToPointCache, points) {
77 points.forEach(point => {
78 azimuth.azimuth.getPoint(contracts, point)
79 .then(details => addToPointCache({ [point]: details }))
80 })
81 }
83 render() {
84 const { setPointCursor, pushRoute } = this.props
85 const { pointCache } = this.props
87 const { points, incoming, managing, voting, spawning } = this.state
88 const { eclipticOwner } = this.state
90 const lookupPointButton =
91 <Row>
92 <Col>
93 <Button
94 prop-type={'link'}
95 prop-size={'md'}
96 onClick={ () => pushRoute(ROUTE_NAMES.VIEW_SHIP) }
97 >
98 { 'View a point →' }
99 </Button>
100 <P>
101 { "View a point on Azimuth." }
102 </P>
103 </Col>
104 </Row>
106 const createGalaxyButton =
107 eclipticOwner === false
108 ? <div />
109 : <Row>
110 <Col>
111 <Button
112 prop-type={'link'}
113 prop-size={'md'}
114 onClick={ () => pushRoute(ROUTE_NAMES.CREATE_GALAXY) }
115 >
116 { 'Create a galaxy →' }
117 </Button>
118 <P>
119 { "You have the authority to create a new Galaxy and you can do so here." }
120 </P>
121 </Col>
122 </Row>
124 const outgoing = points.filter(point =>
125 hasTransferProxy(pointCache, point)
126 )
128 const outgoingPoints =
129 outgoing.length !== 0
130 ? <React.Fragment>
131 <H2>{ 'Outgoing Transfers' }</H2>
132 <P>
133 { `You own these points until the recipient accepts the incoming
134 transfer. You may cancel the transfer until accepted.` }
135 </P>
136 <PointList
137 setPointCursor={ setPointCursor }
138 routeHandler={ pushRoute }
139 points={ outgoing }
140 />
141 </React.Fragment>
142 : <div />
144 const incomingPoints =
145 incoming.length !== 0
146 ? <React.Fragment>
147 <H2>{ 'Incoming Transfers' }</H2>
148 <P>
149 { `You do not own these points until you accept the incoming transfer.
150 You may reject any incoming transfers.` }
151 </P>
152 <PointList
153 setPointCursor={ setPointCursor }
154 routeHandler={ pushRoute }
155 points={ incoming }
156 />
157 </React.Fragment>
158 : <div />
160 const managingPoints =
161 managing.length !== 0
162 ? <React.Fragment>
163 <H2>{ 'You Are a Management Proxy For' }</H2>
164 <P>
165 { `You can configure or set Urbit networking keys and conduct
166 sponsorship related operations for these points.` }
167 </P>
168 <PointList
169 setPointCursor={ setPointCursor }
170 routeHandler={ pushRoute }
171 points={ managing }
172 />
173 </React.Fragment>
174 : <div />
176 const votingPoints =
177 voting.length !== 0
178 ? <React.Fragment>
179 <H2>{ 'You Are a Voting Proxy For' }</H2>
180 <P>
181 { `Since you are part of the Galactic Senate, you can cast votes on
182 new Azimuth proposals on behalf of these points.` }
183 </P>
184 <PointList
185 setPointCursor={ setPointCursor }
186 routeHandler={ pushRoute }
187 points={ voting }
188 />
189 </React.Fragment>
190 : <div />
192 const spawningPoints =
193 spawning.length !== 0
194 ? <React.Fragment>
195 <H2>{ 'You Are a Spawn Proxy For' }</H2>
196 <P>
197 { `You can create new child ships under these points.` }
198 </P>
199 <PointList
200 setPointCursor={ setPointCursor }
201 routeHandler={ pushRoute }
202 points={ spawning }
203 />
204 </React.Fragment>
205 : <div />
207 return (
208 <Row>
209 <Col>
210 <H1>{ 'Points' }</H1>
212 <P>{`A point is an identity on the Ethereum blockchain.
213 Points declare keys for ships on the Arvo network.`}</P>
216 { lookupPointButton }
218 { createGalaxyButton }
220 { incomingPoints }
222 { outgoingPoints }
224 <H2>{ 'Your Points' }</H2>
226 <PointList
227 setPointCursor={ setPointCursor }
228 routeHandler={ pushRoute }
229 points={ points }
230 />
232 { managingPoints }
234 { votingPoints }
236 { spawningPoints }
238 </Col>
239 </Row>
240 )
241 }
244export default Points