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 L2Header from 'components/L2Header';
27import NavHeader from 'components/NavHeader';
29const maybeGetResult = (obj, key, defaultValue) =>
31 Nothing: () => defaultValue,
34 Ok: r => get(r.value, key, defaultValue),
35 Error: e => defaultValue,
39const hasTransferProxy = details => !isZeroAddress(details.transferProxy);
41const PointList = function({ points, className, actions, ...rest }) {
42 const { setPointCursor } = usePointCursor();
43 const { push, names } = useHistory();
46 <Grid gap={3} className={className}>
47 {points.map((point, i) => (
50 className={`full half-${(i % 2) + 1}-md half-${(i % 2) + 1}-lg`}>
56 setPointCursor(Just(point));
62 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
71function ActionButtons({ actions = [] }) {
74 {actions.map(action => (
79 onClick={action.onClick}>
87export default function Points() {
88 const { wallet } = useWallet();
89 const { pop, push, popAndPush, names } = useHistory();
90 const { setPointCursor } = usePointCursor();
91 const { controlledPoints, getDetails } = usePointCache();
92 const isEclipticOwner = useIsEclipticOwner();
96 ] = useRejectedIncomingPointTransfers();
97 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
99 const maybeOutgoingPoints = useMemo(
101 controlledPoints.chain(points =>
103 Error: () => Nothing(),
105 const points = c.value.ownedPoints.map(point =>
106 getDetails(point).chain(details =>
107 Just({ point: point, has: hasTransferProxy(details) })
110 // if we have details for every point,
111 // return the array of pending transfers.
112 if (points.every(p => Just.hasInstance(p))) {
113 const outgoing = points
114 .filter(p => p.value.has)
115 .map(p => p.value.point);
116 return Just(outgoing);
123 [getDetails, controlledPoints]
126 // if we can only interact with a single point, forget about the existence
127 // of this page and jump to the point page.
128 // if there are any pending transfers, incoming or outgoing, stay on this
129 // page, because those can only be completed/cancelled here.
132 Nothing.hasInstance(maybeOutgoingPoints) ||
133 Nothing.hasInstance(starReleaseDetails)
137 controlledPoints.matchWith({
144 ...c.value.ownedPoints,
145 ...c.value.votingPoints,
146 ...c.value.managingPoints,
147 ...c.value.spawningPoints,
149 const incoming = c.value.incomingPoints.filter(
150 p => !rejectedPoints.includes(p)
154 incoming.length === 0 &&
155 maybeOutgoingPoints.value.length === 0 &&
156 (starReleaseDetails.value === null ||
157 starReleaseDetails.value.total === 0)
159 setPointCursor(Just(all[0]));
160 popAndPush(names.POINT);
176 const address = need.addressFromWallet(wallet);
178 const loading = Nothing.hasInstance(controlledPoints);
180 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
181 const incomingPoints = maybeGetResult(
185 ).filter(point => !rejectedPoints.includes(point));
186 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
187 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
188 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
189 const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
192 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
198 const displayEmptyState =
199 !loading && incomingPoints.length === 0 && allPoints.length === 0;
201 const starReleasing = starReleaseDetails
202 .map(s => (s ? s.total > 0 : false))
206 syncStarReleaseDetails();
207 }, [syncStarReleaseDetails]);
209 // sync display details for known points
210 useSyncDetails(ownedPoints);
212 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
217 const goStarRelease = useCallback(() => push(names.STAR_RELEASE), [
222 // if we got an error result, we should display it, instead of showing
223 // a potentially inaccurately empty point list.
226 Just.hasInstance(controlledPoints) &&
227 controlledPoints.value.matchWith({
232 const url = newGithubIssueUrl({
235 title: controlledPoints.value.value,
236 body: `<!-- Please provide some context. Do you have Metamask installed? What login method did you use? -->`,
241 <Grid.Item full as={HelpText} className="mt8 t-center">
242 {controlledPoints.value.value}
244 Try reloading the page. If this problem persists, please{' '}
245 <a href={url}>file an issue on GitHub</a>.
254 (allPoints.length === 1 &&
255 incomingPoints.length === 0 &&
256 outgoingPoints.length === 0 &&
262 <Grid.Item full as={HelpText} className="mt8 t-center">
263 <Blinky /> Loading...
271 <View inset pop={pop} hideBack>
275 className="f6 mono gray4 mb4 us-none pointer">
276 {abbreviateAddress(address)}
281 {displayEmptyState && (
282 <Grid.Item full as={HelpText} className="mt8 t-center">
283 No points to display. This wallet is not the owner or proxy for any
288 {incomingPoints.length > 0 && (
289 <Grid.Item full as={Grid} gap={1} className="mb6">
290 <Grid.Item full as={H5}>
292 incomingPoints.length,
300 points={incomingPoints}
301 actions={(point, i) => (
307 setPointCursor(Just(point));
308 push(names.ACCEPT_TRANSFER);
314 addRejectedPoint(point);
325 {outgoingPoints.length > 0 && (
326 <Grid.Item full as={Grid} gap={1} className="mb6">
327 <Grid.Item full as={H5}>
329 outgoingPoints.length,
337 points={outgoingPoints}
338 actions={(point, i) => (
344 setPointCursor(Just(point));
345 // TODO: deep linking to fix this duplicate route
346 push(names.CANCEL_TRANSFER);
357 {allPoints.length > 0 && (
358 <Grid.Item full as={Grid} gap={1}>
359 <Grid.Item full as={H5}>
360 {pluralize(allPoints.length, 'ID')}
362 <Grid.Item full as={PointList} points={allPoints} />
369 {isEclipticOwner && (
374 detail="You have the authority to create a new Galaxy."
375 onClick={goCreateGalaxy}>
386 detail="You have points being released"
387 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