import React from 'react'; import { Row, Col, H1, H2, P } from '../components/old/Base'; import { Button } from '../components/old/Base'; import * as azimuth from 'azimuth-js'; import PointList from '../components/old/PointList'; import { NETWORK_TYPES } from '../lib/network'; import { ROUTE_NAMES } from '../lib/routeNames'; import { withHistory } from '../store/history'; import { ETH_ZERO_ADDR, eqAddr } from '../lib/wallet'; import { withNetwork } from '../store/network'; import { compose } from '../lib/lib'; import { withWallet } from '../store/wallet'; import { withPointCache } from '../store/pointCache'; const hasTransferProxy = (cache, point) => point in cache ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR) : false; class Points extends React.Component { constructor(props) { super(props); const { networkType } = props; const loading = networkType !== NETWORK_TYPES.OFFLINE; this.state = { points: [], incoming: [], managing: [], voting: [], spawning: [], eclipticOwner: false, loading: loading, }; } componentDidMount() { const { web3, wallet, contracts, addToPointCache } = this.props; web3.chain(_ => contracts.chain(ctrcs => wallet.chain(async wal => { const addr = wal.address; 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 { history, pointCache } = this.props; const { points, incoming, managing, voting, spawning, loading, 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 network 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 compose( withNetwork, withHistory, withWallet, withPointCache )(Points);