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/copiable/CopiableAddress';
26import NavHeader from 'components/NavHeader';
27import L2PointHeader from 'components/L2/Headers/L2PointHeader';
28import IncomingPoint from 'components/L2/Points/IncomingPoint';
30const maybeGetResult = (obj, key, defaultValue) =>
32 Nothing: () => defaultValue,
35 Ok: r => get(r.value, key, defaultValue),
36 Error: e => defaultValue,
40const hasTransferProxy = details => !isZeroAddress(details.transferProxy);
42const PointList = function({
49 const { setPointCursor } = usePointCursor();
50 const { push, names } = useHistory();
53 <Grid gap={4} className={className}>
54 {points.map((point, i) => (
57 className={`full fourth-${(i % 4) + 1}-md fourth-${(i % 4) + 1}-lg`}>
63 setPointCursor(Just(point));
69 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
78function ActionButtons({ actions = [] }) {
81 {actions.map(action => (
86 onClick={action.onClick}>
94export default function Points() {
95 const { wallet } = useWallet();
96 const { pop, push, popAndPush, names } = useHistory();
97 const { setPointCursor } = usePointCursor();
98 const { controlledPoints, getDetails } = usePointCache();
99 const isEclipticOwner = useIsEclipticOwner();
103 ] = useRejectedIncomingPointTransfers();
104 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
106 const maybeOutgoingPoints = useMemo(
108 controlledPoints.chain(points =>
110 Error: () => Nothing(),
112 const points = c.value.ownedPoints.map(point =>
113 getDetails(point).chain(details =>
114 Just({ point: point, has: hasTransferProxy(details) })
117 // if we have details for every point,
118 // return the array of pending transfers.
119 if (points.every(p => Just.hasInstance(p))) {
120 const outgoing = points
121 .filter(p => p.value.has)
122 .map(p => p.value.point);
123 return Just(outgoing);
130 [getDetails, controlledPoints]
133 // if we can only interact with a single point, forget about the existence
134 // of this page and jump to the point page.
135 // if there are any pending transfers, incoming or outgoing, stay on this
136 // page, because those can only be completed/cancelled here.
139 Nothing.hasInstance(maybeOutgoingPoints) ||
140 Nothing.hasInstance(starReleaseDetails)
144 controlledPoints.matchWith({
151 ...c.value.ownedPoints,
152 ...c.value.votingPoints,
153 ...c.value.managingPoints,
154 ...c.value.spawningPoints,
156 const incoming = c.value.incomingPoints.filter(
157 p => !rejectedPoints.includes(p)
161 incoming.length === 0 &&
162 maybeOutgoingPoints.value.length === 0 &&
163 (starReleaseDetails.value === null ||
164 starReleaseDetails.value.total === 0)
166 setPointCursor(Just(all[0]));
167 popAndPush(names.POINT);
183 const address = need.addressFromWallet(wallet);
185 const loading = Nothing.hasInstance(controlledPoints);
187 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
188 const incomingPoints = maybeGetResult(
192 ).filter(point => !rejectedPoints.includes(point));
193 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
194 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
195 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
196 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
199 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
203 ].sort((a, b) => Number(a) - Number(b));
205 const displayEmptyState =
206 !loading && incomingPoints.length === 0 && allPoints.length === 0;
208 const starReleasing = starReleaseDetails
209 .map(s => (s ? s.total > 0 : false))
213 syncStarReleaseDetails();
214 }, [syncStarReleaseDetails]);
216 // sync display details for known points
217 useSyncDetails(ownedPoints);
219 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
224 const goStarRelease = useCallback(() => push(names.STAR_RELEASE), [
229 // if we got an error result, we should display it, instead of showing
230 // a potentially inaccurately empty point list.
233 Just.hasInstance(controlledPoints) &&
234 controlledPoints.value.matchWith({
239 const url = newGithubIssueUrl({
242 title: controlledPoints.value.value,
243 body: `<!-- Please provide some context. Do you have Metamask installed? What login method did you use? -->`,
248 <Grid.Item full as={HelpText} className="mt8 t-center">
249 {controlledPoints.value.value}
251 Try reloading the page. If this problem persists, please{' '}
252 <a href={url}>file an issue on GitHub</a>.
261 (allPoints.length === 1 &&
262 incomingPoints.length === 0 &&
263 outgoingPoints.length === 0 &&
269 <Grid.Item full as={HelpText} className="mt8 t-center">
270 <Blinky /> Loading...
282 header={<L2PointHeader hideTimer hideInvites />}>
286 className="f6 mono gray4 mb4 us-none pointer">
287 {abbreviateAddress(address)}
290 {incomingPoints.map(point => (
294 setPointCursor(Just(point));
295 push(names.ACCEPT_TRANSFER);
297 reject={() => addRejectedPoint(point)}
301 {displayEmptyState && (
302 <Grid.Item full as={HelpText} className="mt8 t-center">
303 No points to display. This wallet is not the owner or proxy for any
308 {outgoingPoints.length > 0 && (
309 <Grid.Item full as={Grid} gap={1} className="mb6">
310 <Grid.Item full as={H5}>
312 outgoingPoints.length,
320 points={outgoingPoints}
321 actions={(point, i) => (
327 setPointCursor(Just(point));
328 // TODO: deep linking to fix this duplicate route
329 push(names.CANCEL_TRANSFER);
340 {allPoints.length > 0 && (
341 <Grid.Item full as={Grid} gap={1}>
342 {/* <Grid.Item full as={H5}>
343 {pluralize(allPoints.length, 'ID')}
345 <Grid.Item full as={PointList} points={allPoints} />
352 {isEclipticOwner && (
357 detail="You have the authority to create a new Galaxy."
358 onClick={goCreateGalaxy}>
369 detail="You have points being released"
370 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