on fe6ee13 help sign in
bridge/src/views/AcceptTransfer.js
93 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';
9import { useWallet } from 'store/wallet';
11import * as need from 'lib/need';
12import useCurrentPointName from 'lib/useCurrentPointName';
13import useEthereumTransaction from 'lib/useEthereumTransaction';
14import { GAS_LIMITS } from 'lib/constants';
15import useLifecycle from 'lib/useLifecycle';
16import { useLocalRouter } from 'lib/LocalRouter';
18import ViewHeader from 'components/ViewHeader';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
20import View from 'components/View';
22function useAcceptTransfer() {
23 const { contracts } = useNetwork();
24 const { pointCursor } = usePointCursor();
25 const { syncOwnedPoint, syncControlledPoints } = usePointCache();
26 const { wallet } = useWallet();
28 const _contracts = need.contracts(contracts);
29 const _point = need.point(pointCursor);
30 const _address = need.addressFromWallet(wallet);
32 const { construct, ...rest } = useEthereumTransaction(
33 useCallback(
34 () =>
35 azimuth.ecliptic.transferPoint(
36 _contracts,
37 _point,
38 _address,
39 /* reset */ true
40 ),
41 [_contracts, _point, _address]
42 ),
43 useCallback(
44 () => Promise.all([syncOwnedPoint(_point), syncControlledPoints()]),
45 [_point, syncControlledPoints, syncOwnedPoint]
46 ),
47 GAS_LIMITS.TRANSFER
48 );
50 useLifecycle(() => {
51 construct();
52 });
54 return {
55 ...rest,
56 };
59export default function AcceptTransfer() {
60 const { pop } = useLocalRouter();
62 const name = useCurrentPointName();
64 const { completed, bind } = useAcceptTransfer();
66 return (
67 <View pop={pop} inset>
68 <Grid>
69 <Grid.Item full as={ViewHeader}>
70 Accept Transfer
71 </Grid.Item>
73 <Grid.Item
74 full
75 as={Text}
76 className={cn('f5 wrap', {
77 green3: completed,
78 })}>
79 {completed
80 ? `${name} has been accepted.`
81 : `Accept the incoming transfer of ${name}.`}
82 </Grid.Item>
84 <Grid.Item
85 full
86 as={InlineEthereumTransaction}
87 {...bind}
88 onReturn={() => pop()}
89 />
90 </Grid>
91 </View>
92 );