@@ -1,6 +1,7 @@
1import React from 'react';
1import React from 'react';
2+import * as ob from 'urbit-ob';
2import { Input, AccessoryIcon } from 'indigo-react';
3import { Input, AccessoryIcon } from 'indigo-react';
3−import { useField } from 'react-final-form';
4+import { useField, useForm } from 'react-final-form';
6 convertToNumber,
7 convertToNumber,
@@ -9,10 +10,14 @@ import {
9 ensurePatFormat,
10 ensurePatFormat,
10 stripHexPrefix,
11 stripHexPrefix,
11 ensureHexPrefix,
12 ensureHexPrefix,
12} from 'form/formatters';
14} from 'form/formatters';
13import { DEFAULT_HD_PATH } from 'lib/constants';
15import { DEFAULT_HD_PATH } from 'lib/constants';
14import InputSigil from 'components/InputSigil';
16import InputSigil from 'components/InputSigil';
19+ StatelessTextInputProps,
15−import { StatelessTextInput } from '@tlon/indigo-react';
20+} from '@tlon/indigo-react';
17const PLACEHOLDER_POINT = '~sampel-ponnym';
22const PLACEHOLDER_POINT = '~sampel-ponnym';
18const PLACEHOLDER_HD_PATH = DEFAULT_HD_PATH;
23const PLACEHOLDER_HD_PATH = DEFAULT_HD_PATH;
@@ -210,16 +215,44 @@ export function EmailInput({ ...rest }) {
218+type TicketSegmentInputProps = {
220+ rest: StatelessTextInputProps;
213−export function TicketSegmentInput({ name, ...rest }) {
223+export function TicketSegmentInput({ name, ...rest }: TicketSegmentInputProps) {
214 const { input } = useField(name);
224 const { input } = useField(name);
225+ const { change } = useForm();
227+ const onPaste = (event: React.ClipboardEvent<HTMLInputElement>) => {
229+ const pasteBuffer = event.clipboardData.getData('text');
230+ const patp = ensurePatFormat(pasteBuffer);
231+ if (!ob.isValidPatp(patp)) {
232+ throw new Error('invalid patp');
235+ // prevent pasting the entire clipboard text into the field
236+ event.preventDefault();
238+ const segments = ticketToSegments(pasteBuffer);
239+ change('ticket0', segments[0]);
240+ change('ticket1', segments[1]);
241+ change('ticket2', segments[2]);
242+ change('ticket3', segments[3]);
244+ console.log(`skipping ticket autofill: ${error}`);
217 <StatelessTextInput
249 <StatelessTextInput
218 autoCapitalize="none"
251 autoCapitalize="none"
219 autoCorrect="off"
252 autoCorrect="off"
220 type="text"
253 type="text"
221 maxLength="6"
254 maxLength="6"
222− {...input}
255+ onPaste={onPaste}
223 {...rest}
256 {...rest}