on d760cbf help sign in
bridge/src/views/Reticket/Confirm.js
63 lines 1.9 kB history raw
1import React, { useState, useCallback } from 'react';
2import * as need from 'lib/need';
3import { Just, Nothing } from 'folktale/maybe';
5import { usePointCursor } from 'store/pointCursor';
7import View from 'components/View';
8import { ForwardButton } from 'components/Buttons';
9import PaperRenderer from 'components/PaperRenderer';
11import useLifecycle from 'lib/useLifecycle';
12import { generateWallet } from 'lib/invite';
13import { useLocalRouter } from 'lib/LocalRouter';
15import { isDevelopment } from 'lib/flags';
17export default function Confirm({ newWallet, storeNewWallet }) {
18 const { push, names } = useLocalRouter();
19 const { pointCursor } = usePointCursor();
20 const point = need.point(pointCursor);
22 const [generatedWallet, setGeneratedWallet] = useState(Nothing());
24 // start generating new wallet on mount
25 //TODO also check we can pay for the transactions?
26 useLifecycle(() => {
27 (async () => {
28 const wal = await generateWallet(point);
29 if (isDevelopment) {
30 console.log('ticket for', point, wal.ticket);
31 }
32 setGeneratedWallet(Just(wal));
33 })();
34 });
36 const next = useCallback(() => push(names.DOWNLOAD), [push, names]);
38 const paperRenderer = generatedWallet.matchWith({
39 Nothing: () => null,
40 Just: gw => (
41 <PaperRenderer
42 point={point}
43 wallet={gw.value}
44 callback={paper => {
45 storeNewWallet(gw.value, paper);
46 }}
47 />
48 ),
49 });
51 return (
52 <View>
53 Maybe we should just duplicate the Login component here? Not everyone who
54 does this will be logged in with an existing ticket. Also, beware, this
55 changes your proxy addresses. If you're using smart contracts, this might
56 break them! It will also change your networking keys!
57 <ForwardButton disabled={Nothing.hasInstance(newWallet)} onClick={next}>
58 I understand, continue
59 </ForwardButton>
60 {paperRenderer}
61 </View>
62 );