on master help sign in
Skip the points list page if only one point
f6ffb6dFang
src/views/Points.js+33−2
@@ -1,4 +1,4 @@
1−import React, { useCallback } from 'react';
1+import React, { useCallback, useEffect } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, H5, H1, HelpText, LinkButton, Flex } from 'indigo-react';
3import { Grid, H5, H1, HelpText, LinkButton, Flex } from 'indigo-react';
4import { get } from 'lodash';
4import { get } from 'lodash';
@@ -79,7 +79,7 @@ function ActionButtons({ actions = [] }) {
79
79
80export default function Points() {
80export default function Points() {
81 const { wallet } = useWallet();
81 const { wallet } = useWallet();
82− const { pop, push, names } = useHistory();
82+ const { pop, push, popAndPush, names } = useHistory();
83 const { setPointCursor } = usePointCursor();
83 const { setPointCursor } = usePointCursor();
84 const { controlledPoints, getDetails } = usePointCache();
84 const { controlledPoints, getDetails } = usePointCache();
85 const isEclipticOwner = useIsEclipticOwner();
85 const isEclipticOwner = useIsEclipticOwner();
@@ -88,6 +88,37 @@ export default function Points() {
88 addRejectedPoint,
88 addRejectedPoint,
89 ] = useRejectedIncomingPointTransfers();
89 ] = useRejectedIncomingPointTransfers();
90
90
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+
91 const address = need.addressFromWallet(wallet);
122 const address = need.addressFromWallet(wallet);
92
123
93 const loading = Nothing.hasInstance(controlledPoints);
124 const loading = Nothing.hasInstance(controlledPoints);