on master help sign in
login: fixing validation for shards, removing debugging helpers
commit2b425914346adec3ff5054700983b9e9391fb72b authorHunter Miller <hunter@hmiller.dev> dateTue 8 Mar 2022, 16:58 (5 years ago) parent09c909e
5 files changed+35−56
src/form/SubmitButton.js−12 src/form/validators.js−1 src/views/Login/Ticket.tsx+34−40 src/views/Points.tsx−2 src/views/UrbitOS/NetworkKeys.scss+1−1
src/form/SubmitButton.js−12
@@ -15,8 +15,6 @@ export default function SubmitButton({
1515 ...rest
1616}) {
1717 const {
18− values,
19− errors,
2018 valid,
2119 validating,
2220 submitting,
@@ -27,16 +25,6 @@ export default function SubmitButton({
2725 submitSucceeded,
2826 } = useFormState();
2927
30− console.log({
31− values,
32− valid,
33− validating,
34− submitting,
35− hasValidationErrors,
36− errors,
37− submitErrors,
38− });
39−
4028 const onlyWarningInSubmitErrors = onlyHasWarning(submitErrors);
4129
4230 // can submit if:
src/form/validators.js−1
@@ -168,7 +168,6 @@ export const composeValidator = (
168168 // that means our `validating` state flickers the UI and it looks pretty bad.
169169 // The solution is to conditionally return a promise only when necessary.
170170 return values => {
171− debugger;
172171 // ask for field-level errors
173172 const errorsOrPromise = fieldLevelValidator(values);
174173
src/views/Login/Ticket.tsx+34−40
@@ -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,39 +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− errors.ticket = undefined;
65−
66− if (errors.shard1 || errors.shard2 || errors.shard3) {
67− console.log(errors);
68− return errors;
69− }
70− const empty = ['shard1', 'shard2', 'shard3'].filter(s => !values[s]);
71− if (empty.length > 1) {
72− let errors: Record<string, string> = {};
73− empty.forEach(s => {
74− errors[s] = 'Please provide at least two out of three shards.';
75− });
76− console.log(errors);
59+ if (errors.point) {
7760 return errors;
7861 }
79− } else {
80− if (errors.ticket) {
81− 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+ }
8279 }
83− }
84− }, []);
80+ },
81+ [useShards]
82+ );
8583
8684 const onSubmit = useCallback(
8785 async values => {
88− const ticket = values.useShards
86+ const ticket = useShards
8987 ? kg.combine(
9088 [values.shard1, values.shard2, values.shard3].map(v =>
9189 v === '' ? undefined : v
@@ -126,41 +124,37 @@ export default function Ticket({ className, goHome }: TicketProps) {
126124 console.error(error);
127125 return {
128126 [FORM_ERROR]: `Unable to derive wallet from ${
129− values.useShards ? 'shards' : 'ticket'
127+ useShards ? 'shards' : 'ticket'
130128 }.`,
131129 };
132130 }
133131 },
134− [setPointCursor, setUrbitWallet, getPoints]
132+ [setPointCursor, setUrbitWallet, getPoints, useShards]
135133 );
136134
135+ const emptyValidator = () => undefined;
136+
137137 const validate = useMemo(
138138 () =>
139139 composeValidator(
140140 {
141− useAdvanced: buildCheckboxValidator(),
142− usePassphrase: buildCheckboxValidator(),
143− useShards: buildCheckboxValidator(),
144141 point: buildPointValidator(4),
145− ticket: buildPatqValidator(),
146− shard1: buildShardValidator(),
147− shard2: buildShardValidator(),
148− shard3: buildShardValidator(),
142+ ticket: useShards ? emptyValidator : buildPatqValidator(),
143+ shard1: useShards ? buildShardValidator() : emptyValidator,
144+ shard2: useShards ? buildShardValidator() : emptyValidator,
145+ shard3: useShards ? buildShardValidator() : emptyValidator,
149146 ticketHidden: buildCheckboxValidator(),
150147 passphrase: buildPassphraseValidator(),
151148 },
152149 validateForm
153150 ),
154− [validateForm]
151+ [validateForm, useShards]
155152 );
156153
157154 const initialValues = useMemo(
158155 () => ({
159156 point: impliedPoint || '',
160− usePassphrase: false,
161− useShards: false,
162157 ticketHidden: true,
163− useAdvanced: false,
164158 }),
165159 [impliedPoint]
166160 );
src/views/Points.tsx−2
@@ -133,8 +133,6 @@ export default function Points() {
133133 [pointList, rejectedPoints]
134134 );
135135
136− console.log(allPoints, pointList);
137−
138136 // if we can only interact with a single point, jump to the point page.
139137 // if there are any pending transfers, incoming or outgoing, stay on this
140138 // page, because those can only be completed/cancelled here.
src/views/UrbitOS/NetworkKeys.scss+1−1
@@ -24,7 +24,7 @@
2424 }
2525
2626 .contents {
27− height: 448px;
27+ height: 100%;
2828 width: 100%;
2929 display: flex;
3030 flex-direction: column;