on master help sign in
Merge pull request #190 from urbit/mino-implied-pages
b447b71Fang
src/lib/useImpliedTicket.jsnew file+14
@@ -0,0 +1,14 @@
1+import * as ob from 'urbit-ob';
2+
3+import { prependSig } from './transformers';
4+
5+/**
6+ * pull the suggested ticket from the #hash in the url
7+ */
8+export default function useImpliedTicket() {
9+ const hash = window.location.hash.slice(1);
10+ const ticket = prependSig(hash);
11+ const isValid = ob.isValidPatq(ticket);
12+
13+ return isValid ? ticket : null;
14+}
src/views/Activate/ActivateCode.js+3
@@ -21,11 +21,13 @@ import { generateWallet } from 'lib/invite';
21import { generateTemporaryOwnershipWallet } from 'lib/walletgen';
21import { generateTemporaryOwnershipWallet } from 'lib/walletgen';
22import { useActivateFlow } from './ActivateFlow';
22import { useActivateFlow } from './ActivateFlow';
23import { useLocalRouter } from 'lib/LocalRouter';
23import { useLocalRouter } from 'lib/LocalRouter';
24+import useImpliedTicket from 'lib/useImpliedTicket';
24
25
25export default function ActivateCode() {
26export default function ActivateCode() {
26 const history = useHistory();
27 const history = useHistory();
27 const { names, push } = useLocalRouter();
28 const { names, push } = useLocalRouter();
28 const { contracts } = useNetwork();
29 const { contracts } = useNetwork();
30+ const impliedTicket = useImpliedTicket();
29 const [generalError, setGeneralError] = useState();
31 const [generalError, setGeneralError] = useState();
30 const [deriving, setDeriving] = useState(false);
32 const [deriving, setDeriving] = useState(false);
31 const {
33 const {
@@ -39,6 +41,7 @@ export default function ActivateCode() {
39 const [ticketInput, { pass: validTicket }] = useTicketInput({
41 const [ticketInput, { pass: validTicket }] = useTicketInput({
40 name: 'ticket',
42 name: 'ticket',
41 label: 'Code',
43 label: 'Code',
44+ initialValue: impliedTicket || '',
42 autoFocus: true,
45 autoFocus: true,
43 });
46 });
44
47
src/views/Landing.js+12−4
@@ -3,12 +3,20 @@ import { H1, P } from 'indigo-react';
3
3
4import { ROUTE_NAMES } from '../lib/routeNames';
4import { ROUTE_NAMES } from '../lib/routeNames';
5import { useHistory } from '../store/history';
5import { useHistory } from '../store/history';
6+import useImpliedPoint from 'lib/useImpliedPoint';
7+import useImpliedTicket from 'lib/useImpliedTicket';
6
8
7import View from 'components/View';
9import View from 'components/View';
8import { ForwardButton } from 'components/Buttons';
10import { ForwardButton } from 'components/Buttons';
9
11
10function Landing() {
12function Landing() {
11− const history = useHistory();
13+ const { push, names } = useHistory();
14+
15+ if (useImpliedPoint()) {
16+ push(names.LOGIN);
17+ } else if (useImpliedTicket()) {
18+ push(names.ACTIVATE);
19+ }
12
20
13 return (
21 return (
14 <View>
22 <View>
@@ -22,21 +30,21 @@ function Landing() {
22 <ForwardButton
30 <ForwardButton
23 className="mt3"
31 className="mt3"
24 detail="If you were sent an Azimuth invite code."
32 detail="If you were sent an Azimuth invite code."
25− onClick={() => history.push(ROUTE_NAMES.ACTIVATE)}>
33+ onClick={() => push(names.ACTIVATE)}>
26 Activate a Point
34 Activate a Point
27 </ForwardButton>
35 </ForwardButton>
28
36
29 <ForwardButton
37 <ForwardButton
30 className="mt3"
38 className="mt3"
31 detail="Login to an activated point."
39 detail="Login to an activated point."
32− onClick={() => history.push(ROUTE_NAMES.LOGIN)}>
40+ onClick={() => push(names.LOGIN)}>
33 Login
41 Login
34 </ForwardButton>
42 </ForwardButton>
35
43
36 <ForwardButton
44 <ForwardButton
37 className="mt3"
45 className="mt3"
38 detail="View an Azimuth point without signing into a wallet."
46 detail="View an Azimuth point without signing into a wallet."
39− onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
47+ onClick={() => push(names.VIEW_POINT)}>
40 View a Point
48 View a Point
41 </ForwardButton>
49 </ForwardButton>
42 </View>
50 </View>