on master help sign in
Merge branch 'mino' into feat/final-form

merge notes: - remove continue buttons and rename doContinue to goHome

commit017d832be0de5d1aba457b49ec2fe422785a83cc authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateFri 9 Aug 2019, 18:55 (7 years ago) parentdc028a2debe822
3 files changed+77−54
src/views/Activate/PassportTransfer.js+1−6 src/views/Login.js+2−40 src/views/Points.js+74−8
src/views/Activate/PassportTransfer.js+1−6
@@ -57,12 +57,7 @@ export default function PassportTransfer({ className, resetActivateRouter }) {
5757 const [needFunds, setNeedFunds] = useState();
5858
5959 const goToLogin = useCallback(
60− () =>
61− replaceWith([
62− { key: names.LOGIN },
63− { key: names.POINTS },
64− { key: names.POINT },
65− ]),
60+ () => replaceWith([{ key: names.LOGIN }, { key: names.POINT }]),
6661 [replaceWith, names]
6762 );
6863
src/views/Login.js+2−40
@@ -1,14 +1,9 @@
11import React, { useCallback, useState } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
3−import * as azimuth from 'azimuth-js';
42import { H4, Grid } from 'indigo-react';
53
64import { useHistory } from 'store/history';
7−import { useNetwork } from 'store/network';
85import { useWallet } from 'store/wallet';
9−import { usePointCursor } from 'store/pointCursor';
106
11−import * as need from 'lib/need';
127import { WALLET_TYPES } from 'lib/wallet';
138
149import View from 'components/View';
@@ -64,9 +59,7 @@ const walletTypeToViewName = walletType => {
6459export default function Login() {
6560 // globals
6661 const { pop, push, names } = useHistory();
67− const { contracts } = useNetwork();
68− const { wallet, walletType } = useWallet();
69− const { pointCursor, setPointCursor } = usePointCursor();
62+ const { walletType } = useWallet();
7063
7164 // inputs
7265 const [currentTab, setCurrentTab] = useState(
@@ -78,41 +71,10 @@ export default function Login() {
7871 names.ACTIVATE,
7972 ]);
8073
81− const goToPoints = useCallback(() => {
74+ const goHome = useCallback(() => {
8275 push(names.POINTS);
8376 }, [push, names]);
8477
85− const goToPoint = useCallback(() => {
86− goToPoints();
87− push(names.POINT);
88− }, [goToPoints, push, names]);
89−
90− const goHome = useCallback(async () => {
91− const _wallet = need.wallet(wallet);
92− const _contracts = need.contracts(contracts);
93−
94− let deduced = pointCursor;
95− // if no point cursor set by login logic, try to deduce it
96− if (Nothing.hasInstance(deduced)) {
97− const owned = await azimuth.azimuth.getOwnedPoints(
98− _contracts,
99− _wallet.address
100− );
101− if (owned.length === 1) {
102− deduced = Just(owned[0]);
103− }
104− }
105−
106− // if we have a deduced point or one in the global context,
107− // navigate to that specific point, otherwise navigate to list of points
108− if (Just.hasInstance(deduced)) {
109− setPointCursor(deduced);
110− goToPoint();
111− } else {
112− goToPoints();
113− }
114− }, [contracts, pointCursor, setPointCursor, wallet, goToPoint, goToPoints]);
115−
11678 return (
11779 <View pop={pop} inset>
11880 <Grid>
src/views/Points.js+74−8
@@ -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)),