1import React, { useCallback, useEffect, useMemo } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, H5, H1, HelpText, LinkButton, Flex } from 'indigo-react';
4import { get } from 'lodash';
6import { useHistory } from 'store/history';
7import { useWallet } from 'store/wallet';
8import { usePointCache } from 'store/pointCache';
9import { usePointCursor } from 'store/pointCursor';
11import * as need from 'lib/need';
12import { isZeroAddress, abbreviateAddress } from 'lib/wallet';
13import useIsEclipticOwner from 'lib/useIsEclipticOwner';
14import { useSyncKnownPoints, useSyncOwnedPoints } from 'lib/useSyncPoints';
15import useRejectedIncomingPointTransfers from 'lib/useRejectedIncomingPointTransfers';
16import pluralize from 'lib/pluralize';
18import View from 'components/View';
19import Blinky from 'components/Blinky';
20import Passport from 'components/Passport';
21import Footer from 'components/Footer';
22import { ForwardButton } from 'components/Buttons';
23import CopiableAddress from 'components/CopiableAddress';
24import NavHeader from 'components/NavHeader';
26const maybeGetResult = (obj, key, defaultValue) =>
28 Nothing: () => defaultValue,
31 Ok: r => get(r.value, key, defaultValue),
32 Error: e => defaultValue,
36const hasTransferProxy = details => !isZeroAddress(details.transferProxy);
38const PointList = function({ points, className, actions, ...rest }) {
39 const { setPointCursor } = usePointCursor();
40 const { push, names } = useHistory();
43 <Grid gap={3} className={className}>
44 {points.map((point, i) => (
47 className={`full half-${(i % 2) + 1}-md half-${(i % 2) + 1}-lg`}>
53 setPointCursor(Just(point));
59 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
68function ActionButtons({ actions = [] }) {
71 {actions.map(action => (
76 onClick={action.onClick}>
84export default function Points() {
85 const { wallet } = useWallet();
86 const { pop, push, popAndPush, names } = useHistory();
87 const { setPointCursor } = usePointCursor();
88 const { controlledPoints, getDetails } = usePointCache();
89 const isEclipticOwner = useIsEclipticOwner();
93 ] = useRejectedIncomingPointTransfers();
95 const maybeOutgoingPoints = useMemo(
97 controlledPoints.chain(points =>
99 Error: () => Nothing(),
101 const points = c.value.ownedPoints.map(point =>
102 getDetails(point).chain(details =>
103 Just({ point: point, has: hasTransferProxy(details) })
106 // if we have details for every point,
107 // return the array of pending transfers.
108 if (points.every(p => Just.hasInstance(p))) {
109 const outgoing = points
110 .filter(p => p.value.has)
111 .map(p => p.value.point);
112 return Just(outgoing);
119 [getDetails, controlledPoints]
122 // if we can only interact with a single point, forget about the existence
123 // of this page and jump to the point page.
124 // if there are any pending transfers, incoming or outgoing, stay on this
125 // page, because those can only be completed/cancelled here.
127 if (Nothing.hasInstance(maybeOutgoingPoints)) {
130 controlledPoints.matchWith({
137 ...c.value.ownedPoints,
138 ...c.value.votingPoints,
139 ...c.value.managingPoints,
140 ...c.value.spawningPoints,
142 const incoming = c.value.incomingPoints.filter(
143 p => !rejectedPoints.includes(p)
147 incoming.length === 0 &&
148 maybeOutgoingPoints.value.length === 0
150 setPointCursor(Just(all[0]));
151 popAndPush(names.POINT);
166 const address = need.addressFromWallet(wallet);
168 const loading = Nothing.hasInstance(controlledPoints);
170 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
171 const incomingPoints = maybeGetResult(
175 ).filter(point => !rejectedPoints.includes(point));
176 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
177 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
178 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
179 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
182 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
188 const displayEmptyState =
189 !loading && incomingPoints.length === 0 && allPoints.length === 0;
191 // sync display details for known points
200 useSyncOwnedPoints(ownedPoints);
202 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
207 const goViewPoint = useCallback(() => push(names.VIEW_POINT), [
214 (allPoints.length === 1 &&
215 incomingPoints.length === 0 &&
216 outgoingPoints.length === 0)
219 <View inset pop={pop}>
221 <Grid.Item full as={HelpText} className="mt8 t-center">
222 <Blinky /> Loading...
230 <View pop={pop} inset>
234 className="f6 mono gray4 mb4 us-none pointer">
235 {abbreviateAddress(address)}
239 {displayEmptyState && (
240 <Grid.Item full as={HelpText} className="mt8 t-center">
241 No points to display. This wallet is not the owner or proxy for any
246 {incomingPoints.length > 0 && (
247 <Grid.Item full as={Grid} gap={1} className="mb6">
248 <Grid.Item full as={H5}>
250 incomingPoints.length,
258 points={incomingPoints}
259 actions={(point, i) => (
265 setPointCursor(Just(point));
266 push(names.ACCEPT_TRANSFER);
272 addRejectedPoint(point);
283 {outgoingPoints.length > 0 && (
284 <Grid.Item full as={Grid} gap={1} className="mb6">
285 <Grid.Item full as={H5}>
287 outgoingPoints.length,
295 points={outgoingPoints}
296 actions={(point, i) => (
302 setPointCursor(Just(point));
303 // TODO: deep linking to fix this duplicate route
304 push(names.CANCEL_TRANSFER);
315 {allPoints.length > 0 && (
316 <Grid.Item full as={Grid} gap={1}>
317 <Grid.Item full as={H5}>
318 {pluralize(allPoints.length, 'ID')}
320 <Grid.Item full as={PointList} points={allPoints} />
327 {isEclipticOwner && (
332 detail="You have the authority to create a new Galaxy."
333 onClick={goCreateGalaxy}>
343 onClick={goViewPoint}>
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list