@@ -1,186 +1,219 @@
1import React from 'react';
1import React from 'react';
2import { Just, Nothing } from 'folktale/maybe';
2import { Just, Nothing } from 'folktale/maybe';
3−import { H1, H2, P, Grid } from 'indigo-react';
3+import { Grid, H5, H1, HelpText, LinkButton, Flex } from 'indigo-react';
5−import { ROUTE_NAMES } from 'lib/routeNames';
6−import { isZeroAddress } from 'lib/wallet';
7−import useIsEclipticOwner from 'lib/useIsEclipticOwner';
8−import { useSyncKnownPoints } from 'lib/useSyncPoints';
10import { useHistory } from 'store/history';
5import { useHistory } from 'store/history';
11import { useWallet } from 'store/wallet';
6import { useWallet } from 'store/wallet';
12import { usePointCache } from 'store/pointCache';
7import { usePointCache } from 'store/pointCache';
8+import { usePointCursor } from 'store/pointCursor';
10+import * as need from 'lib/need';
11+import { ROUTE_NAMES } from 'lib/routeNames';
12+import { isZeroAddress, abbreviateAddress } from 'lib/wallet';
13+import useIsEclipticOwner from 'lib/useIsEclipticOwner';
14+import { useSyncKnownPoints } from 'lib/useSyncPoints';
14import View from 'components/View';
16import View from 'components/View';
15−import { ForwardButton } from 'components/Buttons';
17+import FooterButton from 'components/FooterButton';
16−import useLifecycle from 'lib/useLifecycle';
18+import Blinky from 'components/Blinky';
19+import Passport from 'components/Passport';
20+import useRejectedIncomingPointTransfers from 'lib/useRejectedIncomingPointTransfers';
22+const getFromMaybe = (obj, key, defaultValue) =>
24+ Nothing: () => defaultValue,
27+ Ok: r => r.value[key],
28+ Error: e => defaultValue,
18−//TODO new component
32+const hasTransferProxy = (details, point) =>
19−import { usePointCursor } from 'store/pointCursor';
33+ !isZeroAddress(details.transferProxy);
20−import * as ob from 'urbit-ob';
34+
21−const PointList = function(props) {
35+const PointList = function({ points, className, actions, ...rest }) {
22 const { setPointCursor } = usePointCursor();
36 const { setPointCursor } = usePointCursor();
23 const history = useHistory();
37 const history = useHistory();
24− const { points, loading } = props;
38+
26− return points.length === 0 ? (
39+ return (
27− <p>{loading ? 'Loading...' : 'No points to display'}</p>
40+ <Grid gap={3} className={className}>
30− {points.map(point => (
41+ {points.map((point, i) => (
32− key={point}
42+ <Grid.Item half={(i % 2) + 1} key={point}>
46+ className="clickable"
33− onClick={() => {
47+ onClick={() => {
34− setPointCursor(Just(point));
48+ setPointCursor(Just(point));
35− history.push(ROUTE_NAMES.POINT);
49+ history.push(history.names.POINT);
37− {ob.patp(point)}
51+ {...rest}
54+ <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
44−const matchArray = obj =>
63+function ActionButtons({ actions = [] }) {
45− obj.matchWith({ Nothing: () => [], Just: p => p.value });
64+ return (
47−const hasTransferProxy = (details, point) =>
66+ {actions.map(action => (
48− !isZeroAddress(details.transferProxy);
67+ <Flex.Item
71+ onClick={action.onClick}>
50export default function Points() {
79export default function Points() {
51 const { wallet } = useWallet();
80 const { wallet } = useWallet();
52 const history = useHistory();
81 const history = useHistory();
53− const {
82+ const { setPointCursor } = usePointCursor();
55− syncControlledPoints,
57− } = usePointCache();
83+ const { controlledPoints, getDetails } = usePointCache();
64− } = getControlledPoints(wallet);
65 const isEclipticOwner = useIsEclipticOwner();
84 const isEclipticOwner = useIsEclipticOwner();
67− const owned = matchArray(ownedPoints);
86+ rejectedPoints,
68− const incoming = matchArray(incomingPoints);
87+ addRejectedPoint,
69− const managing = matchArray(managingPoints);
88+ ] = useRejectedIncomingPointTransfers();
70− const voting = matchArray(votingPoints);
89+
71− const spawning = matchArray(spawningPoints);
90+ const address = need.addressFromWallet(wallet);
73− // sync controlled points on mount
75− syncControlledPoints();
78− // sync display details for known points
87− const loading = Nothing.hasInstance(ownedPoints);
92+ const loading = Nothing.hasInstance(controlledPoints);
94+ const ownedPoints = getFromMaybe(controlledPoints, 'ownedPoints', []);
95+ const incomingPoints = getFromMaybe(
99+ ).filter(point => !rejectedPoints.includes(point));
100+ const managingPoints = getFromMaybe(controlledPoints, 'managingPoints', []);
101+ const votingPoints = getFromMaybe(controlledPoints, 'votingPoints', []);
102+ const spawningPoints = getFromMaybe(controlledPoints, 'spawningPoints', []);
89− const outgoing = ownedPoints.filter(point =>
103+ const outgoingPoints = ownedPoints.filter(point =>
90 getDetails(point).matchWith({
104 getDetails(point).matchWith({
91 Nothing: () => false,
105 Nothing: () => false,
92 Just: p => hasTransferProxy(p.value),
106 Just: p => hasTransferProxy(p.value),
110+ const multipassPoints = [
117+ // sync display details for known points
118+ useSyncKnownPoints([
101− A point is an identity on the Ethereum blockchain. Points declare keys
102− for ships on the Arvo network.
105− <Grid>
128+ <Grid className="mt6">
107− <Grid.Item full>
129+ <Grid.Item full as={H1} className="f6 mono gray4 mb4">
108− <ForwardButton
130+ {abbreviateAddress(address)}
109− detail="View a point on Azimuth"
110− onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
113 </Grid.Item>
131 </Grid.Item>
114− <Grid.Divider />
132+
115− {isEclipticOwner && (
133+ {loading && (
116− <>
134+ <Grid.Item full as={HelpText} className="mt8 t-center">
117− <Grid.Item full>
135+ <Blinky /> Loading...
118− <ForwardButton
136+ </Grid.Item>
119− detail="You have the authority to create a new Galaxy."
137+ )}
120− onClick={() => history.push(ROUTE_NAMES.CREATE_GALAXY)}>
138+
121− Create a galaxy
139+ {incomingPoints.length > 0 && (
122− </ForwardButton>
140+ <Grid.Item full as={Grid} gap={1} className="mb6">
141+ <Grid.Item full as={H5}>
123 </Grid.Item>
143 </Grid.Item>
124− <Grid.Divider />
144+ <Grid.Item
147+ points={incomingPoints}
148+ actions={(point, i) => (
154+ setPointCursor(Just(point));
155+ history.push(history.names.ACCEPT_TRANSFER);
161+ addRejectedPoint(point);
172+ {outgoingPoints.length > 0 && (
173+ <Grid.Item full as={Grid} gap={1} className="mb6">
174+ <Grid.Item full as={H5}>
180+ points={outgoingPoints}
181+ actions={(point, i) => (
187+ setPointCursor(Just(point));
188+ // TODO: deep linking to fix this duplicate route
189+ history.push(history.names.CANCEL_TRANSFER);
129− {incoming.length > 0 && (
200+ {multipassPoints.length > 0 && (
130− <>
201+ <Grid.Item full as={Grid} gap={1}>
131− <H2>Incoming Transfers</H2>
202+ <Grid.Item full as={H5}>
133− You do not own these points until you accept the incoming transfer.
204+ </Grid.Item>
134− You may reject any incoming transfers.
205+ <Grid.Item full as={PointList} points={multipassPoints} />
135− </P>
206+ </Grid.Item>
136− <PointList routeHandler={history.push} points={incoming} />
140− {outgoing.length > 0 && (
142− <H2>Outgoing Transfers</H2>
144− You own these points until the recipient accepts the incoming
145− transfer. You may cancel the transfer until accepted.
147− <PointList routeHandler={history.push} points={outgoing} />
151− <H2>Your Points</H2>
153− <PointList routeHandler={history.push} points={owned} loading={loading} />
155− {managing.length > 0 && (
157− <H2>You Are a Management Proxy For</H2>
159− You can configure or set network keys and conduct sponsorship
160− related operations for these points.
162− <PointList routeHandler={history.push} points={managing} />
166− {voting.length > 0 && (
209+ {isEclipticOwner && (
167− <>
210+ <FooterButton
168− <H2>You Are a Voting Proxy For</H2>
211+ detail="You have the authority to create a new Galaxy."
169− <P>
212+ onClick={() => history.push(ROUTE_NAMES.CREATE_GALAXY)}>
170− Since you are part of the Galactic Senate, you can cast votes on new
213+ Create a galaxy
171− Azimuth proposals on behalf of these points.
214+ </FooterButton>
173− <PointList routeHandler={history.push} points={voting} />
216+ </Grid>
177− {spawning.length > 0 && (
179− <H2>You Are a Spawn Proxy For</H2>
180− <P>You can create new child points under these points.</P>
181− <PointList routeHandler={history.push} points={spawning} />