on master help sign in
Skip the points list page if only one point

can be interacted with, and it isn't a pending transfer. TODO: doesn't yet account for outgoing transfers.

commitf6ffb6dd005f2ea2cd92cdd375d41e0752471289 authorFang <git@fang.io> dateFri 2 Aug 2019, 16:17 (7 years ago) parent87a9d76
1 file changed+33−2
src/views/Points.js+33−2
src/views/Points.js+33−2
@@ -1,4 +1,4 @@
1−import React, { useCallback } from 'react';
1+import React, { useCallback, useEffect } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import { Grid, H5, H1, HelpText, LinkButton, Flex } from 'indigo-react';
44import { get } from 'lodash';
@@ -79,7 +79,7 @@ function ActionButtons({ actions = [] }) {
7979
8080export default function Points() {
8181 const { wallet } = useWallet();
82− const { pop, push, names } = useHistory();
82+ const { pop, push, popAndPush, names } = useHistory();
8383 const { setPointCursor } = usePointCursor();
8484 const { controlledPoints, getDetails } = usePointCache();
8585 const isEclipticOwner = useIsEclipticOwner();
@@ -88,6 +88,37 @@ export default function Points() {
8888 addRejectedPoint,
8989 ] = useRejectedIncomingPointTransfers();
9090
91+ // if we can only interact with a single point, forget about the existence
92+ // of this page and jump to the point page.
93+ // if there are any pending transfers, incoming or outgoing, stay on this
94+ // page, because those can only be completed/cancelled here.
95+ useEffect(() => {
96+ controlledPoints.matchWith({
97+ Nothing: () => null,
98+ Just: r => {
99+ r.value.matchWith({
100+ Error: () => null,
101+ Ok: p => {
102+ let all = [
103+ ...p.value.ownedPoints,
104+ ...p.value.votingPoints,
105+ ...p.value.managingPoints,
106+ ...p.value.spawningPoints,
107+ ];
108+ const incoming = p.value.incomingPoints.filter(
109+ p => !rejectedPoints.includes(p)
110+ );
111+ //TODO && outgoing.length === 0
112+ if (all.length === 1 && incoming.length === 0) {
113+ setPointCursor(Just(all[0]));
114+ popAndPush(names.POINT);
115+ }
116+ },
117+ });
118+ },
119+ });
120+ }, [controlledPoints, rejectedPoints, setPointCursor, popAndPush, names]);
121+
91122 const address = need.addressFromWallet(wallet);
92123
93124 const loading = Nothing.hasInstance(controlledPoints);