on dffcebf help sign in
bridge/src/views/Admin/AdminTransfer.js
114 lines 3.0 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 { syncOwnedPoint } = usePointCache();
26 const _contracts = need.contracts(contracts);
27 const _point = need.point(pointCursor);
29 const {
30 construct: _construct,
31 unconstruct,
32 confirmed,
33 inputsLocked,
34 bind,
35 } = useEthereumTransaction(GAS_LIMITS.SET_PROXY);
37 const construct = useCallback(
38 address =>
39 _construct(
40 azimuth.ecliptic.setTransferProxy(_contracts, _point, address)
41 ),
42 [_construct, _contracts, _point]
43 );
45 // sync point details after success
46 useEffect(() => {
47 if (confirmed) {
48 syncOwnedPoint(_point);
49 }
50 }, [_point, confirmed, syncOwnedPoint]);
52 return {
53 construct,
54 unconstruct,
55 confirmed,
56 inputsLocked,
57 bind,
58 };
61export default function AdminTransfer() {
62 const { pop } = useLocalRouter();
63 const name = useCurrentPointName();
65 const {
66 construct,
67 unconstruct,
68 confirmed,
69 inputsLocked,
70 bind,
71 } = useTransfer();
73 const [addressInput, { pass, data: address }] = useAddressInput({
74 name: 'address',
75 label: `Ethereum Address`,
76 disabled: inputsLocked,
77 });
79 useEffect(() => {
80 if (pass) {
81 construct(address);
82 } else {
83 unconstruct();
84 }
85 }, [pass, address, construct, unconstruct]);
87 return (
88 <Grid>
89 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
90 <Grid.Item full as={ViewHeader}>
91 Transfer Point
92 </Grid.Item>
93 <Grid.Item
94 full
95 as={Text}
96 className={cn('f5', {
97 green3: confirmed,
98 })}>
99 {confirmed
100 ? `${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}.`
101 : `Transfer ${name} to a new owner.`}
102 </Grid.Item>
104 <Grid.Item full as={Input} {...addressInput} className="mv4" />
106 <Grid.Item
107 full
108 as={InlineEthereumTransaction}
109 {...bind}
110 onReturn={() => pop()}
111 />
112 </Grid>
113 );