1import React, { useCallback, useEffect, useMemo } from 'react';
2import { Just, Nothing, Result } from 'folktale/maybe';
3import { Grid, H5, 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';
10import { useStarReleaseCache } from 'store/starRelease';
12import * as need from 'lib/need';
13import { isZeroAddress, abbreviateAddress } from 'lib/wallet';
14import useIsEclipticOwner from 'lib/useIsEclipticOwner';
15import { useSyncKnownPoints, useSyncOwnedPoints } from 'lib/useSyncPoints';
16import useRejectedIncomingPointTransfers from 'lib/useRejectedIncomingPointTransfers';
17import pluralize from 'lib/pluralize';
18import newGithubIssueUrl from 'new-github-issue-url';
20import View from 'components/View';
21import Blinky from 'components/Blinky';
22import Passport from 'components/Passport';
23import Footer from 'components/Footer';
24import { ForwardButton } from 'components/Buttons';
25import CopiableAddress from 'components/CopiableAddress';
26import NavHeader from 'components/NavHeader';
28const maybeGetResult = (obj, key, defaultValue) =>
30 Nothing: () => defaultValue,
33 Ok: r => get(r.value, key, defaultValue),
34 Error: e => defaultValue,
38const hasTransferProxy = details => !isZeroAddress(details.transferProxy);
40const PointList = function({ points, className, actions, ...rest }) {
41 const { setPointCursor } = usePointCursor();
42 const { push, names } = useHistory();
45 <Grid gap={3} className={className}>
46 {points.map((point, i) => (
49 className={`full half-${(i % 2) + 1}-md half-${(i % 2) + 1}-lg`}>
55 setPointCursor(Just(point));
61 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
70function ActionButtons({ actions = [] }) {
73 {actions.map(action => (
78 onClick={action.onClick}>
86export default function Points() {
87 const { wallet } = useWallet();
88 const { pop, push, popAndPush, names } = useHistory();
89 const { setPointCursor } = usePointCursor();
90 const { controlledPoints, getDetails } = usePointCache();
91 const isEclipticOwner = useIsEclipticOwner();
95 ] = useRejectedIncomingPointTransfers();
96 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
98 const maybeOutgoingPoints = useMemo(
100 controlledPoints.chain(points =>
102 Error: () => Nothing(),
104 const points = c.value.ownedPoints.map(point =>
105 getDetails(point).chain(details =>
106 Just({ point: point, has: hasTransferProxy(details) })
109 // if we have details for every point,
110 // return the array of pending transfers.
111 if (points.every(p => Just.hasInstance(p))) {
112 const outgoing = points
113 .filter(p => p.value.has)
114 .map(p => p.value.point);
115 return Just(outgoing);
122 [getDetails, controlledPoints]
125 // if we can only interact with a single point, forget about the existence
126 // of this page and jump to the point page.
127 // if there are any pending transfers, incoming or outgoing, stay on this
128 // page, because those can only be completed/cancelled here.
131 Nothing.hasInstance(maybeOutgoingPoints) ||
132 Nothing.hasInstance(starReleaseDetails)
136 controlledPoints.matchWith({
143 ...c.value.ownedPoints,
144 ...c.value.votingPoints,
145 ...c.value.managingPoints,
146 ...c.value.spawningPoints,
148 const incoming = c.value.incomingPoints.filter(
149 p => !rejectedPoints.includes(p)
153 incoming.length === 0 &&
154 maybeOutgoingPoints.value.length === 0 &&
155 starReleaseDetails.value.total === 0
157 setPointCursor(Just(all[0]));
158 popAndPush(names.POINT);
174 const address = need.addressFromWallet(wallet);
176 const loading = Nothing.hasInstance(controlledPoints);
178 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
179 const incomingPoints = maybeGetResult(
183 ).filter(point => !rejectedPoints.includes(point));
184 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
185 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
186 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
187 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
190 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
196 const displayEmptyState =
197 !loading && incomingPoints.length === 0 && allPoints.length === 0;
199 const starReleasing = starReleaseDetails
200 .map(s => s.total > 0)
204 syncStarReleaseDetails();
205 }, [syncStarReleaseDetails]);
206 // sync display details for known points
215 useSyncOwnedPoints(ownedPoints);
217 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
222 const goStarRelease = useCallback(() => push(names.STAR_RELEASE), [
227 // if we got an error result, we should display it, instead of showing
228 // a potentially inaccurately empty point list.
231 Just.hasInstance(controlledPoints) &&
232 controlledPoints.value.matchWith({
237 const url = newGithubIssueUrl({
240 title: controlledPoints.value.value,
241 body: `<!-- Please provide some context. Do you have Metamask installed? What login method did you use? -->`,
246 <Grid.Item full as={HelpText} className="mt8 t-center">
247 {controlledPoints.value.value}
249 Try reloading the page. If this problem persists, please{' '}
250 <a href={url}>file an issue on GitHub</a>.
259 (allPoints.length === 1 &&
260 incomingPoints.length === 0 &&
261 outgoingPoints.length === 0 &&
267 <Grid.Item full as={HelpText} className="mt8 t-center">
268 <Blinky /> Loading...
276 <View inset pop={pop} hideBack>
280 className="f6 mono gray4 mb4 us-none pointer">
281 {abbreviateAddress(address)}
285 {displayEmptyState && (
286 <Grid.Item full as={HelpText} className="mt8 t-center">
287 No points to display. This wallet is not the owner or proxy for any
292 {incomingPoints.length > 0 && (
293 <Grid.Item full as={Grid} gap={1} className="mb6">
294 <Grid.Item full as={H5}>
296 incomingPoints.length,
304 points={incomingPoints}
305 actions={(point, i) => (
311 setPointCursor(Just(point));
312 push(names.ACCEPT_TRANSFER);
318 addRejectedPoint(point);
329 {outgoingPoints.length > 0 && (
330 <Grid.Item full as={Grid} gap={1} className="mb6">
331 <Grid.Item full as={H5}>
333 outgoingPoints.length,
341 points={outgoingPoints}
342 actions={(point, i) => (
348 setPointCursor(Just(point));
349 // TODO: deep linking to fix this duplicate route
350 push(names.CANCEL_TRANSFER);
361 {allPoints.length > 0 && (
362 <Grid.Item full as={Grid} gap={1}>
363 <Grid.Item full as={H5}>
364 {pluralize(allPoints.length, 'ID')}
366 <Grid.Item full as={PointList} points={allPoints} />
373 {isEclipticOwner && (
378 detail="You have the authority to create a new Galaxy."
379 onClick={goCreateGalaxy}>
390 detail="You have points being released"
391 onClick={goStarRelease}>
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