@@ -1,6 +1,7 @@
11import React from 'react';
2+import * as ob from 'urbit-ob';
23import { Input, AccessoryIcon } from 'indigo-react';
3−import { useField } from 'react-final-form';
4+import { useField, useForm } from 'react-final-form';
45
56import {
67 convertToNumber,
@@ -9,10 +10,14 @@ import {
910 ensurePatFormat,
1011 stripHexPrefix,
1112 ensureHexPrefix,
13+ ticketToSegments,
1214} from 'form/formatters';
1315import { DEFAULT_HD_PATH } from 'lib/constants';
1416import InputSigil from 'components/InputSigil';
15−import { StatelessTextInput } from '@tlon/indigo-react';
17+import {
18+ StatelessTextInput,
19+ StatelessTextInputProps,
20+} from '@tlon/indigo-react';
1621
1722const PLACEHOLDER_POINT = '~sampel-ponnym';
1823const PLACEHOLDER_HD_PATH = DEFAULT_HD_PATH;
@@ -210,16 +215,44 @@ export function EmailInput({ ...rest }) {
210215 );
211216}
212217
213−export function TicketSegmentInput({ name, ...rest }) {
218+type TicketSegmentInputProps = {
219+ name: string;
220+ rest: StatelessTextInputProps;
221+};
222+
223+export function TicketSegmentInput({ name, ...rest }: TicketSegmentInputProps) {
214224 const { input } = useField(name);
225+ const { change } = useForm();
226+
227+ const onPaste = (event: React.ClipboardEvent<HTMLInputElement>) => {
228+ try {
229+ const pasteBuffer = event.clipboardData.getData('text');
230+ const patp = ensurePatFormat(pasteBuffer);
231+ if (!ob.isValidPatp(patp)) {
232+ throw new Error('invalid patp');
233+ }
234+
235+ // prevent pasting the entire clipboard text into the field
236+ event.preventDefault();
237+
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]);
243+ } catch (error) {
244+ console.log(`skipping ticket autofill: ${error}`);
245+ }
246+ };
215247
216248 return (
217249 <StatelessTextInput
250+ {...input}
218251 autoCapitalize="none"
219252 autoCorrect="off"
220253 type="text"
221254 maxLength="6"
222− {...input}
255+ onPaste={onPaste}
223256 {...rest}
224257 />
225258 );