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) => (
45 className={`full half-${(i % 2) + 1}-md half-${(i % 2) + 1}-lg`}>
51 setPointCursor(Just(point));
57 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
66function ActionButtons({ actions = [] }) {
69 {actions.map(action => (
74 onClick={action.onClick}>
82export default function Points() {
83 const { wallet } = useWallet();
84 const { pop, push, popAndPush, names } = useHistory();
85 const { setPointCursor } = usePointCursor();
86 const { controlledPoints, getDetails } = usePointCache();
87 const isEclipticOwner = useIsEclipticOwner();
91 ] = useRejectedIncomingPointTransfers();
93 const maybeOutgoingPoints = useMemo(
95 controlledPoints.chain(points =>
97 Error: () => Nothing(),
99 const points = c.value.ownedPoints.map(point =>
100 getDetails(point).chain(details =>
101 Just({ point: point, has: hasTransferProxy(details) })
104 // if we have details for every point,
105 // return the array of pending transfers.
106 if (points.every(p => Just.hasInstance(p))) {
107 const outgoing = points
108 .filter(p => p.value.has)
109 .map(p => p.value.point);
110 return Just(outgoing);
117 [getDetails, controlledPoints]
120 // if we can only interact with a single point, forget about the existence
121 // of this page and jump to the point page.
122 // if there are any pending transfers, incoming or outgoing, stay on this
123 // page, because those can only be completed/cancelled here.
125 if (Nothing.hasInstance(maybeOutgoingPoints)) {
128 controlledPoints.matchWith({
135 ...c.value.ownedPoints,
136 ...c.value.votingPoints,
137 ...c.value.managingPoints,
138 ...c.value.spawningPoints,
140 const incoming = c.value.incomingPoints.filter(
141 p => !rejectedPoints.includes(p)
145 incoming.length === 0 &&
146 maybeOutgoingPoints.value.length === 0
148 setPointCursor(Just(all[0]));
149 popAndPush(names.POINT);
164 const address = need.addressFromWallet(wallet);
166 const loading = Nothing.hasInstance(controlledPoints);
168 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
169 const incomingPoints = maybeGetResult(
173 ).filter(point => !rejectedPoints.includes(point));
174 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
175 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
176 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
177 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
180 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
186 const displayEmptyState =
187 !loading && incomingPoints.length === 0 && allPoints.length === 0;
189 // sync display details for known points
198 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
203 const goViewPoint = useCallback(() => push(names.VIEW_POINT), [
209 <View pop={pop} inset>
211 <Grid.Item full as={H1} className="f6 mono gray4 mb4">
212 {abbreviateAddress(address)}
216 <Grid.Item full as={HelpText} className="mt8 t-center">
217 <Blinky /> Loading...
221 {displayEmptyState && (
222 <Grid.Item full as={HelpText} className="mt8 t-center">
223 No points to display. This wallet is not the owner or proxy for any
228 {incomingPoints.length > 0 && (
229 <Grid.Item full as={Grid} gap={1} className="mb6">
230 <Grid.Item full as={H5}>
232 incomingPoints.length,
240 points={incomingPoints}
241 actions={(point, i) => (
247 setPointCursor(Just(point));
248 push(names.ACCEPT_TRANSFER);
254 addRejectedPoint(point);
265 {outgoingPoints.length > 0 && (
266 <Grid.Item full as={Grid} gap={1} className="mb6">
267 <Grid.Item full as={H5}>
269 outgoingPoints.length,
277 points={outgoingPoints}
278 actions={(point, i) => (
284 setPointCursor(Just(point));
285 // TODO: deep linking to fix this duplicate route
286 push(names.CANCEL_TRANSFER);
297 {allPoints.length > 0 && (
298 <Grid.Item full as={Grid} gap={1}>
299 <Grid.Item full as={H5}>
300 {pluralize(allPoints.length, 'Point')}
302 <Grid.Item full as={PointList} points={allPoints} />
309 {isEclipticOwner && (
314 detail="You have the authority to create a new Galaxy."
315 onClick={goCreateGalaxy}>
324 detail="View a point"
325 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