on 4c8c607 help sign in
bridge/src/views/UrbitID/Transfer.js
141 lines 4.3 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';
9import { useStarReleaseCache } from 'store/starRelease';
11import * as need from 'lib/need';
12import { useLocalRouter } from 'lib/LocalRouter';
13import useCurrentPointName from 'lib/useCurrentPointName';
14import useEthereumTransaction from 'lib/useEthereumTransaction';
15import { GAS_LIMITS } from 'lib/constants';
17import ViewHeader from 'components/ViewHeader';
18import NoticeBox from 'components/NoticeBox';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
20import { AddressInput } from 'form/Inputs';
21import { composeValidator, buildAddressValidator } from 'form/validators';
22import BridgeForm from 'form/BridgeForm';
23import FormError from 'form/FormError';
25function useTransfer() {
26 const { contracts } = useNetwork();
27 const { pointCursor } = usePointCursor();
28 const { syncDetails } = usePointCache();
30 const _contracts = need.contracts(contracts);
31 const _point = need.point(pointCursor);
33 return useEthereumTransaction(
34 useCallback(
35 address => azimuth.ecliptic.setTransferProxy(_contracts, _point, address),
36 [_contracts, _point]
37 ),
38 useCallback(() => syncDetails(_point), [_point, syncDetails]),
39 GAS_LIMITS.SET_PROXY
40 );
43export default function AdminTransfer() {
44 const { pop } = useLocalRouter();
45 const name = useCurrentPointName();
46 const { pointCursor } = usePointCursor();
47 const { starReleaseDetails } = useStarReleaseCache();
49 const {
50 construct,
51 unconstruct,
52 completed,
53 inputsLocked,
54 bind,
55 } = useTransfer();
57 const needLockupWarning = useMemo(() => {
58 const point = need.point(pointCursor);
59 const az = azimuth.azimuth;
60 return (
61 az.getPointSize(point) === az.PointSize.Galaxy &&
62 starReleaseDetails.map(a => a.kind).getOrElse('none') !== 'none'
63 );
64 }, [pointCursor, starReleaseDetails]);
66 const validate = useMemo(
67 () => composeValidator({ address: buildAddressValidator() }),
68 []
69 );
71 const onValues = useCallback(
72 ({ valid, values }) => {
73 if (valid) {
74 construct(values.address);
75 } else {
76 unconstruct();
77 }
78 },
79 [construct, unconstruct]
80 );
82 return (
83 <Grid gap={1}>
84 <Grid.Item full as={ViewHeader}>
85 Transfer Point
86 </Grid.Item>
88 <BridgeForm validate={validate} onValues={onValues}>
89 {({ handleSubmit, values }) => (
90 <>
91 {!completed && (
92 <Grid.Item full as={Text} className={cn('f5 wrap')}>
93 Transfer {name} to a new owner.
94 </Grid.Item>
95 )}
96 {!completed && needLockupWarning && (
97 <Grid.Item full as={NoticeBox}>
98 You have stars in lockup. These will not transfer with the{' '}
99 galaxy. If you wish, you must transfer the lockup separately.
100 </Grid.Item>
101 )}
102 {completed && (
103 <>
104 <Grid.Item full as={Text} className="wrap">
105 Started transferring <span className="mono">{name}</span> to{' '}
106 </Grid.Item>
107 <Grid.Item full as={Text}>
108 <span className="mono gray4">{values.address}</span>
109 </Grid.Item>
110 <Grid.Item full as={Text} className="mt6">
111 Until they accept the transfer, you still own{' '}
112 <span className="mono">{name}</span>
113 </Grid.Item>
114 </>
115 )}
117 {!completed && (
118 <Grid.Item
119 full
120 as={AddressInput}
121 className="mv4"
122 name="address"
123 label="Ethereum Address"
124 disabled={inputsLocked}
125 />
126 )}
128 <Grid.Item full as={FormError} />
130 <Grid.Item
131 full
132 as={InlineEthereumTransaction}
133 {...bind}
134 onReturn={() => pop()}
135 />
136 </>
137 )}
138 </BridgeForm>
139 </Grid>
140 );