1import React, { useCallback, useMemo, useRef } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import cn from 'classnames';
4import * as azimuth from 'azimuth-js';
5import * as kg from 'urbit-key-generation/dist/index';
6import { Grid, CheckboxInput } from 'indigo-react';
7import { FORM_ERROR } from 'final-form';
9import { useNetwork } from 'store/network';
10import { useWallet } from 'store/wallet';
11import { usePointCursor } from 'store/pointCursor';
13import * as need from 'lib/need';
14import { WALLET_TYPES, urbitWalletFromTicket } from 'lib/wallet';
15import useImpliedPoint from 'lib/useImpliedPoint';
16import useLoginView from 'lib/useLoginView';
17import patp2dec from 'lib/patp2dec';
18import timeout from 'lib/timeout';
20import BridgeForm from 'form/BridgeForm';
21import Condition from 'form/Condition';
22import { TicketInput, PassphraseInput, PointInput } from 'form/Inputs';
25 buildCheckboxValidator,
27 buildPassphraseValidator,
29} from 'form/validators';
30import FormError from 'form/FormError';
32import ContinueButton from './ContinueButton';
33import useSetState from 'lib/useSetState';
35export default function Ticket({ className, goHome }) {
36 useLoginView(WALLET_TYPES.TICKET);
38 const { contracts } = useNetwork();
39 const { setUrbitWallet } = useWallet();
40 const { setPointCursor } = usePointCursor();
41 const impliedPoint = useImpliedPoint();
42 const [warnings, addWarning] = useSetState();
44 const cachedUrbitWallet = useRef(Nothing());
46 const validateForm = useCallback(
47 async (values, errors) => {
52 await timeout(100); // allow ui events to flush
55 if (values.useShards) {
56 if (errors.shard1 || errors.shard2 || errors.shard3) {
60 ticket = kg.combine([values.shard1, values.shard2, values.shard3]);
66 ticket = values.ticket;
71 const _contracts = need.contracts(contracts);
72 const point = patp2dec(values.point);
74 cachedUrbitWallet.current = await urbitWalletFromTicket(
80 const [isOwner, isTransferProxy] = await Promise.all([
81 azimuth.azimuth.isOwner(
84 cachedUrbitWallet.current.ownership.keys.address
86 azimuth.azimuth.isTransferProxy(
89 cachedUrbitWallet.current.ownership.keys.address
93 const noPermissions = !isOwner && !isTransferProxy;
94 // notify the user, but allow login regardless
97 ? 'This wallet is not the owner or transfer proxy for this point.'
101 console.error(error);
103 [FORM_ERROR]: `Unable to derive wallet from ${
104 values.useShards ? 'shards' : 'ticket'
109 [addWarning, contracts]
112 const validate = useMemo(
116 usePassphrase: buildCheckboxValidator(),
117 useShards: buildCheckboxValidator(),
118 point: buildPointValidator(4),
119 ticket: buildPatqValidator(),
120 shard1: buildPatqValidator(),
121 shard2: buildPatqValidator(),
122 shard3: buildPatqValidator(),
123 passphrase: buildPassphraseValidator(),
130 const onValues = useCallback(
131 ({ valid, values }) => {
133 setUrbitWallet(Just(cachedUrbitWallet.current));
134 setPointCursor(Just(patp2dec(values.point)));
136 setUrbitWallet(Nothing());
139 [setPointCursor, setUrbitWallet]
142 const initialValues = useMemo(
144 point: impliedPoint || '',
152 <Grid className={cn('mt4', className)}>
158 initialValues={initialValues}>
159 {({ handleSubmit }) => (
161 <Grid.Item full as={PointInput} name="point" />
163 <Condition when="useShards" is={false}>
168 label="Master Ticket"
172 <Condition when="useShards" is={true}>
173 <Grid.Item full as={TicketInput} name="shard1" label="Shard 1" />
174 <Grid.Item full as={TicketInput} name="shard2" label="Shard 2" />
175 <Grid.Item full as={TicketInput} name="shard3" label="Shard 3" />
178 <Condition when="usePassphrase" is={true}>
183 label="Wallet Passphrase"
200 <Grid.Item full as={FormError} />
202 <Grid.Item full as={ContinueButton} handleSubmit={handleSubmit} />
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