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';
29import { useNetwork } from 'store/network';
31export const maybeGetResult = (obj, key, defaultValue) =>
33 Nothing: () => defaultValue,
36 Ok: r => get(r.value, key, defaultValue),
37 Error: e => defaultValue,
41export const hasTransferProxy = details =>
42 !isZeroAddress(details.transferProxy);
44export const getOutgoingPoints = (controlledPoints, getDetails) => {
45 return controlledPoints
48 Error: () => Nothing(),
50 const points = c.value.ownedPoints.map(point =>
51 getDetails(point).chain(details =>
52 Just({ point: point, has: hasTransferProxy(details) })
55 if (points.every(p => Just.hasInstance(p))) {
56 const outgoing = points
57 .filter(p => p.value.has)
58 .map(p => p.value.point);
59 return Just(outgoing);
69export const isLocked = (details, contracts) =>
70 details.owner === contracts.linearSR ||
71 details.owner === contracts.conditionalSR;
73const PointList = function({
80 const { setPointCursor } = usePointCursor();
81 const { push, names } = useHistory();
84 <Grid gap={4} className={className}>
85 {points.map((point, i) => (
88 className={`full fourth-${(i % 4) + 1}-md fourth-${(i % 4) + 1}-lg`}>
97 setPointCursor(Just(point));
104 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
113function ActionButtons({ actions = [] }) {
116 {actions.map(action => (
121 onClick={action.onClick}>
129export default function Points() {
130 const { wallet } = useWallet();
131 const { pop, push, popAndPush, names } = useHistory();
132 const { setPointCursor } = usePointCursor();
133 const { controlledPoints, getDetails } = usePointCache();
134 const { contracts } = useNetwork();
135 const isEclipticOwner = useIsEclipticOwner();
139 ] = useRejectedIncomingPointTransfers();
140 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
142 const outgoingPoints = useMemo(
143 () => getOutgoingPoints(controlledPoints, getDetails),
144 [getDetails, controlledPoints]
147 const _contracts = need.contracts(contracts);
149 const maybeLockedPoints = useMemo(
151 controlledPoints.chain(points =>
153 Error: () => Nothing(),
155 const points = c.value.ownedPoints.map(point =>
156 getDetails(point).chain(details =>
157 Just({ point, has: isLocked(details, _contracts) })
160 // if we have details for every point,
161 // return the array of pending transfers.
162 if (points.every(p => Just.hasInstance(p))) {
163 const locked = points
164 .filter(p => p.value.has)
165 .map(p => p.value.point);
173 [getDetails, controlledPoints, _contracts]
175 // if we can only interact with a single point, forget about the existence
176 // of this page and jump to the point page.
177 // if there are any pending transfers, incoming or outgoing, stay on this
178 // page, because those can only be completed/cancelled here.
181 Nothing.hasInstance(outgoingPoints) ||
182 Nothing.hasInstance(starReleaseDetails)
186 controlledPoints.matchWith({
193 ...c.value.ownedPoints,
194 ...c.value.votingPoints,
195 ...c.value.managingPoints,
196 ...c.value.spawningPoints,
198 const incoming = c.value.incomingPoints.filter(
199 p => !rejectedPoints.includes(p)
203 incoming.length === 0 &&
204 outgoingPoints.length === 0 &&
205 (starReleaseDetails.value === null ||
206 starReleaseDetails.value.total === 0)
208 setPointCursor(Just(all[0]));
209 popAndPush(names.POINT);
225 const address = need.addressFromWallet(wallet);
227 const loading = Nothing.hasInstance(controlledPoints);
229 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
230 const incomingPoints = maybeGetResult(
234 ).filter(point => !rejectedPoints.includes(point));
235 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
236 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
237 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
238 const lockedPoints = maybeLockedPoints.getOrElse([]);
241 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
245 ].sort((a, b) => Number(a) - Number(b));
247 const displayEmptyState =
248 !loading && incomingPoints.length === 0 && allPoints.length === 0;
250 const starReleasing = starReleaseDetails
251 .map(s => (s ? s.total > 0 : false))
255 syncStarReleaseDetails();
256 }, [syncStarReleaseDetails]);
258 // sync display details for known points
259 useSyncDetails(ownedPoints);
261 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
266 const goStarRelease = useCallback(() => push(names.STAR_RELEASE), [
271 // if we got an error result, we should display it, instead of showing
272 // a potentially inaccurately empty point list.
275 Just.hasInstance(controlledPoints) &&
276 controlledPoints.value.matchWith({
281 const url = newGithubIssueUrl({
284 title: controlledPoints.value.value,
285 body: `<!-- Please provide some context. Do you have Metamask installed? What login method did you use? -->`,
290 <Grid.Item full as={HelpText} className="mt8 t-center">
291 {controlledPoints.value.value}
293 Try reloading the page. If this problem persists, please{' '}
294 <a href={url}>file an issue on GitHub</a>.
303 (allPoints.length === 1 &&
304 incomingPoints.length === 0 &&
305 outgoingPoints.length === 0 &&
311 <Grid.Item full as={HelpText} className="mt8 t-center">
312 <Blinky /> Loading...
324 header={<L2PointHeader hideTimer hideInvites showMigrate />}>
328 className="f6 mono gray4 mb4 us-none pointer">
329 {abbreviateAddress(address)}
332 {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