on master help sign in
Account for outgoing transfers
commit81fb2b6bf3ecea60f056aebc44629e8d124839e7 authorFang <git@fang.io> dateFri 2 Aug 2019, 19:55 (7 years ago) parent1215e01
1 file changed+47−10
src/views/Points.js+47−10
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';
22import { Just, Nothing } from 'folktale/maybe';
33import { Grid, H5, H1, HelpText, LinkButton, Flex } from 'indigo-react';
44import { get } from 'lodash';
@@ -88,11 +88,43 @@ export default function Points() {
8888 addRejectedPoint,
8989 ] = useRejectedIncomingPointTransfers();
9090
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+
91120 // if we can only interact with a single point, forget about the existence
92121 // of this page and jump to the point page.
93122 // if there are any pending transfers, incoming or outgoing, stay on this
94123 // page, because those can only be completed/cancelled here.
95124 useEffect(() => {
125+ if (Nothing.hasInstance(maybeOutgoingPoints)) {
126+ return;
127+ }
96128 controlledPoints.matchWith({
97129 Nothing: () => null,
98130 Just: r => {
@@ -108,8 +140,11 @@ export default function Points() {
108140 const incoming = p.value.incomingPoints.filter(
109141 p => !rejectedPoints.includes(p)
110142 );
111− //TODO && outgoing.length === 0
112− if (all.length === 1 && incoming.length === 0) {
143+ if (
144+ all.length === 1 &&
145+ incoming.length === 0 &&
146+ maybeOutgoingPoints.value.length === 0
147+ ) {
113148 setPointCursor(Just(all[0]));
114149 popAndPush(names.POINT);
115150 }
@@ -117,7 +152,14 @@ export default function Points() {
117152 });
118153 },
119154 });
120− }, [controlledPoints, rejectedPoints, setPointCursor, popAndPush, names]);
155+ }, [
156+ controlledPoints,
157+ rejectedPoints,
158+ maybeOutgoingPoints,
159+ setPointCursor,
160+ popAndPush,
161+ names,
162+ ]);
121163
122164 const address = need.addressFromWallet(wallet);
123165
@@ -132,12 +174,7 @@ export default function Points() {
132174 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
133175 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
134176 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
135− const outgoingPoints = ownedPoints.filter(point =>
136− getDetails(point).matchWith({
137− Nothing: () => false,
138− Just: p => hasTransferProxy(p.value),
139− })
140− );
177+ const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
141178
142179 const multipassPoints = [
143180 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),