on master help sign in
fix: minor cleanup across forms

+ use correct Input comonent {HdPath,Address}Input + separate validateForm and asyncValidate form to better handle the 'only return promise if necessary' pattern

commit302442cb6e1106359421f864ea3961a4f4a351a5 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateMon 12 Aug 2019, 16:58 (7 years ago) parent95edabb
5 files changed+36−25
src/views/CreateGalaxy.js+16−4 src/views/Invite/InviteEmail.js+1−1 src/views/IssueChild.js+13−1 src/views/Login/Ledger.js+3−10 src/views/Login/Trezor.js+3−9
src/views/CreateGalaxy.js+16−4
@@ -1,6 +1,6 @@
11import React, { useCallback, useMemo, useState } from 'react';
22import cn from 'classnames';
3−import { Grid, Text, Input } from 'indigo-react';
3+import { Grid, Text } from 'indigo-react';
44import * as azimuth from 'azimuth-js';
55
66import { useNetwork } from 'store/network';
@@ -17,11 +17,12 @@ import ViewHeader from 'components/ViewHeader';
1717import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
1818import View from 'components/View';
1919import BridgeForm from 'form/BridgeForm';
20−import { PointInput } from 'form/Inputs';
20+import { PointInput, AddressInput } from 'form/Inputs';
2121import {
2222 composeValidator,
2323 buildPointValidator,
2424 buildAddressValidator,
25+ hasErrors,
2526} from 'form/validators';
2627import FormError from 'form/FormError';
2728
@@ -59,7 +60,7 @@ export default function CreateGalaxy() {
5960 bind,
6061 } = useCreateGalaxy();
6162
62− const validateForm = useCallback(
63+ const validateFormAsync = useCallback(
6364 async values => {
6465 const currentOwner = await azimuth.azimuth.getOwner(
6566 _contracts,
@@ -74,6 +75,17 @@ export default function CreateGalaxy() {
7475 [_contracts]
7576 );
7677
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+
7789 const validate = useMemo(
7890 () =>
7991 composeValidator(
@@ -129,7 +141,7 @@ export default function CreateGalaxy() {
129141 />
130142 <Grid.Item
131143 full
132− as={Input}
144+ as={AddressInput}
133145 className="mb4"
134146 name="owner"
135147 label="Ethereum Address"
src/views/Invite/InviteEmail.js+1−1
@@ -142,7 +142,7 @@ export default function InviteEmail() {
142142 [getHasReceived]
143143 );
144144
145− const validateForm = useCallback(async (values, errors) => {
145+ const validateForm = useCallback((values, errors) => {
146146 if (hasErrors(errors)) {
147147 return errors;
148148 }
src/views/IssueChild.js+13−1
@@ -24,6 +24,7 @@ import {
2424 composeValidator,
2525 buildPointValidator,
2626 buildAddressValidator,
27+ hasErrors,
2728} from 'form/validators';
2829import BridgeForm from 'form/BridgeForm';
2930import FormError from 'form/FormError';
@@ -81,7 +82,7 @@ export default function IssueChild() {
8182 bind,
8283 } = useIssueChild();
8384
84− const validateForm = useCallback(
85+ const validateFormAsync = useCallback(
8586 async values => {
8687 const point = patp2dec(values.name);
8788 const hasPoint = (await availablePointsPromise).has(point);
@@ -93,6 +94,17 @@ export default function IssueChild() {
9394 [availablePointsPromise]
9495 );
9596
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+
96108 const validate = useMemo(
97109 () =>
98110 composeValidator(
src/views/Login/Ledger.js+3−10
@@ -1,15 +1,7 @@
11import React, { useCallback, useMemo } from 'react';
22import cn from 'classnames';
33import { 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';
135import { times } from 'lodash';
146import * as bip32 from 'bip32';
157import Transport from '@ledgerhq/hw-transport-u2f';
@@ -38,6 +30,7 @@ import FormError from 'form/FormError';
3830import ContinueButton from './ContinueButton';
3931import Condition from 'form/Condition';
4032import { FORM_ERROR } from 'final-form';
33+import { HdPathInput } from 'form/Inputs';
4134
4235const PATH_OPTIONS = [
4336 { text: 'Ledger Live', value: LEDGER_LIVE_PATH },
@@ -176,7 +169,7 @@ export default function Ledger({ className, goHome }) {
176169 {({ handleSubmit }) => (
177170 <>
178171 <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" />
180173 </Condition>
181174
182175 <Condition when="useCustomPath" is={false}>
src/views/Login/Trezor.js+3−9
@@ -4,14 +4,7 @@ import * as bip32 from 'bip32';
44import { times } from 'lodash';
55import TrezorConnect from 'trezor-connect';
66import * 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';
158
169import { useWallet } from 'store/wallet';
1710
@@ -31,6 +24,7 @@ import FormError from 'form/FormError';
3124
3225import ContinueButton from './ContinueButton';
3326import { FORM_ERROR } from 'final-form';
27+import { HdPathInput } from 'form/Inputs';
3428
3529const ACCOUNT_OPTIONS = times(20, i => ({
3630 text: `Account #${i + 1}`,
@@ -118,7 +112,7 @@ export default function Trezor({ className, goHome }) {
118112 {({ handleSubmit }) => (
119113 <>
120114 <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" />
122116 </Condition>
123117
124118 <Condition when="useCustomPath" is={false}>