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 } 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';
25const maybeGetResult = (obj, key, defaultValue) =>
27 Nothing: () => defaultValue,
30 Ok: r => get(r.value, key, defaultValue),
31 Error: e => defaultValue,
35const hasTransferProxy = details => !isZeroAddress(details.transferProxy);
37const PointList = function({ points, className, actions, ...rest }) {
38 const { setPointCursor } = usePointCursor();
39 const { push, names } = useHistory();
42 <Grid gap={3} className={className}>
43 {points.map((point, i) => (
46 className={`full half-${(i % 2) + 1}-md half-${(i % 2) + 1}-lg`}>
52 setPointCursor(Just(point));
58 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
67function ActionButtons({ actions = [] }) {
70 {actions.map(action => (
75 onClick={action.onClick}>
83export default function Points() {
84 const { wallet } = useWallet();
85 const { pop, push, popAndPush, names } = useHistory();
86 const { setPointCursor } = usePointCursor();
87 const { controlledPoints, getDetails } = usePointCache();
88 const isEclipticOwner = useIsEclipticOwner();
92 ] = useRejectedIncomingPointTransfers();
94 const maybeOutgoingPoints = useMemo(
96 controlledPoints.chain(points =>
98 Error: () => Nothing(),
100 const points = c.value.ownedPoints.map(point =>
101 getDetails(point).chain(details =>
102 Just({ point: point, has: hasTransferProxy(details) })
105 // if we have details for every point,
106 // return the array of pending transfers.
107 if (points.every(p => Just.hasInstance(p))) {
108 const outgoing = points
109 .filter(p => p.value.has)
110 .map(p => p.value.point);
111 return Just(outgoing);
118 [getDetails, controlledPoints]
121 // if we can only interact with a single point, forget about the existence
122 // of this page and jump to the point page.
123 // if there are any pending transfers, incoming or outgoing, stay on this
124 // page, because those can only be completed/cancelled here.
126 if (Nothing.hasInstance(maybeOutgoingPoints)) {
129 controlledPoints.matchWith({
136 ...c.value.ownedPoints,
137 ...c.value.votingPoints,
138 ...c.value.managingPoints,
139 ...c.value.spawningPoints,
141 const incoming = c.value.incomingPoints.filter(
142 p => !rejectedPoints.includes(p)
146 incoming.length === 0 &&
147 maybeOutgoingPoints.value.length === 0
149 setPointCursor(Just(all[0]));
150 popAndPush(names.POINT);
165 const address = need.addressFromWallet(wallet);
167 const loading = Nothing.hasInstance(controlledPoints);
169 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
170 const incomingPoints = maybeGetResult(
174 ).filter(point => !rejectedPoints.includes(point));
175 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
176 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
177 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
178 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
181 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
187 const displayEmptyState =
188 !loading && incomingPoints.length === 0 && allPoints.length === 0;
190 // sync display details for known points
199 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
204 const goViewPoint = useCallback(() => push(names.VIEW_POINT), [
210 <View pop={pop} inset>
212 <Grid.Item full as={H1} className="f6 mono gray4 mb4 us-none pointer">
213 <CopiableAddress text={address}>
214 {abbreviateAddress(address)}
219 <Grid.Item full as={HelpText} className="mt8 t-center">
220 <Blinky /> Loading...
224 {displayEmptyState && (
225 <Grid.Item full as={HelpText} className="mt8 t-center">
226 No points to display. This wallet is not the owner or proxy for any
231 {incomingPoints.length > 0 && (
232 <Grid.Item full as={Grid} gap={1} className="mb6">
233 <Grid.Item full as={H5}>
235 incomingPoints.length,
243 points={incomingPoints}
244 actions={(point, i) => (
250 setPointCursor(Just(point));
251 push(names.ACCEPT_TRANSFER);
257 addRejectedPoint(point);
268 {outgoingPoints.length > 0 && (
269 <Grid.Item full as={Grid} gap={1} className="mb6">
270 <Grid.Item full as={H5}>
272 outgoingPoints.length,
280 points={outgoingPoints}
281 actions={(point, i) => (
287 setPointCursor(Just(point));
288 // TODO: deep linking to fix this duplicate route
289 push(names.CANCEL_TRANSFER);
300 {allPoints.length > 0 && (
301 <Grid.Item full as={Grid} gap={1}>
302 <Grid.Item full as={H5}>
303 {pluralize(allPoints.length, 'Point')}
305 <Grid.Item full as={PointList} points={allPoints} />
312 {isEclipticOwner && (
317 detail="You have the authority to create a new Galaxy."
318 onClick={goCreateGalaxy}>
327 detail="View a point"
328 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