on 4b0ca21 help sign in
bridge/src/views/CancelTransfer.js
94 lines 2.5 kB history raw
1import React, { useCallback } 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 { ETH_ZERO_ADDR, GAS_LIMITS } from 'lib/constants';
15import useLifecycle from 'lib/useLifecycle';
17import ViewHeader from 'components/ViewHeader';
18import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
19import View from 'components/ViewHeader';
21function useCancelTransfer() {
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 const { construct, ...rest } = useEthereumTransaction(
30 useCallback(
31 () =>
32 azimuth.ecliptic.setTransferProxy(_contracts, _point, ETH_ZERO_ADDR),
33 [_contracts, _point]
34 ),
35 useCallback(() => syncDetails(_point), [_point, syncDetails]),
36 GAS_LIMITS.SET_PROXY
37 );
39 useLifecycle(() => {
40 construct();
41 });
43 return {
44 ...rest,
45 };
48function AdminCancelTransfer() {
49 const { pop } = useLocalRouter();
50 const { getDetails } = usePointCache();
51 const { pointCursor } = usePointCursor();
52 const _point = need.point(pointCursor);
54 const name = useCurrentPointName();
55 const _details = need.details(getDetails(_point));
57 const { completed, bind } = useCancelTransfer();
59 return (
60 <Grid>
61 <Grid.Item full as={ViewHeader}>
62 Cancel Outgoing Transfer
63 </Grid.Item>
65 <Grid.Item
66 full
67 as={Text}
68 className={cn('f5 wrap', {
69 green3: completed,
70 })}>
71 {completed
72 ? `The outgoing transfer of ${name} has been cancelled.`
73 : `Cancel the outgoing transfer of ${name} to ${_details.transferProxy}.`}
74 </Grid.Item>
76 <Grid.Item
77 full
78 as={InlineEthereumTransaction}
79 {...bind}
80 onReturn={() => pop()}
81 />
82 </Grid>
83 );
86export default function CancelTransfer() {
87 const { pop } = useLocalRouter();
89 return (
90 <View pop={pop} inset>
91 <AdminCancelTransfer />
92 </View>
93 );