on 5eceb4e help sign in
bridge/src/views/AcceptTransfer.js
116 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 useLifecycle from 'lib/useLifecycle';
16import { useLocalRouter } from 'lib/LocalRouter';
18import ViewHeader from 'components/ViewHeader';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
20import View from 'components/View';
22import BridgeForm from 'form/BridgeForm';
23import { composeValidator, buildCheckboxValidator } from 'form/validators';
25function useAcceptTransfer() {
26 const { contracts } = useNetwork();
27 const { pointCursor } = usePointCursor();
28 const { syncOwnedPoint, syncControlledPoints } = usePointCache();
29 const { wallet } = useWallet();
31 const _contracts = need.contracts(contracts);
32 const _point = need.point(pointCursor);
33 const _address = need.addressFromWallet(wallet);
35 const transaction = useEthereumTransaction(
36 useCallback(
37 reset =>
38 azimuth.ecliptic.transferPoint(_contracts, _point, _address, reset),
39 [_contracts, _point, _address]
40 ),
41 useCallback(
42 () => Promise.all([syncOwnedPoint(_point), syncControlledPoints()]),
43 [_point, syncControlledPoints, syncOwnedPoint]
44 ),
45 GAS_LIMITS.TRANSFER
46 );
48 return {
49 ...transaction,
50 };
53export default function AcceptTransfer() {
54 const { pop } = useLocalRouter();
56 const name = useCurrentPointName();
58 const { completed, bind, inputsLocked, construct } = useAcceptTransfer();
60 const initialValues = useMemo(() => ({ noReset: false }), []);
62 const validate = useMemo(
63 () => composeValidator({ noReset: buildCheckboxValidator() }),
64 []
65 );
67 const onValues = useCallback(
68 ({ valid, values, form }) => {
69 construct(!values.noReset);
70 },
71 [construct]
72 );
74 return (
75 <View pop={pop} inset>
76 <Grid>
77 <Grid.Item full as={ViewHeader}>
78 Accept Transfer
79 </Grid.Item>
81 <Grid.Item
82 full
83 as={Text}
84 className={cn('f5 wrap', {
85 green3: completed,
86 })}>
87 {completed
88 ? `${name} has been accepted.`
89 : `Accept the incoming transfer of ${name}.`}
90 </Grid.Item>
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>
107 <Grid.Item
108 full
109 as={InlineEthereumTransaction}
110 {...bind}
111 onReturn={() => pop()}
112 />
113 </Grid>
114 </View>
115 );