on 729283f help sign in
bridge/src/views/Admin/AdminTransfer.js
94 lines 2.7 kB history raw
1import React, { useCallback, useEffect } from 'react';
2import cn from 'classnames';
3import { Grid, Text, Input } 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 { useAddressInput } from 'lib/useInputs';
13import useCurrentPointName from 'lib/useCurrentPointName';
14import useEthereumTransaction from 'lib/useEthereumTransaction';
15import { GAS_LIMITS } from 'lib/constants';
17import ViewHeader from 'components/ViewHeader';
18import MiniBackButton from 'components/MiniBackButton';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
21function useTransfer() {
22 const { contracts } = useNetwork();
23 const { pointCursor } = usePointCursor();
24 const { syncDetails } = usePointCache();
26 const _contracts = need.contracts(contracts);
27 const _point = need.point(pointCursor);
29 return useEthereumTransaction(
30 useCallback(
31 address => azimuth.ecliptic.setTransferProxy(_contracts, _point, address),
32 [_contracts, _point]
33 ),
34 useCallback(() => syncDetails(_point), [_point, syncDetails]),
35 GAS_LIMITS.SET_PROXY
36 );
39export default function AdminTransfer() {
40 const { pop } = useLocalRouter();
41 const name = useCurrentPointName();
43 const {
44 construct,
45 unconstruct,
46 completed,
47 inputsLocked,
48 bind,
49 } = useTransfer();
51 const [addressInput, { pass, data: address }] = useAddressInput({
52 name: 'address',
53 label: `Ethereum Address`,
54 disabled: inputsLocked,
55 });
57 useEffect(() => {
58 if (pass) {
59 construct(address);
60 } else {
61 unconstruct();
62 }
63 }, [pass, address, construct, unconstruct]);
65 return (
66 <Grid>
67 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
68 <Grid.Item full as={ViewHeader}>
69 Transfer Point
70 </Grid.Item>
71 <Grid.Item
72 full
73 as={Text}
74 className={cn('f5', {
75 green3: completed,
76 })}>
77 {completed
78 ? `${address} is now the Transfer Proxy for ${name} and can accept the transfer by logging into Multipass themselves. Until they accept your transfer, you will still have ownership over ${name}.`
79 : `Transfer ${name} to a new owner.`}
80 </Grid.Item>
82 {!completed && (
83 <Grid.Item full as={Input} {...addressInput} className="mv4" />
84 )}
86 <Grid.Item
87 full
88 as={InlineEthereumTransaction}
89 {...bind}
90 onReturn={() => pop()}
91 />
92 </Grid>
93 );