on 4b0ca21 help sign in
bridge/src/views/UrbitID/DownloadKeys.js
75 lines 2.2 kB history raw
1import React, { useCallback, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as need from 'lib/need';
5import { usePointCursor } from 'store/pointCursor';
7import { DownloadButton, RestartButton } from 'components/Buttons';
8import PaperBuilder from 'components/PaperBuilder';
10import { downloadWallet } from 'lib/invite';
11import useKeyfileGenerator from 'lib/useKeyfileGenerator';
13import { useWallet } from 'store/wallet';
14import { Grid, P } from 'indigo-react';
15import ViewHeader from 'components/ViewHeader';
16import { useLocalRouter } from 'lib/LocalRouter';
18export default function AdminRedownload() {
19 const { urbitWallet } = useWallet();
20 const { pointCursor } = usePointCursor();
21 const { pop } = useLocalRouter();
23 const _urbitWallet = need.wallet(urbitWallet);
24 const point = need.point(pointCursor);
26 const { keyfile, filename } = useKeyfileGenerator();
28 const [paper, setPaper] = useState(Nothing());
29 const [downloaded, setDownloaded] = useState(false);
31 const doDownload = useCallback(() => {
32 downloadWallet(paper.value, keyfile, filename);
33 setDownloaded(true);
34 }, [paper, keyfile, filename, setDownloaded]);
36 const goBack = useCallback(() => pop(), [pop]);
38 return (
39 <>
40 <Grid>
41 <Grid.Item full as={ViewHeader}>
42 Download Passport
43 </Grid.Item>
44 <Grid.Item full as={P}>
45 After you’ve downloaded your passport, back up the ticket manually or
46 store on a trusted device.
47 </Grid.Item>
48 {downloaded ? (
49 <Grid.Item full as={RestartButton} solid onClick={goBack}>
50 Done
51 </Grid.Item>
52 ) : (
53 <Grid.Item
54 full
55 as={DownloadButton}
56 solid
57 disabled={Nothing.hasInstance(paper)}
58 onClick={doDownload}>
59 {paper.matchWith({
60 Nothing: () => 'Printing and folding...',
61 Just: _ => 'Download paper wallet',
62 })}
63 </Grid.Item>
64 )}
65 </Grid>
66 <PaperBuilder
67 point={point}
68 wallets={[_urbitWallet]}
69 callback={paper => {
70 setPaper(Just(paper));
71 }}
72 />
73 </>
74 );