@@ -1,6 +1,6 @@
1−import React, { useCallback, useEffect } from 'react';
1+import React, { useCallback, useMemo } from 'react';
22import cn from 'classnames';
3−import { Grid, Text, Input, Flex, ToggleInput } from 'indigo-react';
3+import { Grid, Text, Flex, ToggleInput } from 'indigo-react';
44import * as azimuth from 'azimuth-js';
55
66import { useNetwork } from 'store/network';
@@ -16,12 +16,18 @@ import * as need from 'lib/need';
1616import { useLocalRouter } from 'lib/LocalRouter';
1717import { ETH_ZERO_ADDR, eqAddr, isZeroAddress } from 'lib/wallet';
1818import capitalize from 'lib/capitalize';
19−import { useAddressInput, useCheckboxInput } from 'lib/useInputs';
2019import useEthereumTransaction from 'lib/useEthereumTransaction';
2120
2221import ViewHeader from 'components/ViewHeader';
2322import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
2423import { GAS_LIMITS } from 'lib/constants';
24+import {
25+ composeValidator,
26+ buildCheckboxValidator,
27+ buildAddressValidator,
28+ AddressInput,
29+} from 'form/Inputs';
30+import BridgeForm from 'form/BridgeForm';
2531
2632const proxyFromDetails = (details, contracts, proxyType) => {
2733 switch (proxyType) {
@@ -107,41 +113,41 @@ export default function AdminSetProxy() {
107113 bind,
108114 } = useSetProxy(data.proxyType);
109115
110− const [unsetInput, { data: isUnsetting }] = useCheckboxInput({
111− name: 'unset',
112− label: 'Unset',
113− inverseLabel: 'Specify',
114− initialValue: false,
115− disabled: inputsLocked,
116− });
117− const [
118− addressInput,
119− { pass: validAddress, data: address },
120− { reset: resetAddress },
121− ] = useAddressInput({
122− name: 'address',
123− label: `New ${properProxyType} Address`,
124− disabled: inputsLocked || isUnsetting,
125− });
126−
127− useEffect(() => {
128− if (isUnsetting) {
129− unset();
130− resetAddress();
131− } else if (validAddress) {
132− construct(address);
133− } else {
134− unconstruct();
116+ const validateForm = useCallback((values, errors) => {
117+ if (!values.unset && errors.address) {
118+ return errors;
135119 }
136− }, [
137− validAddress,
138− address,
139− construct,
140− isUnsetting,
141− unset,
142− unconstruct,
143− resetAddress,
144− ]);
120+
121+ return {};
122+ }, []);
123+
124+ const validate = useMemo(
125+ () =>
126+ composeValidator(
127+ {
128+ unset: buildCheckboxValidator(),
129+ address: buildAddressValidator(),
130+ },
131+ validateForm
132+ ),
133+ [validateForm]
134+ );
135+
136+ const onValues = useCallback(
137+ ({ valid, values, form }) => {
138+ if (valid) {
139+ if (values.unset) {
140+ unset();
141+ form.change('address', '');
142+ } else {
143+ construct(values.address);
144+ }
145+ } else {
146+ unconstruct();
147+ }
148+ },
149+ [construct, unconstruct, unset]
150+ );
145151
146152 const proxyAddress = proxyFromDetails(_details, _contracts, data.proxyType);
147153 const isProxySet = !isZeroAddress(proxyAddress);
@@ -169,27 +175,50 @@ export default function AdminSetProxy() {
169175 {proxyAddressLabel}
170176 </Grid.Item>
171177
172− <Grid.Item full as={Flex} row justify="between" align="center">
173− <Flex.Item
174− flex
175− as={Text}
176− className={cn('mono', {
177− black: !completed && isProxySet,
178− gray4: !completed && !isProxySet,
179− green3: completed,
180− })}>
181− {isProxySet ? proxyAddress : 'Unset'}
182− </Flex.Item>
183− {!completed && isProxySet && (
184− <Flex.Item as={ToggleInput} {...unsetInput} />
178+ <BridgeForm
179+ validate={validate}
180+ onValues={onValues}
181+ onSubmit={() => {}}
182+ initialValues={{ unset: false }}>
183+ {({ handleSubmit, values }) => (
184+ <>
185+ <Grid.Item full as={Flex} row justify="between" align="center">
186+ <Flex.Item
187+ flex
188+ as={Text}
189+ className={cn('mono', {
190+ black: !completed && isProxySet,
191+ gray4: !completed && !isProxySet,
192+ green3: completed,
193+ })}>
194+ {isProxySet ? proxyAddress : 'Unset'}
195+ </Flex.Item>
196+ {!completed && isProxySet && (
197+ <Flex.Item
198+ as={ToggleInput}
199+ name="unset"
200+ label="Unset"
201+ inverseLabel="Specify"
202+ disabled={inputsLocked}
203+ />
204+ )}
205+ </Grid.Item>
206+
207+ {completed ? (
208+ <Grid.Item full className="mb4" />
209+ ) : (
210+ <Grid.Item
211+ full
212+ as={AddressInput}
213+ className="mv4"
214+ name="address"
215+ label={`New ${properProxyType} Address`}
216+ disabled={inputsLocked || values.unset}
217+ />
218+ )}
219+ </>
185220 )}
186− </Grid.Item>
187−
188− {completed ? (
189− <Grid.Item full className="mb4" />
190− ) : (
191− <Grid.Item full as={Input} {...addressInput} className="mv4" />
192− )}
221+ </BridgeForm>
193222
194223 <Grid.Item
195224 full