on abbbcbc help sign in
bridge/src/views/Admin/AdminTransfer.js
103 lines 2.9 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 confirmed,
32 inputsLocked,
33 bind,
34 } = useEthereumTransaction(GAS_LIMITS.TRANSFER);
36 const construct = useCallback(
37 address =>
38 _construct(
39 azimuth.ecliptic.setTransferProxy(_contracts, _point, address)
40 ),
41 [_construct, _contracts, _point]
42 );
44 // sync point details after success
45 useEffect(() => {
46 if (confirmed) {
47 syncOwnedPoint(_point);
48 }
49 }, [_point, confirmed, syncOwnedPoint]);
51 return {
52 construct,
53 confirmed,
54 inputsLocked,
55 bind,
56 };
59export default function AdminTransfer() {
60 const { pop } = useLocalRouter();
61 const name = useCurrentPointName();
63 const { construct, confirmed, inputsLocked, bind } = useTransfer();
64 const [addressInput, { pass, data: address }] = useAddressInput({
65 name: 'address',
66 label: `Ethereum Address`,
67 disabled: inputsLocked,
68 });
70 useEffect(() => {
71 if (pass) {
72 construct(address);
73 }
74 }, [pass, address, construct]);
76 return (
77 <Grid>
78 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
79 <Grid.Item full as={ViewHeader}>
80 Transfer Point
81 </Grid.Item>
82 <Grid.Item
83 full
84 as={Text}
85 className={cn('f5', {
86 green3: confirmed,
87 })}>
88 {confirmed
89 ? `${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}.`
90 : `Transfer ${name} to a new owner.`}
91 </Grid.Item>
93 <Grid.Item full as={Input} {...addressInput} className="mv4" />
95 <Grid.Item
96 full
97 as={InlineEthereumTransaction}
98 {...bind}
99 onReturn={() => pop()}
100 />
101 </Grid>
102 );