import React from 'react' import { Row, Col, H1, H2, P } from '../components/Base' import { Button } from '../components/Base' import * as azimuth from 'azimuth-js' import PointList from '../components/PointList' import { ROUTE_NAMES } from '../lib/router' import { ETH_ZERO_ADDR, addressFromSecp256k1Public, eqAddr } from '../lib/wallet' const hasTransferProxy = (cache, point) => point in cache ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR) : false class Points extends React.Component { constructor(props) { super(props) this.state = { points: [], incoming: [], managing: [], voting: [], spawning: [], eclipticOwner: false, loading: true } } componentDidMount() { const { web3, wallet, contracts, addToPointCache } = this.props web3.chain(_ => contracts.chain(ctrcs => wallet.chain(async wal => { const pub = wal.publicKey const addr = addressFromSecp256k1Public(pub) const points = await azimuth.azimuth.getOwnedPoints(ctrcs, addr) const incoming = await azimuth.azimuth.getTransferringFor(ctrcs, addr) const managing = await azimuth.azimuth.getManagerFor(ctrcs, addr) const voting = await azimuth.azimuth.getVotingFor(ctrcs, addr) const spawning = await azimuth.azimuth.getSpawningFor(ctrcs, addr) const owner = await azimuth.ecliptic.owner(ctrcs) const eclipticOwner = eqAddr(addr, owner) this.setState({ points, incoming, managing, voting, spawning, eclipticOwner, loading: false }) this.cachePoints(ctrcs, addToPointCache, points) }))) } cachePoints(contracts, addToPointCache, points) { points.forEach(point => { azimuth.azimuth.getPoint(contracts, point) .then(details => addToPointCache({ [point]: details })) }) } render() { const { setPointCursor, pushRoute } = this.props const { pointCache } = this.props const { points, incoming, managing, voting, spawning, loading } = this.state const { eclipticOwner } = this.state const lookupPointButton =

{ "View a point on Azimuth." }

const createGalaxyButton = eclipticOwner === false ?
:

{ "You have the authority to create a new Galaxy and you can do so here." }

const outgoing = points.filter(point => hasTransferProxy(pointCache, point) ) const outgoingPoints = outgoing.length !== 0 ?

{ 'Outgoing Transfers' }

{ `You own these points until the recipient accepts the incoming transfer. You may cancel the transfer until accepted.` }

:
const incomingPoints = incoming.length !== 0 ?

{ 'Incoming Transfers' }

{ `You do not own these points until you accept the incoming transfer. You may reject any incoming transfers.` }

:
const managingPoints = managing.length !== 0 ?

{ 'You Are a Management Proxy For' }

{ `You can configure or set public keys and conduct sponsorship related operations for these points.` }

:
const votingPoints = voting.length !== 0 ?

{ 'You Are a Voting Proxy For' }

{ `Since you are part of the Galactic Senate, you can cast votes on new Azimuth proposals on behalf of these points.` }

:
const spawningPoints = spawning.length !== 0 ?

{ 'You Are a Spawn Proxy For' }

{ `You can create new child ships under these points.` }

:
return (

{ 'Points' }

{`A point is an identity on the Ethereum blockchain. Points declare keys for ships on the Arvo network.`}

{ lookupPointButton } { createGalaxyButton } { incomingPoints } { outgoingPoints }

{ 'Your Points' }

{ managingPoints } { votingPoints } { spawningPoints }
) } } export default Points