on master help sign in
Merge pull request #190 from urbit/mino-implied-pages

Implied ticket & navigation

commitb447b718ba7e9c2e5a89ab2754f56a87a24a27a8 authorFang <Fang-@users.noreply.github.com> dateFri 12 Jul 2019, 20:43 (7 years ago) parenta531c303f629b7
3 files changed+29−4
src/lib/useImpliedTicket.js+14 src/views/Activate/ActivateCode.js+3 src/views/Landing.js+12−4
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';
2121import { generateTemporaryOwnershipWallet } from 'lib/walletgen';
2222import { useActivateFlow } from './ActivateFlow';
2323import { useLocalRouter } from 'lib/LocalRouter';
24+import useImpliedTicket from 'lib/useImpliedTicket';
2425
2526export default function ActivateCode() {
2627 const history = useHistory();
2728 const { names, push } = useLocalRouter();
2829 const { contracts } = useNetwork();
30+ const impliedTicket = useImpliedTicket();
2931 const [generalError, setGeneralError] = useState();
3032 const [deriving, setDeriving] = useState(false);
3133 const {
@@ -39,6 +41,7 @@ export default function ActivateCode() {
3941 const [ticketInput, { pass: validTicket }] = useTicketInput({
4042 name: 'ticket',
4143 label: 'Code',
44+ initialValue: impliedTicket || '',
4245 autoFocus: true,
4346 });
4447
src/views/Landing.js+12−4
@@ -3,12 +3,20 @@ import { H1, P } from 'indigo-react';
33
44import { ROUTE_NAMES } from '../lib/routeNames';
55import { useHistory } from '../store/history';
6+import useImpliedPoint from 'lib/useImpliedPoint';
7+import useImpliedTicket from 'lib/useImpliedTicket';
68
79import View from 'components/View';
810import { ForwardButton } from 'components/Buttons';
911
1012function 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+ }
1220
1321 return (
1422 <View>
@@ -22,21 +30,21 @@ function Landing() {
2230 <ForwardButton
2331 className="mt3"
2432 detail="If you were sent an Azimuth invite code."
25− onClick={() => history.push(ROUTE_NAMES.ACTIVATE)}>
33+ onClick={() => push(names.ACTIVATE)}>
2634 Activate a Point
2735 </ForwardButton>
2836
2937 <ForwardButton
3038 className="mt3"
3139 detail="Login to an activated point."
32− onClick={() => history.push(ROUTE_NAMES.LOGIN)}>
40+ onClick={() => push(names.LOGIN)}>
3341 Login
3442 </ForwardButton>
3543
3644 <ForwardButton
3745 className="mt3"
3846 detail="View an Azimuth point without signing into a wallet."
39− onClick={() => history.push(ROUTE_NAMES.VIEW_POINT)}>
47+ onClick={() => push(names.VIEW_POINT)}>
4048 View a Point
4149 </ForwardButton>
4250 </View>