on master help sign in
Don't do "smart" routing in Login view

Logic can live entirely in Points view.

commit1215e01dcf60b9c145cb9acfade0653cf164d517 authorFang <git@fang.io> dateFri 2 Aug 2019, 16:36 (7 years ago) parentf6ffb6d
1 file changed+3−47
src/views/Login.js+3−47
src/views/Login.js+3−47
@@ -1,14 +1,10 @@
11import React, { useCallback, useState } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
3−import * as azimuth from 'azimuth-js';
2+import { Nothing } from 'folktale/maybe';
43import { H4, Grid } from 'indigo-react';
54
65import { useHistory } from 'store/history';
7−import { useNetwork } from 'store/network';
86import { useWallet } from 'store/wallet';
9−import { usePointCursor } from 'store/pointCursor';
107
11−import * as need from 'lib/need';
128import { WALLET_TYPES } from 'lib/wallet';
139
1410import View from 'components/View';
@@ -64,11 +60,7 @@ const walletTypeToViewName = walletType => {
6460export default function Login() {
6561 // globals
6662 const { pop, push, names } = useHistory();
67− const { contracts } = useNetwork();
6863 const { wallet, walletType } = useWallet();
69− const { pointCursor, setPointCursor } = usePointCursor();
70−
71− const [deducing, setDeducing] = useState(false);
7264
7365 // inputs
7466 const [currentTab, setCurrentTab] = useState(
@@ -80,45 +72,10 @@ export default function Login() {
8072 names.ACTIVATE,
8173 ]);
8274
83− const goToPoints = useCallback(() => {
75+ const doContinue = useCallback(() => {
8476 push(names.POINTS);
8577 }, [push, names]);
8678
87− const goToPoint = useCallback(() => {
88− goToPoints();
89− push(names.POINT);
90− }, [goToPoints, push, names]);
91−
92− const doContinue = useCallback(async () => {
93− const _wallet = need.wallet(wallet);
94− const _contracts = need.contracts(contracts);
95−
96− setDeducing(true);
97−
98− let deduced = pointCursor;
99− // if no point cursor set by login logic, try to deduce it
100− if (Nothing.hasInstance(deduced)) {
101− const owned = await azimuth.azimuth.getOwnedPoints(
102− _contracts,
103− _wallet.address
104− );
105− if (owned.length === 1) {
106− deduced = Just(owned[0]);
107− }
108− }
109−
110− setDeducing(false);
111−
112− // if we have a deduced point or one in the global context,
113− // navigate to that specific point, otherwise navigate to list of points
114− if (Just.hasInstance(deduced)) {
115− setPointCursor(deduced);
116− goToPoint();
117− } else {
118− goToPoints();
119− }
120− }, [contracts, pointCursor, setPointCursor, wallet, goToPoint, goToPoints]);
121−
12279 return (
12380 <View pop={pop} inset>
12481 <Grid>
@@ -142,8 +99,7 @@ export default function Login() {
14299 as={ForwardButton}
143100 solid
144101 className="mt2"
145− loading={deducing}
146− disabled={Nothing.hasInstance(wallet) || deducing}
102+ disabled={Nothing.hasInstance(wallet)}
147103 onClick={doContinue}>
148104 Continue
149105 </Grid.Item>