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';
11import { useNetwork } from 'store/network';
13import * as need from 'lib/need';
14import { isZeroAddress, abbreviateAddress } from 'lib/utils/address';
15import useIsEclipticOwner from 'lib/useIsEclipticOwner';
16import { useSyncDetails } from 'lib/useSyncPoints';
17import useRejectedIncomingPointTransfers from 'lib/useRejectedIncomingPointTransfers';
18import { pluralize } from 'lib/pluralize';
19import newGithubIssueUrl from 'new-github-issue-url';
21import View from 'components/View';
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';
29import LoadingOverlay from 'components/L2/LoadingOverlay';
30import { onlyUnique } from 'lib/utils/array';
32export const maybeGetResult = (obj, key, defaultValue) =>
34 Nothing: () => defaultValue,
37 Ok: r => get(r.value, key, defaultValue),
38 Error: e => defaultValue,
42export const hasTransferProxy = details =>
43 !isZeroAddress(details.transferProxy);
45export const getOutgoingPoints = (controlledPoints, getDetails) => {
46 return controlledPoints
49 Error: () => Nothing(),
51 const points = c.value.ownedPoints.map(point =>
52 getDetails(point).chain(details =>
53 Just({ point: point, has: hasTransferProxy(details) })
56 if (points.every(p => Just.hasInstance(p))) {
57 const outgoing = points
58 .filter(p => p.value.has)
59 .map(p => p.value.point);
60 return Just(outgoing);
70export const isLocked = (details, contracts) =>
71 details.owner === contracts.linearSR ||
72 details.owner === contracts.conditionalSR;
74const PointList = function({
81 const { setPointCursor } = usePointCursor();
82 const { push, names } = useHistory();
85 <Grid gap={4} className={className}>
86 {points.map((point, i) => (
89 className={`full fourth-${(i % 4) + 1}-md fourth-${(i % 4) + 1}-lg`}>
98 setPointCursor(Just(point));
105 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
114function ActionButtons({ actions = [] }) {
117 {actions.map(action => (
122 onClick={action.onClick}>
130export default function Points() {
131 const { wallet } = useWallet();
132 const { pop, push, popAndPush, names } = useHistory();
133 const { setPointCursor } = usePointCursor();
134 const { controlledPoints, getDetails } = usePointCache();
135 const { contracts } = useNetwork();
136 const isEclipticOwner = useIsEclipticOwner();
140 ] = useRejectedIncomingPointTransfers();
141 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
143 const outgoingPoints = useMemo(
144 () => getOutgoingPoints(controlledPoints, getDetails),
145 [getDetails, controlledPoints]
148 const _contracts = need.contracts(contracts);
150 const maybeLockedPoints = useMemo(
152 controlledPoints.chain(points =>
154 Error: () => Nothing(),
156 const points = c.value.ownedPoints.map(point =>
157 getDetails(point).chain(details =>
158 Just({ point, has: isLocked(details, _contracts) })
161 // if we have details for every point,
162 // return the array of pending transfers.
163 if (points.every(p => Just.hasInstance(p))) {
164 const locked = points
165 .filter(p => p.value.has)
166 .map(p => p.value.point);
174 [getDetails, controlledPoints, _contracts]
176 // if we can only interact with a single point, forget about the existence
177 // of this page and jump to the point page.
178 // if there are any pending transfers, incoming or outgoing, stay on this
179 // page, because those can only be completed/cancelled here.
182 Nothing.hasInstance(outgoingPoints) ||
183 Nothing.hasInstance(starReleaseDetails)
187 controlledPoints.matchWith({
194 ...c.value.ownedPoints,
195 ...c.value.votingPoints,
196 ...c.value.managingPoints,
197 ...c.value.spawningPoints,
199 const incoming = c.value.incomingPoints.filter(
200 p => !rejectedPoints.includes(p)
204 incoming.length === 0 &&
205 outgoingPoints.length === 0 &&
206 (starReleaseDetails.value === null ||
207 starReleaseDetails.value.total === 0)
209 setPointCursor(Just(all[0]));
210 popAndPush(names.POINT);
226 const address = need.addressFromWallet(wallet);
228 const loading = Nothing.hasInstance(controlledPoints);
230 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
231 const incomingPoints = maybeGetResult(
235 ).filter(point => !rejectedPoints.includes(point));
236 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
237 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
238 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
239 const lockedPoints = maybeLockedPoints.getOrElse([]);
242 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
247 .sort((a, b) => Number(a) - Number(b))
250 const displayEmptyState =
251 !loading && incomingPoints.length === 0 && allPoints.length === 0;
253 const starReleasing = starReleaseDetails
254 .map(s => (s ? s.total > 0 : false))
258 syncStarReleaseDetails();
259 }, [syncStarReleaseDetails]);
261 // sync display details for known points
262 useSyncDetails(ownedPoints);
264 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
269 const goStarRelease = useCallback(() => push(names.STAR_RELEASE), [
274 // if we got an error result, we should display it, instead of showing
275 // a potentially inaccurately empty point list.
278 Just.hasInstance(controlledPoints) &&
279 controlledPoints.value.matchWith({
284 const url = newGithubIssueUrl({
287 title: controlledPoints.value.value,
288 body: `<!-- Please provide some context. Do you have Metamask installed? What login method did you use? -->`,
293 <Grid.Item full as={HelpText} className="mt8 t-center">
294 {controlledPoints.value.value}
296 Try reloading the page. If this problem persists, please{' '}
297 <a href={url}>file an issue on GitHub</a>.
306 (allPoints.length === 1 &&
307 incomingPoints.length === 0 &&
308 outgoingPoints.length === 0 &&
313 <LoadingOverlay loading />
323 header={<L2PointHeader hideHome hideTimer hideInvites showMigrate />}>
327 className="f6 mono gray4 mb4 us-none pointer">
328 {abbreviateAddress(address)}
331 {incomingPoints.map(point => (
336 setPointCursor(Just(point));
337 push(names.ACCEPT_TRANSFER);
339 reject={() => addRejectedPoint(point)}
343 {displayEmptyState && (
344 <Grid.Item full as={HelpText} className="mt8 t-center">
345 No points to display. This wallet is not the owner or proxy for any
350 {outgoingPoints.length > 0 && (
351 <Grid.Item full as={Grid} gap={1} className="mb6">
352 <Grid.Item full as={H5}>
354 outgoingPoints.length,
362 points={outgoingPoints}
363 actions={(point, i) => (
369 setPointCursor(Just(point));
370 // TODO: deep linking to fix this duplicate route
371 push(names.CANCEL_TRANSFER);
381 {allPoints.length > 0 && (
382 <Grid.Item full as={Grid} gap={1}>
383 <Grid.Item full as={PointList} points={allPoints} />
387 {lockedPoints.length > 0 && (
388 <Grid.Item full as={Grid} gap={1}>
389 <Grid.Item full as={PointList} locked points={allPoints} />
396 {isEclipticOwner && (
401 detail="You have the authority to create a new Galaxy."
402 onClick={goCreateGalaxy}>
413 detail="You have points being released"
414 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