1import React, { useCallback, useEffect, useMemo, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as need from 'lib/need';
5import { ActivateSteps } from './ActivateSteps';
6import { Box } from '@tlon/indigo-react';
7import { FadeableActivateButton as ActivateButton } from './ActivateButton';
8import { FadeableActivateHeader as ActivateHeader } from './ActivateHeader';
9import { FadeableActivateParagraph as ActivateParagraph } from './ActivateParagraph';
10import { FadeableDangerBox as DangerBox } from './DangerBox';
11import { FadeableMasterKeyCopy as MasterKeyCopy } from './MasterKeyCopy';
12import { FadeableMasterKeyPresenter as MasterKeyPresenter } from './MasterKeyPresenter';
13import { useActivateFlow } from './useActivateFlow';
14import ActivateView from './ActivateView';
15import { useLocalRouter } from 'lib/LocalRouter';
16import PaperBuilder from 'components/PaperBuilder';
17import { DEFAULT_FADE_TIMEOUT, MASTER_KEY_DURATION } from 'lib/constants';
18import { timeout } from 'lib/timeout';
19import { downloadWallet } from 'lib/invite';
20import View from 'components/View';
21import { useActivationKeyfileGenerator } from 'lib/useKeyfileGenerator';
23const MasterKeyDownload = () => {
26 inviteMasterTicketWallet,
31 }: any = useActivateFlow();
32 const { data, push, names }: any = useLocalRouter();
33 const point = need.point(derivedPoint);
34 const wallet = need.wallet(inviteMasterTicketWallet);
35 const ticket = wallet.ticket.replace('~', '');
37 const [paper, setPaper] = useState(Nothing());
38 const [triggerAnimation, setTriggerAnimation] = useState<boolean>(false);
40 const skipAnimationDelay = useMemo(() => {
41 return data?.skipAnimationDelay ? true : false;
44 const pointAsString = derivedPoint.matchWith({
46 Just: (p: any) => p.value.toFixed(),
49 const { keyfile, filename } = useActivationKeyfileGenerator({
51 wallets: [inviteWallet.value, inviteMasterTicketWallet.value],
54 // sync paper value to activation state
66 const download = useCallback(async () => {
67 await downloadWallet(paper.getOrElse([]), keyfile, filename);
68 }, [paper, keyfile, filename]);
70 const onDownloadClick = useCallback(async () => {
73 await timeout(DEFAULT_FADE_TIMEOUT); // Pause for UI fade animation
75 }, [download, setIsIn, push, names.CONFIRM]);
77 const header = useMemo(() => {
80 <ActivateHeader content={'Back up your Master Ticket.'} />
83 'Download and store your backup somewhere safe, like a security deposit box or password manager.'
90 const footer = useMemo(() => {
92 <ActivateButton onClick={onDownloadClick}>
93 {'Download Backup (Passport)'}
96 }, [onDownloadClick]);
98 const fadeIn = useCallback(() => {
99 setTriggerAnimation(true);
103 const delayedFadeIn = useCallback(async () => {
106 }, MASTER_KEY_DURATION);
110 if (skipAnimationDelay) {
119 }, [delayedFadeIn, fadeIn, setIsIn, skipAnimationDelay]);
122 <View inset hideBack>
125 header={triggerAnimation && header}
126 footer={triggerAnimation && footer}>
128 alignItems={'center'}
130 flexDirection={'column'}
133 justifyContent={'space-evenly'}>
135 overrideFadeIn={triggerAnimation && isIn}
136 className={`mv8 ${!isIn ? 'hidden' : ''}`}>
137 Never share your Master Ticket with anyone.
140 <MasterKeyPresenter ticket={ticket} overrideFadeIn={true} />
144 overrideFadeIn={triggerAnimation && isIn}
145 className={`mv5 ${!isIn ? 'hidden' : ''}`}
149 <ActivateSteps currentStep={1} totalSteps={4} />
151 point={pointAsString}
153 callback={(data: any) => {
154 setPaper(Just(data));
161export default MasterKeyDownload;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list