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.'}
{ 'You have the authority to create a new Galaxy and you can do so here.' }
{`You own these points until the recipient accepts the incoming transfer. You may cancel the transfer until accepted.`}
{`You do not own these points until you accept the incoming transfer. You may reject any incoming transfers.`}
{`You can configure or set network keys and conduct sponsorship related operations for these points.`}
{`Since you are part of the Galactic Senate, you can cast votes on new Azimuth proposals on behalf of these points.`}
{`You can create new child ships under these points.`}
{`A point is an identity on the Ethereum blockchain. Points declare keys for ships on the Arvo network.`}
{lookupPointButton} {createGalaxyButton} {incomingPoints} {outgoingPoints}