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';
30export const 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`}>
66 setPointCursor(Just(point));
73 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
82function ActionButtons({ actions = [] }) {
85 {actions.map(action => (
90 onClick={action.onClick}>
98export default function Points() {
99 const { wallet } = useWallet();
100 const { pop, push, popAndPush, names } = useHistory();
101 const { setPointCursor } = usePointCursor();
102 const { controlledPoints, getDetails } = usePointCache();
103 const isEclipticOwner = useIsEclipticOwner();
107 ] = useRejectedIncomingPointTransfers();
108 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
110 const maybeOutgoingPoints = useMemo(
112 controlledPoints.chain(points =>
114 Error: () => Nothing(),
116 const points = c.value.ownedPoints.map(point =>
117 getDetails(point).chain(details =>
118 Just({ point: point, has: hasTransferProxy(details) })
121 // if we have details for every point,
122 // return the array of pending transfers.
123 if (points.every(p => Just.hasInstance(p))) {
124 const outgoing = points
125 .filter(p => p.value.has)
126 .map(p => p.value.point);
127 return Just(outgoing);
134 [getDetails, controlledPoints]
137 const maybeLockedPoints = useMemo(
139 controlledPoints.chain(points =>
141 Error: () => Nothing(),
143 // TODO: how to determine this?
144 const points = c.value.ownedPoints.map(point =>
145 getDetails(point).chain(details =>
146 Just({ point: point, has: hasTransferProxy(details) })
149 // if we have details for every point,
150 // return the array of pending transfers.
151 if (points.every(p => Just.hasInstance(p))) {
152 const locked = points
153 .filter(p => p.value.has)
154 .map(p => p.value.point);
162 [getDetails, controlledPoints]
165 // if we can only interact with a single point, forget about the existence
166 // of this page and jump to the point page.
167 // if there are any pending transfers, incoming or outgoing, stay on this
168 // page, because those can only be completed/cancelled here.
171 Nothing.hasInstance(maybeOutgoingPoints) ||
172 Nothing.hasInstance(starReleaseDetails)
176 controlledPoints.matchWith({
183 ...c.value.ownedPoints,
184 ...c.value.votingPoints,
185 ...c.value.managingPoints,
186 ...c.value.spawningPoints,
188 const incoming = c.value.incomingPoints.filter(
189 p => !rejectedPoints.includes(p)
193 incoming.length === 0 &&
194 maybeOutgoingPoints.value.length === 0 &&
195 (starReleaseDetails.value === null ||
196 starReleaseDetails.value.total === 0)
198 setPointCursor(Just(all[0]));
199 popAndPush(names.POINT);
215 const address = need.addressFromWallet(wallet);
217 const loading = Nothing.hasInstance(controlledPoints);
219 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
220 const incomingPoints = maybeGetResult(
224 ).filter(point => !rejectedPoints.includes(point));
225 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
226 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
227 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
228 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
229 const lockedPoints = maybeLockedPoints.getOrElse([]);
232 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
236 ].sort((a, b) => Number(a) - Number(b));
238 const displayEmptyState =
239 !loading && incomingPoints.length === 0 && allPoints.length === 0;
241 const starReleasing = starReleaseDetails
242 .map(s => (s ? s.total > 0 : false))
246 syncStarReleaseDetails();
247 }, [syncStarReleaseDetails]);
249 // sync display details for known points
250 useSyncDetails(ownedPoints);
252 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
257 const goStarRelease = useCallback(() => push(names.STAR_RELEASE), [
262 // if we got an error result, we should display it, instead of showing
263 // a potentially inaccurately empty point list.
266 Just.hasInstance(controlledPoints) &&
267 controlledPoints.value.matchWith({
272 const url = newGithubIssueUrl({
275 title: controlledPoints.value.value,
276 body: `<!-- Please provide some context. Do you have Metamask installed? What login method did you use? -->`,
281 <Grid.Item full as={HelpText} className="mt8 t-center">
282 {controlledPoints.value.value}
284 Try reloading the page. If this problem persists, please{' '}
285 <a href={url}>file an issue on GitHub</a>.
294 (allPoints.length === 1 &&
295 incomingPoints.length === 0 &&
296 outgoingPoints.length === 0 &&
302 <Grid.Item full as={HelpText} className="mt8 t-center">
303 <Blinky /> Loading...
315 header={<L2PointHeader hideTimer hideInvites />}>
319 className="f6 mono gray4 mb4 us-none pointer">
320 {abbreviateAddress(address)}
323 {incomingPoints.map(point => (
327 setPointCursor(Just(point));
328 push(names.ACCEPT_TRANSFER);
330 reject={() => addRejectedPoint(point)}
334 {displayEmptyState && (
335 <Grid.Item full as={HelpText} className="mt8 t-center">
336 No points to display. This wallet is not the owner or proxy for any
341 {outgoingPoints.length > 0 && (
342 <Grid.Item full as={Grid} gap={1} className="mb6">
343 <Grid.Item full as={H5}>
345 outgoingPoints.length,
353 points={outgoingPoints}
354 actions={(point, i) => (
360 setPointCursor(Just(point));
361 // TODO: deep linking to fix this duplicate route
362 push(names.CANCEL_TRANSFER);
373 {allPoints.length > 0 && (
374 <Grid.Item full as={Grid} gap={1}>
375 {/* <Grid.Item full as={H5}>
376 {pluralize(allPoints.length, 'ID')}
378 <Grid.Item full as={PointList} points={allPoints} />
382 {lockedPoints.length > 0 && (
383 <Grid.Item full as={Grid} gap={1}>
384 <Grid.Item full as={PointList} locked points={allPoints} />
391 {isEclipticOwner && (
396 detail="You have the authority to create a new Galaxy."
397 onClick={goCreateGalaxy}>
408 detail="You have points being released"
409 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