on master help sign in
Account for outgoing transfers
81fb2b6Fang
src/views/Points.js+47−10
@@ -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();
90
90
91+ const maybeOutgoingPoints = useMemo(() => {
92+ return controlledPoints.matchWith({
93+ Nothing: () => Nothing(),
94+ Just: r =>
95+ r.value.matchWith({
96+ Error: () => Nothing(),
97+ Ok: c => {
98+ const points = c.value.ownedPoints.map(point =>
99+ getDetails(point).matchWith({
100+ Nothing: () => Nothing(),
101+ Just: p =>
102+ Just({ point: point, has: hasTransferProxy(p.value) }),
103+ })
104+ );
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);
112+ } else {
113+ return Nothing();
114+ }
115+ },
116+ }),
117+ });
118+ }, [getDetails, controlledPoints]);
119+
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)) {
126+ return;
127+ }
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)
110 );
142 );
111− //TODO && outgoing.length === 0
143+ if (
144+ all.length === 1 &&
112− if (all.length === 1 && incoming.length === 0) {
145+ incoming.length === 0 &&
146+ maybeOutgoingPoints.value.length === 0
147+ ) {
113 setPointCursor(Just(all[0]));
148 setPointCursor(Just(all[0]));
114 popAndPush(names.POINT);
149 popAndPush(names.POINT);
115 }
150 }
@@ -117,7 +152,14 @@ export default function Points() {
117 });
152 });
118 },
153 },
119 });
154 });
155+ }, [
120− }, [controlledPoints, rejectedPoints, setPointCursor, popAndPush, names]);
156+ controlledPoints,
157+ rejectedPoints,
158+ maybeOutgoingPoints,
159+ setPointCursor,
160+ popAndPush,
161+ names,
162+ ]);
121
163
122 const address = need.addressFromWallet(wallet);
164 const address = need.addressFromWallet(wallet);
123
165
@@ -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),
139− })
140− );
141
178
142 const multipassPoints = [
179 const multipassPoints = [
143 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
180 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),