1import React, { useCallback, useMemo, useState } from 'react';
2import * as need from 'lib/need';
3import cn from 'classnames';
5import ActivateView from './ActivateView';
6import { Box, Text } from '@tlon/indigo-react';
7import { composeValidator, buildPatqValidator } from 'form/validators';
8import { DEFAULT_FADE_TIMEOUT } from 'lib/constants';
9import { FadeableActivateButton as ActivateButton } from './ActivateButton';
10import { FadeableActivateHeader as ActivateHeader } from './ActivateHeader';
11import { FadeableActivateParagraph as ActivateParagraph } from './ActivateParagraph';
12import { FadeableActivateSteps as ActivateSteps } from './ActivateSteps';
13import { isDevelopment } from 'lib/flags';
14import { ticketFromSegments, ticketToSegments } from 'form/formatters';
15import { timeout } from 'lib/timeout';
16import { useActivateFlow } from './useActivateFlow';
17import { useLocalRouter } from 'lib/LocalRouter';
18import { validateExactly } from 'lib/validators';
19import BridgeForm from 'form/BridgeForm';
20import FormError from 'form/FormError';
21import useFadeIn from './useFadeIn';
22import { HiddenInput, TicketSegmentInput } from 'form/Inputs';
23import View from 'components/View';
25import './MasterKeyConfirm.scss';
27const MasterKeyConfirm = () => {
28 const { inviteMasterTicketWallet, setIsIn }: any = useActivateFlow();
29 const { ticket } = need.wallet(inviteMasterTicketWallet);
30 const { push, names }: any = useLocalRouter();
31 const STUB_VERIFY_TICKET = isDevelopment;
32 const ticketSegments = useMemo(() => ticketToSegments(ticket), [ticket]);
33 const [showError, setShowError] = useState<boolean>(false);
35 const onValues = useCallback(({ valid, values, form }) => {
36 const { ticket0, ticket1, ticket2, ticket3 } = values;
37 const tickets = [ticket0, ticket1, ticket2, ticket3];
38 const allTicketsPopulated = tickets.every(t => t?.length === 6);
40 setShowError(!valid && allTicketsPopulated);
42 form.change('ticket', ticketFromSegments(tickets));
45 const validate = useMemo(
48 ticket: buildPatqValidator([
49 validateExactly(ticket, 'Does not match expected master ticket.'),
55 const initialValues = useMemo(
57 ticket: STUB_VERIFY_TICKET ? ticket : undefined,
58 ticket0: STUB_VERIFY_TICKET ? ticketSegments[0] : undefined,
59 ticket1: STUB_VERIFY_TICKET ? ticketSegments[1] : undefined,
60 ticket2: STUB_VERIFY_TICKET ? ticketSegments[2] : undefined,
61 ticket3: STUB_VERIFY_TICKET ? ticketSegments[3].slice(0, 5) : undefined,
63 [STUB_VERIFY_TICKET, ticket, ticketSegments]
66 const goToTransfer = useCallback(async () => {
68 await timeout(DEFAULT_FADE_TIMEOUT); // Pause for UI fade animation
70 }, [names.TRANSFER, push, setIsIn]);
72 const goBack = useCallback(async () => {
74 await timeout(DEFAULT_FADE_TIMEOUT); // Pause for UI fade animation
75 push(names.DOWNLOAD, { skipAnimationDelay: true });
76 }, [names.DOWNLOAD, push, setIsIn]);
78 const header = useMemo(() => {
81 <ActivateHeader content={'Confirm Backup'} />
84 'To confirm that you stored your Master Ticket somewhere safe, enter it below.'
94 <View inset id={'master-key-confirm'} hideBack>
99 gridAreas={"'header' 'content'"}>
100 <Box className={'content'}>
104 flexFlow: 'column nowrap',
107 justifyContent: 'center',
108 alignItems: 'center',
111 afterSubmit={goToTransfer}
113 initialValues={initialValues}>
114 {({ handleSubmit, valid }: any) => (
115 <Box className="form-inner">
116 <Box className="inputs-outer">
118 <Box height={'24px'}>
119 {/* this is a flexbox placeholder to balance the error message below*/}
122 <Box className="inputs-inner">
123 {ticketSegments.map((segment, i) => {
128 flexDirection={'row'}
131 className={cn('ticket-input', {
132 'has-error': showError,
137 {i < ticketSegments.length - 1 ? (
152 <Text className="error-message">
153 The Master Ticket you entered is incorrect.
161 style={{ display: 'none' }}
166 <Box as={FormError} />
170 flexDirection="column"
173 justifyContent="flex-end"
175 <ActivateButton disabled={!valid} onClick={handleSubmit}>
184 <ActivateSteps currentStep={2} totalSteps={4} overrideFadeIn={true} />
189export default MasterKeyConfirm;
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