on bc552c8 help sign in
bridge/src/views/Redownload.js
52 lines 1.3 kB history raw
1import React, { useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as need from 'lib/need';
5import { usePointCursor } from 'store/pointCursor';
7import View from 'components/View';
8import { DownloadButton } from 'components/Buttons';
9import PaperRenderer from 'components/PaperRenderer';
11import { downloadWallet } from 'lib/invite';
13import { useWallet } from 'store/wallet';
15export default function Redownload() {
16 const { urbitWallet } = useWallet();
17 const { pointCursor } = usePointCursor();
18 const point = need.point(pointCursor);
20 const [paper, setPaper] = useState(Nothing());
22 const doDownload = () => {
23 downloadWallet(paper.value);
24 };
26 const paperRenderer = paper.matchWith({
27 Nothing: () => null,
28 Just: p => (
29 <PaperRenderer
30 point={point}
31 wallet={urbitWallet.value}
32 callback={paper => {
33 setPaper(Just(paper));
34 }}
35 />
36 ),
37 });
39 return (
40 <View>
41 <DownloadButton
42 disabled={Nothing.hasInstance(paper)}
43 onClick={doDownload}>
44 {paper.matchWith({
45 Nothing: () => 'Printing and folding...',
46 Just: _ => 'Download paper wallet',
47 })}
48 </DownloadButton>
49 {paperRenderer}
50 </View>
51 );