1import React, { useCallback, useEffect, useMemo } from 'react';
2import { Just, Nothing } 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/utils/address';
14import useIsEclipticOwner from 'lib/useIsEclipticOwner';
15import { useSyncDetails } 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 === null ||
156 starReleaseDetails.value.total === 0)
158 setPointCursor(Just(all[0]));
159 popAndPush(names.POINT);
175 const address = need.addressFromWallet(wallet);
177 const loading = Nothing.hasInstance(controlledPoints);
179 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
180 const incomingPoints = maybeGetResult(
184 ).filter(point => !rejectedPoints.includes(point));
185 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
186 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
187 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
188 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
191 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
197 const displayEmptyState =
198 !loading && incomingPoints.length === 0 && allPoints.length === 0;
200 const starReleasing = starReleaseDetails
201 .map(s => (s ? s.total > 0 : false))
205 syncStarReleaseDetails();
206 }, [syncStarReleaseDetails]);
208 // sync display details for known points
209 useSyncDetails(ownedPoints);
211 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
216 const goStarRelease = useCallback(() => push(names.STAR_RELEASE), [
221 // if we got an error result, we should display it, instead of showing
222 // a potentially inaccurately empty point list.
225 Just.hasInstance(controlledPoints) &&
226 controlledPoints.value.matchWith({
231 const url = newGithubIssueUrl({
234 title: controlledPoints.value.value,
235 body: `<!-- Please provide some context. Do you have Metamask installed? What login method did you use? -->`,
240 <Grid.Item full as={HelpText} className="mt8 t-center">
241 {controlledPoints.value.value}
243 Try reloading the page. If this problem persists, please{' '}
244 <a href={url}>file an issue on GitHub</a>.
253 (allPoints.length === 1 &&
254 incomingPoints.length === 0 &&
255 outgoingPoints.length === 0 &&
261 <Grid.Item full as={HelpText} className="mt8 t-center">
262 <Blinky /> Loading...
270 <View inset pop={pop} hideBack>
274 className="f6 mono gray4 mb4 us-none pointer">
275 {abbreviateAddress(address)}
279 {displayEmptyState && (
280 <Grid.Item full as={HelpText} className="mt8 t-center">
281 No points to display. This wallet is not the owner or proxy for any
286 {incomingPoints.length > 0 && (
287 <Grid.Item full as={Grid} gap={1} className="mb6">
288 <Grid.Item full as={H5}>
290 incomingPoints.length,
298 points={incomingPoints}
299 actions={(point, i) => (
305 setPointCursor(Just(point));
306 push(names.ACCEPT_TRANSFER);
312 addRejectedPoint(point);
323 {outgoingPoints.length > 0 && (
324 <Grid.Item full as={Grid} gap={1} className="mb6">
325 <Grid.Item full as={H5}>
327 outgoingPoints.length,
335 points={outgoingPoints}
336 actions={(point, i) => (
342 setPointCursor(Just(point));
343 // TODO: deep linking to fix this duplicate route
344 push(names.CANCEL_TRANSFER);
355 {allPoints.length > 0 && (
356 <Grid.Item full as={Grid} gap={1}>
357 <Grid.Item full as={H5}>
358 {pluralize(allPoints.length, 'ID')}
360 <Grid.Item full as={PointList} points={allPoints} />
367 {isEclipticOwner && (
372 detail="You have the authority to create a new Galaxy."
373 onClick={goCreateGalaxy}>
384 detail="You have points being released"
385 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