on a8a2d64 help sign in
bridge/src/views/Admin/AdminTransfer.js
113 lines 3.2 kB history raw
1import React, { useCallback, useMemo } from 'react';
2import cn from 'classnames';
3import { Grid, Text } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
6import { useNetwork } from 'store/network';
7import { usePointCursor } from 'store/pointCursor';
8import { usePointCache } from 'store/pointCache';
10import * as need from 'lib/need';
11import { useLocalRouter } from 'lib/LocalRouter';
12import useCurrentPointName from 'lib/useCurrentPointName';
13import useEthereumTransaction from 'lib/useEthereumTransaction';
14import { GAS_LIMITS } from 'lib/constants';
16import ViewHeader from 'components/ViewHeader';
17import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
18import { AddressInput } from 'form/Inputs';
19import { composeValidator, buildAddressValidator } from 'form/validators';
20import BridgeForm from 'form/BridgeForm';
21import FormError from 'form/FormError';
23function useTransfer() {
24 const { contracts } = useNetwork();
25 const { pointCursor } = usePointCursor();
26 const { syncDetails } = usePointCache();
28 const _contracts = need.contracts(contracts);
29 const _point = need.point(pointCursor);
31 return useEthereumTransaction(
32 useCallback(
33 address => azimuth.ecliptic.setTransferProxy(_contracts, _point, address),
34 [_contracts, _point]
35 ),
36 useCallback(() => syncDetails(_point), [_point, syncDetails]),
37 GAS_LIMITS.SET_PROXY
38 );
41export default function AdminTransfer() {
42 const { pop } = useLocalRouter();
43 const name = useCurrentPointName();
45 const {
46 construct,
47 unconstruct,
48 completed,
49 inputsLocked,
50 bind,
51 } = useTransfer();
53 const validate = useMemo(
54 () => composeValidator({ address: buildAddressValidator() }),
55 []
56 );
58 const onValues = useCallback(
59 ({ valid, values }) => {
60 if (valid) {
61 construct(values.address);
62 } else {
63 unconstruct();
64 }
65 },
66 [construct, unconstruct]
67 );
69 return (
70 <Grid>
71 <Grid.Item full as={ViewHeader}>
72 Transfer Point
73 </Grid.Item>
75 <BridgeForm validate={validate} onValues={onValues}>
76 {({ handleSubmit, values }) => (
77 <>
78 <Grid.Item
79 full
80 as={Text}
81 className={cn('f5 wrap', {
82 green3: completed,
83 })}>
84 {completed
85 ? `${values.address} is now the Transfer Proxy for ${name} and can accept the transfer by logging into Bridge themselves. Until they accept your transfer, you will still have ownership over ${name}.`
86 : `Transfer ${name} to a new owner.`}
87 </Grid.Item>
89 {!completed && (
90 <Grid.Item
91 full
92 as={AddressInput}
93 className="mv4"
94 name="address"
95 label="Ethereum Address"
96 disabled={inputsLocked}
97 />
98 )}
100 <Grid.Item full as={FormError} />
102 <Grid.Item
103 full
104 as={InlineEthereumTransaction}
105 {...bind}
106 onReturn={() => pop()}
107 />
108 </>
109 )}
110 </BridgeForm>
111 </Grid>
112 );