1import React, { useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, H5, H1, 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';
11import * as need from 'lib/need';
12import { isZeroAddress, abbreviateAddress } from 'lib/wallet';
13import useIsEclipticOwner from 'lib/useIsEclipticOwner';
14import { useSyncKnownPoints } from 'lib/useSyncPoints';
16import View from 'components/View';
17import Blinky from 'components/Blinky';
18import Passport from 'components/Passport';
19import useRejectedIncomingPointTransfers from 'lib/useRejectedIncomingPointTransfers';
20import pluralize from 'lib/pluralize';
21import Footer from 'components/Footer';
22import { ForwardButton } from 'components/Buttons';
24const maybeGetResult = (obj, key, defaultValue) =>
26 Nothing: () => defaultValue,
29 Ok: r => get(r.value, key, defaultValue),
30 Error: e => defaultValue,
34const hasTransferProxy = details => !isZeroAddress(details.transferProxy);
36const PointList = function({ points, className, actions, ...rest }) {
37 const { setPointCursor } = usePointCursor();
38 const { push, names } = useHistory();
41 <Grid gap={3} className={className}>
42 {points.map((point, i) => (
43 <Grid.Item half={(i % 2) + 1} key={point}>
49 setPointCursor(Just(point));
55 <Flex.Item className="mt2">{actions(point, i)}</Flex.Item>
64function ActionButtons({ actions = [] }) {
67 {actions.map(action => (
72 onClick={action.onClick}>
80export default function Points() {
81 const { wallet } = useWallet();
82 const { pop, push, names } = useHistory();
83 const { setPointCursor } = usePointCursor();
84 const { controlledPoints, getDetails } = usePointCache();
85 const isEclipticOwner = useIsEclipticOwner();
89 ] = useRejectedIncomingPointTransfers();
91 const address = need.addressFromWallet(wallet);
93 const loading = Nothing.hasInstance(controlledPoints);
95 const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
96 const incomingPoints = maybeGetResult(
100 ).filter(point => !rejectedPoints.includes(point));
101 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
102 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
103 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
104 const outgoingPoints = ownedPoints.filter(point =>
105 getDetails(point).matchWith({
106 Nothing: () => false,
107 Just: p => hasTransferProxy(p.value),
111 const multipassPoints = [
112 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
118 const displayEmptyState =
119 !loading && incomingPoints.length === 0 && multipassPoints.length === 0;
121 // sync display details for known points
130 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
135 const goViewPoint = useCallback(() => push(names.VIEW_POINT), [
141 <View pop={pop} inset>
143 <Grid.Item full as={H1} className="f6 mono gray4 mb4">
144 {abbreviateAddress(address)}
148 <Grid.Item full as={HelpText} className="mt8 t-center">
149 <Blinky /> Loading...
153 {displayEmptyState && (
154 <Grid.Item full as={HelpText} className="mt8 t-center">
155 No points to display. This wallet is not the owner or proxy for any
160 {incomingPoints.length > 0 && (
161 <Grid.Item full as={Grid} gap={1} className="mb6">
162 <Grid.Item full as={H5}>
164 incomingPoints.length,
172 points={incomingPoints}
173 actions={(point, i) => (
179 setPointCursor(Just(point));
180 push(names.ACCEPT_TRANSFER);
186 addRejectedPoint(point);
197 {outgoingPoints.length > 0 && (
198 <Grid.Item full as={Grid} gap={1} className="mb6">
199 <Grid.Item full as={H5}>
201 outgoingPoints.length,
209 points={outgoingPoints}
210 actions={(point, i) => (
216 setPointCursor(Just(point));
217 // TODO: deep linking to fix this duplicate route
218 push(names.CANCEL_TRANSFER);
229 {multipassPoints.length > 0 && (
230 <Grid.Item full as={Grid} gap={1}>
231 <Grid.Item full as={H5}>
232 {pluralize(multipassPoints.length, 'Multipass', 'Multipasses')}
234 <Grid.Item full as={PointList} points={multipassPoints} />
241 {isEclipticOwner && (
246 detail="You have the authority to create a new Galaxy."
247 onClick={goCreateGalaxy}>
256 detail="View a point"
257 onClick={goViewPoint}>
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