@@ -1,245 +1,159 @@
1import React from 'react';
1import React from 'react';
2−import { H1, H2, P } from '../components/old/Base';
2+import Maybe from 'folktale/maybe';
3−import { Button } from '../components/old/Base';
3+import { H1, H2, P, Grid } from 'indigo-react';
4−import * as azimuth from 'azimuth-js';
4+
6−import PointList from '../components/old/PointList';
7−import { NETWORK_TYPES } from '../lib/network';
8−import { ROUTE_NAMES } from '../lib/routeNames';
5+import { ROUTE_NAMES } from 'lib/routeNames';
9−import { withHistory } from '../store/history';
10−import { ETH_ZERO_ADDR, eqAddr } from '../lib/wallet';
6+import { ETH_ZERO_ADDR, eqAddr } from 'lib/wallet';
11−import { withNetwork } from '../store/network';
7+import useIsEclipticOwner from 'lib/useIsEclipticOwner';
12−import { compose } from '../lib/lib';
8+import { useSyncKnownPoints } from 'lib/useSyncPoints';
10+import { useHistory } from 'store/history';
13−import { withWallet } from '../store/wallet';
11+import { useWallet } from 'store/wallet';
14−import { withPointCache } from '../store/pointCache';
12+import { usePointCache } from 'store/pointCache';
14+import PointList from 'components/old/PointList';
15import View from 'components/View';
15import View from 'components/View';
16−import { Grid } from 'indigo-react';
16+import { ForwardButton } from 'components/Buttons';
17−
17+import useLifecycle from 'lib/useLifecycle';
19+const matchArray = obj =>
20+ obj.matchWith({ Nothing: () => [], Just: p => p.value });
18−const hasTransferProxy = (cache, point) =>
22+const hasTransferProxy = (details, point) =>
19− point in cache ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR) : false;
23+ !eqAddr(details.transferProxy, ETH_ZERO_ADDR);
21−class Points extends React.Component {
25+export default function Points() {
22− constructor(props) {
26+ const { wallet } = useWallet();
25− const { networkType } = props;
26− const loading = networkType !== NETWORK_TYPES.OFFLINE;
34− eclipticOwner: false,
39− componentDidMount() {
40− const { web3, wallet, contracts, addToPointCache } = this.props;
43− contracts.chain(ctrcs =>
44− wallet.chain(async wal => {
45− const addr = wal.address;
47− const points = await azimuth.azimuth.getOwnedPoints(ctrcs, addr);
49− const incoming = await azimuth.azimuth.getTransferringFor(
54− const managing = await azimuth.azimuth.getManagerFor(ctrcs, addr);
56− const voting = await azimuth.azimuth.getVotingFor(ctrcs, addr);
58− const spawning = await azimuth.azimuth.getSpawningFor(ctrcs, addr);
60− const owner = await azimuth.ecliptic.owner(ctrcs);
62− const eclipticOwner = eqAddr(addr, owner);
74− this.cachePoints(ctrcs, addToPointCache, points);
80− cachePoints(contracts, addToPointCache, points) {
81− points.forEach(point => {
83− .getPoint(contracts, point)
84− .then(details => addToPointCache({ [point]: details }));
89− const { history, pointCache } = this.props;
27+ const history = useHistory();
91− const {
29+ getControlledPoints,
92− points,
30+ syncControlledPoints,
39+ } = getControlledPoints(wallet);
40+ const isEclipticOwner = useIsEclipticOwner();
42+ const owned = matchArray(ownedPoints);
43+ const incoming = matchArray(incomingPoints);
44+ const managing = matchArray(managingPoints);
45+ const voting = matchArray(votingPoints);
46+ const spawning = matchArray(spawningPoints);
48+ // sync controlled points on mount
50+ syncControlledPoints();
53+ // sync display details for known points
93− incoming,
56+ ...incoming,
94− managing,
57+ ...managing,
95− voting,
58+ ...voting,
96− spawning,
59+ ...spawning,
99− } = this.state;
62+ const loading = Maybe.Nothing.hasInstance(ownedPoints);
101− const lookupPointButton = (
64+ const outgoing = ownedPoints.filter(point =>
65+ getDetails(point).matchWith({
66+ Nothing: () => false,
67+ Just: p => hasTransferProxy(p.value),
76+ A point is an identity on the Ethereum blockchain. Points declare keys
77+ for ships on the Arvo network.
103 <Grid.Item full>
81 <Grid.Item full>
104− <Button
82+ <ForwardButton
105− prop-type={'link'}
83+ detail="View a point on Azimuth"
107 onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
84 onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
108− {'View a point →'}
85+ View a point
109− </Button>
86+ </ForwardButton>
110− <P>{'View a point on Azimuth.'}</P>
111 </Grid.Item>
87 </Grid.Item>
115− const createGalaxyButton =
90+ {isEclipticOwner && (
116− eclipticOwner === false ? (
120 <Grid.Item full>
92 <Grid.Item full>
121− <Button
93+ <ForwardButton
122− prop-type={'link'}
94+ detail="You have the authority to create a new Galaxy."
124 onClick={() => history.push(ROUTE_NAMES.CREATE_GALAXY)}>
95 onClick={() => history.push(ROUTE_NAMES.CREATE_GALAXY)}>
125− {'Create a galaxy →'}
96+ Create a galaxy
126− </Button>
97+ </ForwardButton>
129− 'You have the authority to create a new Galaxy and you can do so here.'
132 </Grid.Item>
98 </Grid.Item>
136− const outgoing = points.filter(point =>
137− hasTransferProxy(pointCache, point)
140− const outgoingPoints =
141− outgoing.length !== 0 ? (
102+ {incoming.length > 0 && (
142− <React.Fragment>
103+ <>
143− <H2>{'Outgoing Transfers'}</H2>
104+ <H2>Incoming Transfers</H2>
145− {`You own these points until the recipient accepts the incoming
106+ You do not own these points until you accept the incoming transfer.
146− transfer. You may cancel the transfer until accepted.`}
107+ You may reject any incoming transfers.
148− <PointList routeHandler={history.push} points={outgoing} />
109+ <PointList routeHandler={history.push} points={incoming} />
149− </React.Fragment>
110+ </>
154− const incomingPoints =
155− incoming.length !== 0 ? (
113+ {outgoing.length > 0 && (
156− <React.Fragment>
114+ <>
157− <H2>{'Incoming Transfers'}</H2>
115+ <H2>Outgoing Transfers</H2>
159− {`You do not own these points until you accept the incoming transfer.
117+ You own these points until the recipient accepts the incoming
160− You may reject any incoming transfers.`}
118+ transfer. You may cancel the transfer until accepted.
162− <PointList routeHandler={history.push} points={incoming} />
120+ <PointList routeHandler={history.push} points={outgoing} />
163− </React.Fragment>
121+ </>
166− );
124+ <H2>Your Points</H2>
168− const managingPoints =
126+ <PointList routeHandler={history.push} points={owned} loading={loading} />
169− managing.length !== 0 ? (
128+ {managing.length > 0 && (
170− <React.Fragment>
129+ <>
171− <H2>{'You Are a Management Proxy For'}</H2>
130+ <H2>You Are a Management Proxy For</H2>
173− {`You can configure or set network keys and conduct sponsorship
132+ You can configure or set network keys and conduct sponsorship
174− related operations for these points.`}
133+ related operations for these points.
176 <PointList routeHandler={history.push} points={managing} />
135 <PointList routeHandler={history.push} points={managing} />
177− </React.Fragment>
136+ </>
182− const votingPoints =
183− voting.length !== 0 ? (
139+ {voting.length > 0 && (
184− <React.Fragment>
140+ <>
185− <H2>{'You Are a Voting Proxy For'}</H2>
141+ <H2>You Are a Voting Proxy For</H2>
187− {`Since you are part of the Galactic Senate, you can cast votes on
143+ Since you are part of the Galactic Senate, you can cast votes on new
188− new Azimuth proposals on behalf of these points.`}
144+ Azimuth proposals on behalf of these points.
190 <PointList routeHandler={history.push} points={voting} />
146 <PointList routeHandler={history.push} points={voting} />
191− </React.Fragment>
147+ </>
196− const spawningPoints =
197− spawning.length !== 0 ? (
199− <H2>{'You Are a Spawn Proxy For'}</H2>
200− <P>{`You can create new child ships under these points.`}</P>
201− <PointList routeHandler={history.push} points={spawning} />
211− <P>{`A point is an identity on the Ethereum blockchain.
212− Points declare keys for ships on the Arvo network.`}</P>
216− {createGalaxyButton}
222− <H2>{'Your Points'}</H2>
150+ {spawning.length > 0 && (
224− <PointList
152+ <H2>You Are a Spawn Proxy For</H2>
153+ <P>You can create new child points under these points.</P>
225− routeHandler={history.push}
154+ <PointList routeHandler={history.push} points={spawning} />
226− points={points}
155+ </>
227− loading={loading}
156+ )}
240−export default compose(