on master help sign in
Don't do "smart" routing in Login view
1215e01Fang
src/views/Login.js+3−47
@@ -1,14 +1,10 @@
1import React, { useCallback, useState } from 'react';
1import React, { useCallback, useState } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
2+import { Nothing } from 'folktale/maybe';
3−import * as azimuth from 'azimuth-js';
4import { H4, Grid } from 'indigo-react';
3import { H4, Grid } from 'indigo-react';
5
4
6import { useHistory } from 'store/history';
5import { useHistory } from 'store/history';
7−import { useNetwork } from 'store/network';
8import { useWallet } from 'store/wallet';
6import { useWallet } from 'store/wallet';
9−import { usePointCursor } from 'store/pointCursor';
10
7
11−import * as need from 'lib/need';
12import { WALLET_TYPES } from 'lib/wallet';
8import { WALLET_TYPES } from 'lib/wallet';
13
9
14import View from 'components/View';
10import View from 'components/View';
@@ -64,11 +60,7 @@ const walletTypeToViewName = walletType => {
64export default function Login() {
60export default function Login() {
65 // globals
61 // globals
66 const { pop, push, names } = useHistory();
62 const { pop, push, names } = useHistory();
67− const { contracts } = useNetwork();
68 const { wallet, walletType } = useWallet();
63 const { wallet, walletType } = useWallet();
69− const { pointCursor, setPointCursor } = usePointCursor();
70−
71− const [deducing, setDeducing] = useState(false);
72
64
73 // inputs
65 // inputs
74 const [currentTab, setCurrentTab] = useState(
66 const [currentTab, setCurrentTab] = useState(
@@ -80,45 +72,10 @@ export default function Login() {
80 names.ACTIVATE,
72 names.ACTIVATE,
81 ]);
73 ]);
82
74
83− const goToPoints = useCallback(() => {
75+ const doContinue = useCallback(() => {
84 push(names.POINTS);
76 push(names.POINTS);
85 }, [push, names]);
77 }, [push, names]);
86
78
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−
122 return (
79 return (
123 <View pop={pop} inset>
80 <View pop={pop} inset>
124 <Grid>
81 <Grid>
@@ -142,8 +99,7 @@ export default function Login() {
142 as={ForwardButton}
99 as={ForwardButton}
143 solid
100 solid
144 className="mt2"
101 className="mt2"
145− loading={deducing}
146− disabled={Nothing.hasInstance(wallet) || deducing}
102+ disabled={Nothing.hasInstance(wallet)}
147 onClick={doContinue}>
103 onClick={doContinue}>
148 Continue
104 Continue
149 </Grid.Item>
105 </Grid.Item>