on 4c8c607 help sign in
bridge/src/views/CancelTransfer.js
95 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 { GAS_LIMITS } from 'lib/constants';
15import { ETH_ZERO_ADDR } from 'lib/wallet';
16import useLifecycle from 'lib/useLifecycle';
18import ViewHeader from 'components/ViewHeader';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
20import View from 'components/ViewHeader';
22function useCancelTransfer() {
23 const { contracts } = useNetwork();
24 const { pointCursor } = usePointCursor();
25 const { syncDetails } = usePointCache();
27 const _contracts = need.contracts(contracts);
28 const _point = need.point(pointCursor);
30 const { construct, ...rest } = useEthereumTransaction(
31 useCallback(
32 () =>
33 azimuth.ecliptic.setTransferProxy(_contracts, _point, ETH_ZERO_ADDR),
34 [_contracts, _point]
35 ),
36 useCallback(() => syncDetails(_point), [_point, syncDetails]),
37 GAS_LIMITS.SET_PROXY
38 );
40 useLifecycle(() => {
41 construct();
42 });
44 return {
45 ...rest,
46 };
49function AdminCancelTransfer() {
50 const { pop } = useLocalRouter();
51 const { getDetails } = usePointCache();
52 const { pointCursor } = usePointCursor();
53 const _point = need.point(pointCursor);
55 const name = useCurrentPointName();
56 const _details = need.details(getDetails(_point));
58 const { completed, bind } = useCancelTransfer();
60 return (
61 <Grid>
62 <Grid.Item full as={ViewHeader}>
63 Cancel Outgoing Transfer
64 </Grid.Item>
66 <Grid.Item
67 full
68 as={Text}
69 className={cn('f5 wrap', {
70 green3: completed,
71 })}>
72 {completed
73 ? `The outgoing transfer of ${name} has been cancelled.`
74 : `Cancel the outgoing transfer of ${name} to ${_details.transferProxy}.`}
75 </Grid.Item>
77 <Grid.Item
78 full
79 as={InlineEthereumTransaction}
80 {...bind}
81 onReturn={() => pop()}
82 />
83 </Grid>
84 );
87export default function CancelTransfer() {
88 const { pop } = useLocalRouter();
90 return (
91 <View pop={pop} inset>
92 <AdminCancelTransfer />
93 </View>
94 );