on master help sign in
Merge branch 'mino' into feat/final-form
017d832Matt Condon (shrugs)
src/views/Activate/PassportTransfer.js+1−6
@@ -57,12 +57,7 @@ export default function PassportTransfer({ className, resetActivateRouter }) {
57 const [needFunds, setNeedFunds] = useState();
57 const [needFunds, setNeedFunds] = useState();
58
58
59 const goToLogin = useCallback(
59 const goToLogin = useCallback(
60− () =>
61− replaceWith([
62− { key: names.LOGIN },
60+ () => replaceWith([{ key: names.LOGIN }, { key: names.POINT }]),
63− { key: names.POINTS },
64− { key: names.POINT },
65− ]),
66 [replaceWith, names]
61 [replaceWith, names]
67 );
62 );
68
63
src/views/Login.js+2−40
@@ -1,14 +1,9 @@
1import React, { useCallback, useState } from 'react';
1import React, { useCallback, useState } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
3−import * as azimuth from 'azimuth-js';
4import { H4, Grid } from 'indigo-react';
2import { H4, Grid } from 'indigo-react';
5
3
6import { useHistory } from 'store/history';
4import { useHistory } from 'store/history';
7−import { useNetwork } from 'store/network';
8import { useWallet } from 'store/wallet';
5import { useWallet } from 'store/wallet';
9−import { usePointCursor } from 'store/pointCursor';
10
6
11−import * as need from 'lib/need';
12import { WALLET_TYPES } from 'lib/wallet';
7import { WALLET_TYPES } from 'lib/wallet';
13
8
14import View from 'components/View';
9import View from 'components/View';
@@ -64,9 +59,7 @@ const walletTypeToViewName = walletType => {
64export default function Login() {
59export default function Login() {
65 // globals
60 // globals
66 const { pop, push, names } = useHistory();
61 const { pop, push, names } = useHistory();
67− const { contracts } = useNetwork();
68− const { wallet, walletType } = useWallet();
62+ const { walletType } = useWallet();
69− const { pointCursor, setPointCursor } = usePointCursor();
70
63
71 // inputs
64 // inputs
72 const [currentTab, setCurrentTab] = useState(
65 const [currentTab, setCurrentTab] = useState(
@@ -78,41 +71,10 @@ export default function Login() {
78 names.ACTIVATE,
71 names.ACTIVATE,
79 ]);
72 ]);
80
73
81− const goToPoints = useCallback(() => {
74+ const goHome = useCallback(() => {
82 push(names.POINTS);
75 push(names.POINTS);
83 }, [push, names]);
76 }, [push, names]);
84
77
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−
116 return (
78 return (
117 <View pop={pop} inset>
79 <View pop={pop} inset>
118 <Grid>
80 <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';
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';
@@ -79,7 +79,7 @@ function ActionButtons({ actions = [] }) {
79
79
80export default function Points() {
80export default function Points() {
81 const { wallet } = useWallet();
81 const { wallet } = useWallet();
82− const { pop, push, names } = useHistory();
82+ const { pop, push, popAndPush, names } = useHistory();
83 const { setPointCursor } = usePointCursor();
83 const { setPointCursor } = usePointCursor();
84 const { controlledPoints, getDetails } = usePointCache();
84 const { controlledPoints, getDetails } = usePointCache();
85 const isEclipticOwner = useIsEclipticOwner();
85 const isEclipticOwner = useIsEclipticOwner();
@@ -88,6 +88,77 @@ export default function Points() {
88 addRejectedPoint,
88 addRejectedPoint,
89 ] = useRejectedIncomingPointTransfers();
89 ] = useRejectedIncomingPointTransfers();
90
90
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+
91 const address = need.addressFromWallet(wallet);
162 const address = need.addressFromWallet(wallet);
92
163
93 const loading = Nothing.hasInstance(controlledPoints);
164 const loading = Nothing.hasInstance(controlledPoints);
@@ -101,12 +172,7 @@ export default function Points() {
101 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
172 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
102 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
173 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
103 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
174 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
104− const outgoingPoints = ownedPoints.filter(point =>
175+ const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
105− getDetails(point).matchWith({
106− Nothing: () => false,
107− Just: p => hasTransferProxy(p.value),
108− })
109− );
110
176
111 const allPoints = [
177 const allPoints = [
112 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
178 ...ownedPoints.filter(p => !outgoingPoints.includes(p)),