on 2d3487f help sign in
bridge/src/views/AcceptTransfer.js
115 lines 3.2 kB history raw
1import React, { useCallback, useMemo } from 'react';
2import cn from 'classnames';
3import { Grid, Text, CheckboxInput } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
6import { useNetwork } from 'store/network';
7import { usePointCursor } from 'store/pointCursor';
8import { usePointCache } from 'store/pointCache';
9import { useWallet } from 'store/wallet';
11import * as need from 'lib/need';
12import useCurrentPointName from 'lib/useCurrentPointName';
13import useEthereumTransaction from 'lib/useEthereumTransaction';
14import { GAS_LIMITS } from 'lib/constants';
15import { useLocalRouter } from 'lib/LocalRouter';
17import ViewHeader from 'components/ViewHeader';
18import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
19import View from 'components/View';
21import BridgeForm from 'form/BridgeForm';
22import { composeValidator, buildCheckboxValidator } from 'form/validators';
24function useAcceptTransfer() {
25 const { contracts } = useNetwork();
26 const { pointCursor } = usePointCursor();
27 const { syncExtras, syncControlledPoints } = usePointCache();
28 const { wallet } = useWallet();
30 const _contracts = need.contracts(contracts);
31 const _point = need.point(pointCursor);
32 const _address = need.addressFromWallet(wallet);
34 const transaction = useEthereumTransaction(
35 useCallback(
36 reset =>
37 azimuth.ecliptic.transferPoint(_contracts, _point, _address, reset),
38 [_contracts, _point, _address]
39 ),
40 useCallback(
41 () => Promise.all([syncExtras(_point), syncControlledPoints()]),
42 [_point, syncControlledPoints, syncExtras]
43 ),
44 GAS_LIMITS.TRANSFER
45 );
47 return {
48 ...transaction,
49 };
52export default function AcceptTransfer() {
53 const { pop } = useLocalRouter();
55 const name = useCurrentPointName();
57 const { completed, bind, inputsLocked, construct } = useAcceptTransfer();
59 const initialValues = useMemo(() => ({ noReset: false }), []);
61 const validate = useMemo(
62 () => composeValidator({ noReset: buildCheckboxValidator() }),
63 []
64 );
66 const onValues = useCallback(
67 ({ valid, values, form }) => {
68 construct(!values.noReset);
69 },
70 [construct]
71 );
73 return (
74 <View pop={pop} inset>
75 <Grid>
76 <Grid.Item full as={ViewHeader}>
77 Accept Transfer
78 </Grid.Item>
80 <Grid.Item
81 full
82 as={Text}
83 className={cn('f5 wrap', {
84 green3: completed,
85 })}>
86 {completed
87 ? `${name} has been accepted.`
88 : `Accept the incoming transfer of ${name}.`}
89 </Grid.Item>
91 <BridgeForm
92 validate={validate}
93 initialValues={initialValues}
94 onValues={onValues}>
95 {() => (
96 <Grid.Item
97 full
98 as={CheckboxInput}
99 name="noReset"
100 label="Retain proxies and key configuration, in case of transferring to self"
101 disabled={inputsLocked}
102 />
103 )}
104 </BridgeForm>
106 <Grid.Item
107 full
108 as={InlineEthereumTransaction}
109 {...bind}
110 onReturn={() => pop()}
111 />
112 </Grid>
113 </View>
114 );