@@ -17,7 +17,6 @@ import { timeout } from 'lib/timeout';
1717import useRoller from 'lib/useRoller';
1818
1919import BridgeForm from 'form/BridgeForm';
20−import Condition from 'form/Condition';
2120import { TicketInput, PassphraseInput, PointInput } from 'form/Inputs';
2221import {
2322 composeValidator,
@@ -53,35 +52,38 @@ export default function Ticket({ className, goHome }: TicketProps) {
5352 const [usePassphrase, setUsePassphrase] = useState(false);
5453 const [useShards, setUseShards] = useState(false);
5554
56− const validateForm = useCallback((values, errors) => {
57− didWarn.current = false;
55+ const validateForm = useCallback(
56+ (values, errors) => {
57+ didWarn.current = false;
5858
59− if (errors.point) {
60− return errors;
61− }
62−
63− if (values.useShards) {
64− if (errors.shard1 || errors.shard2 || errors.shard3) {
65− return errors;
66− }
67− const empty = ['shard1', 'shard2', 'shard3'].filter(s => !values[s]);
68− if (empty.length > 1) {
69− let errors: Record<string, string> = {};
70− empty.forEach(s => {
71− errors[s] = 'Please provide at least two out of three shards.';
72− });
59+ if (errors.point) {
7360 return errors;
7461 }
75− } else {
76− if (errors.ticket) {
77− return errors;
62+
63+ if (useShards) {
64+ if (errors.shard1 || errors.shard2 || errors.shard3) {
65+ return errors;
66+ }
67+ const empty = ['shard1', 'shard2', 'shard3'].filter(s => !values[s]);
68+ if (empty.length > 1) {
69+ let errors: Record<string, string> = {};
70+ empty.forEach(s => {
71+ errors[s] = 'Please provide at least two out of three shards.';
72+ });
73+ return errors;
74+ }
75+ } else {
76+ if (errors.ticket) {
77+ return errors;
78+ }
7879 }
79− }
80− }, []);
80+ },
81+ [useShards]
82+ );
8183
8284 const onSubmit = useCallback(
8385 async values => {
84− const ticket = values.useShards
86+ const ticket = useShards
8587 ? kg.combine(
8688 [values.shard1, values.shard2, values.shard3].map(v =>
8789 v === '' ? undefined : v
@@ -122,41 +124,37 @@ export default function Ticket({ className, goHome }: TicketProps) {
122124 console.error(error);
123125 return {
124126 [FORM_ERROR]: `Unable to derive wallet from ${
125− values.useShards ? 'shards' : 'ticket'
127+ useShards ? 'shards' : 'ticket'
126128 }.`,
127129 };
128130 }
129131 },
130− [setPointCursor, setUrbitWallet, getPoints]
132+ [setPointCursor, setUrbitWallet, getPoints, useShards]
131133 );
132134
135+ const emptyValidator = () => undefined;
136+
133137 const validate = useMemo(
134138 () =>
135139 composeValidator(
136140 {
137− useAdvanced: buildCheckboxValidator(),
138− usePassphrase: buildCheckboxValidator(),
139− useShards: buildCheckboxValidator(),
140141 point: buildPointValidator(4),
141− ticket: buildPatqValidator(),
142− shard1: buildShardValidator(),
143− shard2: buildShardValidator(),
144− shard3: buildShardValidator(),
142+ ticket: useShards ? emptyValidator : buildPatqValidator(),
143+ shard1: useShards ? buildShardValidator() : emptyValidator,
144+ shard2: useShards ? buildShardValidator() : emptyValidator,
145+ shard3: useShards ? buildShardValidator() : emptyValidator,
145146 ticketHidden: buildCheckboxValidator(),
146147 passphrase: buildPassphraseValidator(),
147148 },
148149 validateForm
149150 ),
150− [validateForm]
151+ [validateForm, useShards]
151152 );
152153
153154 const initialValues = useMemo(
154155 () => ({
155156 point: impliedPoint || '',
156− usePasshrase: false,
157− useShards: false,
158157 ticketHidden: true,
159− useAdvanced: false,
160158 }),
161159 [impliedPoint]
162160 );