@@ -1,4 +1,4 @@
1−import React, { useCallback, useEffect } from 'react';
1+import React, { useCallback, useEffect, useMemo } 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';
@@ -88,11 +88,43 @@ export default function Points() {
88 addRejectedPoint,
88 addRejectedPoint,
89 ] = useRejectedIncomingPointTransfers();
89 ] = useRejectedIncomingPointTransfers();
91+ const maybeOutgoingPoints = useMemo(() => {
92+ return controlledPoints.matchWith({
93+ Nothing: () => Nothing(),
96+ Error: () => Nothing(),
98+ const points = c.value.ownedPoints.map(point =>
99+ getDetails(point).matchWith({
100+ Nothing: () => Nothing(),
102+ Just({ point: point, has: hasTransferProxy(p.value) }),
105+ // if we have details for every point,
106+ // return the array of pending transfers.
107+ if (points.every(p => Just.hasInstance(p))) {
108+ const outgoing = points
109+ .filter(p => p.value.has)
110+ .map(p => p.value.point);
111+ return Just(outgoing);
118+ }, [getDetails, controlledPoints]);
91 // if we can only interact with a single point, forget about the existence
120 // if we can only interact with a single point, forget about the existence
92 // of this page and jump to the point page.
121 // of this page and jump to the point page.
93 // if there are any pending transfers, incoming or outgoing, stay on this
122 // if there are any pending transfers, incoming or outgoing, stay on this
94 // page, because those can only be completed/cancelled here.
123 // page, because those can only be completed/cancelled here.
95 useEffect(() => {
124 useEffect(() => {
125+ if (Nothing.hasInstance(maybeOutgoingPoints)) {
96 controlledPoints.matchWith({
128 controlledPoints.matchWith({
97 Nothing: () => null,
129 Nothing: () => null,
98 Just: r => {
130 Just: r => {
@@ -108,8 +140,11 @@ export default function Points() {
108 const incoming = p.value.incomingPoints.filter(
140 const incoming = p.value.incomingPoints.filter(
109 p => !rejectedPoints.includes(p)
141 p => !rejectedPoints.includes(p)
111− //TODO && outgoing.length === 0
143+ if (
112− if (all.length === 1 && incoming.length === 0) {
145+ incoming.length === 0 &&
146+ maybeOutgoingPoints.value.length === 0
113 setPointCursor(Just(all[0]));
148 setPointCursor(Just(all[0]));
114 popAndPush(names.POINT);
149 popAndPush(names.POINT);
@@ -117,7 +152,14 @@ export default function Points() {
120− }, [controlledPoints, rejectedPoints, setPointCursor, popAndPush, names]);
156+ controlledPoints,
158+ maybeOutgoingPoints,
122 const address = need.addressFromWallet(wallet);
164 const address = need.addressFromWallet(wallet);
@@ -132,12 +174,7 @@ export default function Points() {
132 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
174 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
133 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
175 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
134 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
176 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
135− const outgoingPoints = ownedPoints.filter(point =>
177+ const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
136− getDetails(point).matchWith({
137− Nothing: () => false,
138− Just: p => hasTransferProxy(p.value),
142 const multipassPoints = [
179 const multipassPoints = [
143 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
180 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),