on master help sign in
Merge pull request #525 from urbit/m/transfer-wo-reset
30dcfcdfang
src/views/AcceptTransfer.js+39−16
@@ -1,6 +1,6 @@
1−import React, { useCallback } from 'react';
1+import React, { useCallback, useMemo } from 'react';
2import cn from 'classnames';
2import cn from 'classnames';
3−import { Grid, Text } from 'indigo-react';
3+import { Grid, Text, CheckboxInput } 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';
@@ -19,6 +19,9 @@ import ViewHeader from 'components/ViewHeader';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
20import View from 'components/View';
20import View from 'components/View';
21
21
22+import BridgeForm from 'form/BridgeForm';
23+import { composeValidator, buildCheckboxValidator } from 'form/validators';
24+
22function useAcceptTransfer() {
25function useAcceptTransfer() {
23 const { contracts } = useNetwork();
26 const { contracts } = useNetwork();
24 const { pointCursor } = usePointCursor();
27 const { pointCursor } = usePointCursor();
@@ -29,15 +32,10 @@ function useAcceptTransfer() {
29 const _point = need.point(pointCursor);
32 const _point = need.point(pointCursor);
30 const _address = need.addressFromWallet(wallet);
33 const _address = need.addressFromWallet(wallet);
31
34
32− const { construct, ...rest } = useEthereumTransaction(
35+ const transaction = useEthereumTransaction(
33 useCallback(
36 useCallback(
34− () =>
37+ reset =>
35− azimuth.ecliptic.transferPoint(
38+ azimuth.ecliptic.transferPoint(_contracts, _point, _address, reset),
36− _contracts,
37− _point,
38− _address,
39− /* reset */ true
40− ),
41 [_contracts, _point, _address]
39 [_contracts, _point, _address]
42 ),
40 ),
43 useCallback(
41 useCallback(
@@ -47,12 +45,8 @@ function useAcceptTransfer() {
47 GAS_LIMITS.TRANSFER
45 GAS_LIMITS.TRANSFER
48 );
46 );
49
47
50− useLifecycle(() => {
51− construct();
52− });
53−
54 return {
48 return {
55− ...rest,
49+ ...transaction,
56 };
50 };
57}
51}
58
52
@@ -61,7 +55,21 @@ export default function AcceptTransfer() {
61
55
62 const name = useCurrentPointName();
56 const name = useCurrentPointName();
63
57
64− const { completed, bind } = useAcceptTransfer();
58+ const { completed, bind, inputsLocked, construct } = useAcceptTransfer();
59+
60+ const initialValues = useMemo(() => ({ noReset: false }), []);
61+
62+ const validate = useMemo(
63+ () => composeValidator({ noReset: buildCheckboxValidator() }),
64+ []
65+ );
66+
67+ const onValues = useCallback(
68+ ({ valid, values, form }) => {
69+ construct(!values.noReset);
70+ },
71+ [construct]
72+ );
65
73
66 return (
74 return (
67 <View pop={pop} inset>
75 <View pop={pop} inset>
@@ -81,6 +89,21 @@ export default function AcceptTransfer() {
81 : `Accept the incoming transfer of ${name}.`}
89 : `Accept the incoming transfer of ${name}.`}
82 </Grid.Item>
90 </Grid.Item>
83
91
92+ <BridgeForm
93+ validate={validate}
94+ initialValues={initialValues}
95+ onValues={onValues}>
96+ {() => (
97+ <Grid.Item
98+ full
99+ as={CheckboxInput}
100+ name="noReset"
101+ label="Retain proxies and key configuration, in case of transferring to self"
102+ disabled={inputsLocked}
103+ />
104+ )}
105+ </BridgeForm>
106+
84 <Grid.Item
107 <Grid.Item
85 full
108 full
86 as={InlineEthereumTransaction}
109 as={InlineEthereumTransaction}