@@ -1,4 +1,4 @@
1−import React, { useCallback } from 'react';
1+import React, { useCallback, useEffect, useMemo } 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,77 @@ export default function Points() {
8888 addRejectedPoint,
8989 ] = useRejectedIncomingPointTransfers();
9090
91+ const maybeOutgoingPoints = useMemo(
92+ () =>
93+ controlledPoints.chain(points =>
94+ points.matchWith({
95+ Error: () => Nothing(),
96+ Ok: c => {
97+ const points = c.value.ownedPoints.map(point =>
98+ getDetails(point).chain(details =>
99+ Just({ point: point, has: hasTransferProxy(details) })
100+ )
101+ );
102+ // if we have details for every point,
103+ // return the array of pending transfers.
104+ if (points.every(p => Just.hasInstance(p))) {
105+ const outgoing = points
106+ .filter(p => p.value.has)
107+ .map(p => p.value.point);
108+ return Just(outgoing);
109+ } else {
110+ return Nothing();
111+ }
112+ },
113+ })
114+ ),
115+ [getDetails, controlledPoints]
116+ );
117+
118+ // if we can only interact with a single point, forget about the existence
119+ // of this page and jump to the point page.
120+ // if there are any pending transfers, incoming or outgoing, stay on this
121+ // page, because those can only be completed/cancelled here.
122+ useEffect(() => {
123+ if (Nothing.hasInstance(maybeOutgoingPoints)) {
124+ return;
125+ }
126+ controlledPoints.matchWith({
127+ Nothing: () => null,
128+ Just: r => {
129+ r.value.matchWith({
130+ Error: () => null,
131+ Ok: c => {
132+ let all = [
133+ ...c.value.ownedPoints,
134+ ...c.value.votingPoints,
135+ ...c.value.managingPoints,
136+ ...c.value.spawningPoints,
137+ ];
138+ const incoming = c.value.incomingPoints.filter(
139+ p => !rejectedPoints.includes(p)
140+ );
141+ if (
142+ all.length === 1 &&
143+ incoming.length === 0 &&
144+ maybeOutgoingPoints.value.length === 0
145+ ) {
146+ setPointCursor(Just(all[0]));
147+ popAndPush(names.POINT);
148+ }
149+ },
150+ });
151+ },
152+ });
153+ }, [
154+ controlledPoints,
155+ rejectedPoints,
156+ maybeOutgoingPoints,
157+ setPointCursor,
158+ popAndPush,
159+ names,
160+ ]);
161+
91162 const address = need.addressFromWallet(wallet);
92163
93164 const loading = Nothing.hasInstance(controlledPoints);
@@ -101,12 +172,7 @@ export default function Points() {
101172 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
102173 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
103174 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
104− const outgoingPoints = ownedPoints.filter(point =>
105− getDetails(point).matchWith({
106− Nothing: () => false,
107− Just: p => hasTransferProxy(p.value),
108− })
109− );
175+ const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
110176
111177 const allPoints = [
112178 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),