on master help sign in
fix: minor cleanup across forms
302442cMatt Condon (shrugs)
src/views/CreateGalaxy.js+16−4
@@ -1,6 +1,6 @@
1import React, { useCallback, useMemo, useState } from 'react';
1import React, { useCallback, useMemo, useState } from 'react';
2import cn from 'classnames';
2import cn from 'classnames';
3−import { Grid, Text, Input } from 'indigo-react';
3+import { Grid, Text } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
4import * as azimuth from 'azimuth-js';
5
5
6import { useNetwork } from 'store/network';
6import { useNetwork } from 'store/network';
@@ -17,11 +17,12 @@ import ViewHeader from 'components/ViewHeader';
17import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
17import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
18import View from 'components/View';
18import View from 'components/View';
19import BridgeForm from 'form/BridgeForm';
19import BridgeForm from 'form/BridgeForm';
20−import { PointInput } from 'form/Inputs';
20+import { PointInput, AddressInput } from 'form/Inputs';
21import {
21import {
22 composeValidator,
22 composeValidator,
23 buildPointValidator,
23 buildPointValidator,
24 buildAddressValidator,
24 buildAddressValidator,
25+ hasErrors,
25} from 'form/validators';
26} from 'form/validators';
26import FormError from 'form/FormError';
27import FormError from 'form/FormError';
27
28
@@ -59,7 +60,7 @@ export default function CreateGalaxy() {
59 bind,
60 bind,
60 } = useCreateGalaxy();
61 } = useCreateGalaxy();
61
62
62− const validateForm = useCallback(
63+ const validateFormAsync = useCallback(
63 async values => {
64 async values => {
64 const currentOwner = await azimuth.azimuth.getOwner(
65 const currentOwner = await azimuth.azimuth.getOwner(
65 _contracts,
66 _contracts,
@@ -74,6 +75,17 @@ export default function CreateGalaxy() {
74 [_contracts]
75 [_contracts]
75 );
76 );
76
77
78+ const validateForm = useCallback(
79+ (values, errors) => {
80+ if (hasErrors(errors)) {
81+ return errors;
82+ }
83+
84+ return validateFormAsync(values, errors);
85+ },
86+ [validateFormAsync]
87+ );
88+
77 const validate = useMemo(
89 const validate = useMemo(
78 () =>
90 () =>
79 composeValidator(
91 composeValidator(
@@ -129,7 +141,7 @@ export default function CreateGalaxy() {
129 />
141 />
130 <Grid.Item
142 <Grid.Item
131 full
143 full
132− as={Input}
144+ as={AddressInput}
133 className="mb4"
145 className="mb4"
134 name="owner"
146 name="owner"
135 label="Ethereum Address"
147 label="Ethereum Address"
src/views/Invite/InviteEmail.js+1−1
@@ -142,7 +142,7 @@ export default function InviteEmail() {
142 [getHasReceived]
142 [getHasReceived]
143 );
143 );
144
144
145− const validateForm = useCallback(async (values, errors) => {
145+ const validateForm = useCallback((values, errors) => {
146 if (hasErrors(errors)) {
146 if (hasErrors(errors)) {
147 return errors;
147 return errors;
148 }
148 }
src/views/IssueChild.js+13−1
@@ -24,6 +24,7 @@ import {
24 composeValidator,
24 composeValidator,
25 buildPointValidator,
25 buildPointValidator,
26 buildAddressValidator,
26 buildAddressValidator,
27+ hasErrors,
27} from 'form/validators';
28} from 'form/validators';
28import BridgeForm from 'form/BridgeForm';
29import BridgeForm from 'form/BridgeForm';
29import FormError from 'form/FormError';
30import FormError from 'form/FormError';
@@ -81,7 +82,7 @@ export default function IssueChild() {
81 bind,
82 bind,
82 } = useIssueChild();
83 } = useIssueChild();
83
84
84− const validateForm = useCallback(
85+ const validateFormAsync = useCallback(
85 async values => {
86 async values => {
86 const point = patp2dec(values.name);
87 const point = patp2dec(values.name);
87 const hasPoint = (await availablePointsPromise).has(point);
88 const hasPoint = (await availablePointsPromise).has(point);
@@ -93,6 +94,17 @@ export default function IssueChild() {
93 [availablePointsPromise]
94 [availablePointsPromise]
94 );
95 );
95
96
97+ const validateForm = useCallback(
98+ (values, errors) => {
99+ if (hasErrors(errors)) {
100+ return errors;
101+ }
102+
103+ return validateFormAsync(values, errors);
104+ },
105+ [validateFormAsync]
106+ );
107+
96 const validate = useMemo(
108 const validate = useMemo(
97 () =>
109 () =>
98 composeValidator(
110 composeValidator(
src/views/Login/Ledger.js+3−10
@@ -1,15 +1,7 @@
1import React, { useCallback, useMemo } from 'react';
1import React, { useCallback, useMemo } from 'react';
2import cn from 'classnames';
2import cn from 'classnames';
3import { Just } from 'folktale/maybe';
3import { Just } from 'folktale/maybe';
4−import {
5− P,
6− Text,
7− Input,
8− Grid,
9− H5,
10− CheckboxInput,
11− SelectInput,
12−} from 'indigo-react';
4+import { P, Text, Grid, H5, CheckboxInput, SelectInput } from 'indigo-react';
13import { times } from 'lodash';
5import { times } from 'lodash';
14import * as bip32 from 'bip32';
6import * as bip32 from 'bip32';
15import Transport from '@ledgerhq/hw-transport-u2f';
7import Transport from '@ledgerhq/hw-transport-u2f';
@@ -38,6 +30,7 @@ import FormError from 'form/FormError';
38import ContinueButton from './ContinueButton';
30import ContinueButton from './ContinueButton';
39import Condition from 'form/Condition';
31import Condition from 'form/Condition';
40import { FORM_ERROR } from 'final-form';
32import { FORM_ERROR } from 'final-form';
33+import { HdPathInput } from 'form/Inputs';
41
34
42const PATH_OPTIONS = [
35const PATH_OPTIONS = [
43 { text: 'Ledger Live', value: LEDGER_LIVE_PATH },
36 { text: 'Ledger Live', value: LEDGER_LIVE_PATH },
@@ -176,7 +169,7 @@ export default function Ledger({ className, goHome }) {
176 {({ handleSubmit }) => (
169 {({ handleSubmit }) => (
177 <>
170 <>
178 <Condition when="useCustomPath" is={true}>
171 <Condition when="useCustomPath" is={true}>
179− <Grid.Item full as={Input} name="hdpath" label="HD Path" />
172+ <Grid.Item full as={HdPathInput} name="hdpath" label="HD Path" />
180 </Condition>
173 </Condition>
181
174
182 <Condition when="useCustomPath" is={false}>
175 <Condition when="useCustomPath" is={false}>
src/views/Login/Trezor.js+3−9
@@ -4,14 +4,7 @@ import * as bip32 from 'bip32';
4import { times } from 'lodash';
4import { times } from 'lodash';
5import TrezorConnect from 'trezor-connect';
5import TrezorConnect from 'trezor-connect';
6import * as secp256k1 from 'secp256k1';
6import * as secp256k1 from 'secp256k1';
7−import {
8− Text,
9− Input,
10− Grid,
11− H5,
12− CheckboxInput,
13− SelectInput,
14−} from 'indigo-react';
7+import { Text, Grid, H5, CheckboxInput, SelectInput } from 'indigo-react';
15
8
16import { useWallet } from 'store/wallet';
9import { useWallet } from 'store/wallet';
17
10
@@ -31,6 +24,7 @@ import FormError from 'form/FormError';
31
24
32import ContinueButton from './ContinueButton';
25import ContinueButton from './ContinueButton';
33import { FORM_ERROR } from 'final-form';
26import { FORM_ERROR } from 'final-form';
27+import { HdPathInput } from 'form/Inputs';
34
28
35const ACCOUNT_OPTIONS = times(20, i => ({
29const ACCOUNT_OPTIONS = times(20, i => ({
36 text: `Account #${i + 1}`,
30 text: `Account #${i + 1}`,
@@ -118,7 +112,7 @@ export default function Trezor({ className, goHome }) {
118 {({ handleSubmit }) => (
112 {({ handleSubmit }) => (
119 <>
113 <>
120 <Condition when="useCustomPath" is={true}>
114 <Condition when="useCustomPath" is={true}>
121− <Grid.Item full as={Input} name="hdpath" label="HD Path" />
115+ <Grid.Item full as={HdPathInput} name="hdpath" label="HD Path" />
122 </Condition>
116 </Condition>
123
117
124 <Condition when="useCustomPath" is={false}>
118 <Condition when="useCustomPath" is={false}>