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';
16import View from 'components/View';
17import Blinky from 'components/Blinky';
18import Passport from 'components/Passport';
19import useRejectedIncomingPointTransfers from 'lib/useRejectedIncomingPointTransfers';
20import pluralize from 'lib/pluralize';
21import Footer from 'components/Footer';
22import { ForwardButton } from 'components/Buttons';
24const maybeGetResult = (obj, key, defaultValue) =>
26 Nothing: () => defaultValue,
29 Ok: r => get(r.value, key, defaultValue),
30 Error: e => defaultValue,
34const hasTransferProxy = details => !isZeroAddress(details.transferProxy);
36const PointList = function({ points, className, actions, ...rest }) {
37 const { setPointCursor } = usePointCursor();
38 const { push, names } = useHistory();
41 <Grid gap={3} className={className}>
42 {points.map((point, i) => (
43 <Grid.Item half={(i % 2) + 1} key={point}>
49 setPointCursor(Just(point));
55 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
64function ActionButtons({ actions = [] }) {
67 {actions.map(action => (
72 onClick={action.onClick}>
80export default function Points() {
81 const { wallet } = useWallet();
82 const { pop, push, popAndPush, names } = useHistory();
83 const { setPointCursor } = usePointCursor();
84 const { controlledPoints, getDetails } = usePointCache();
85 const isEclipticOwner = useIsEclipticOwner();
89 ] = useRejectedIncomingPointTransfers();
91 const maybeOutgoingPoints = useMemo(
93 controlledPoints.chain(points =>
95 Error: () => Nothing(),
97 const points = c.value.ownedPoints.map(point =>
98 getDetails(point).chain(details =>
99 Just({ point: point, has: hasTransferProxy(details) })
102 // if we have details for every point,
103 // return the array of pending transfers.
104 if (points.every(p => Just.hasInstance(p))) {
105 const outgoing = points
106 .filter(p => p.value.has)
107 .map(p => p.value.point);
108 return Just(outgoing);
115 [getDetails, controlledPoints]
118 // if we can only interact with a single point, forget about the existence
119 // of this page and jump to the point page.
120 // if there are any pending transfers, incoming or outgoing, stay on this
121 // page, because those can only be completed/cancelled here.
123 if (Nothing.hasInstance(maybeOutgoingPoints)) {
126 controlledPoints.matchWith({
133 ...c.value.ownedPoints,
134 ...c.value.votingPoints,
135 ...c.value.managingPoints,
136 ...c.value.spawningPoints,
138 const incoming = c.value.incomingPoints.filter(
139 p => !rejectedPoints.includes(p)
143 incoming.length === 0 &&
144 maybeOutgoingPoints.value.length === 0
146 setPointCursor(Just(all[0]));
147 popAndPush(names.POINT);
162 const address = need.addressFromWallet(wallet);
164 const loading = Nothing.hasInstance(controlledPoints);
166 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
167 const incomingPoints = maybeGetResult(
171 ).filter(point => !rejectedPoints.includes(point));
172 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
173 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
174 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
175 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
178 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
184 const displayEmptyState =
185 !loading && incomingPoints.length === 0 && allPoints.length === 0;
187 // sync display details for known points
196 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
201 const goViewPoint = useCallback(() => push(names.VIEW_POINT), [
207 <View pop={pop} inset>
209 <Grid.Item full as={H1} className="f6 mono gray4 mb4">
210 {abbreviateAddress(address)}
214 <Grid.Item full as={HelpText} className="mt8 t-center">
215 <Blinky /> Loading...
219 {displayEmptyState && (
220 <Grid.Item full as={HelpText} className="mt8 t-center">
221 No points to display. This wallet is not the owner or proxy for any
226 {incomingPoints.length > 0 && (
227 <Grid.Item full as={Grid} gap={1} className="mb6">
228 <Grid.Item full as={H5}>
230 incomingPoints.length,
238 points={incomingPoints}
239 actions={(point, i) => (
245 setPointCursor(Just(point));
246 push(names.ACCEPT_TRANSFER);
252 addRejectedPoint(point);
263 {outgoingPoints.length > 0 && (
264 <Grid.Item full as={Grid} gap={1} className="mb6">
265 <Grid.Item full as={H5}>
267 outgoingPoints.length,
275 points={outgoingPoints}
276 actions={(point, i) => (
282 setPointCursor(Just(point));
283 // TODO: deep linking to fix this duplicate route
284 push(names.CANCEL_TRANSFER);
295 {allPoints.length > 0 && (
296 <Grid.Item full as={Grid} gap={1}>
297 <Grid.Item full as={H5}>
298 {pluralize(allPoints.length, 'Point')}
300 <Grid.Item full as={PointList} points={allPoints} />
307 {isEclipticOwner && (
312 detail="You have the authority to create a new Galaxy."
313 onClick={goCreateGalaxy}>
322 detail="View a point"
323 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