on 2be1f8a help sign in
bridge/src/views/AcceptTransfer.js
96 lines 2.6 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 { useHistory } from 'store/history';
10import { useWallet } from 'store/wallet';
12import * as need from 'lib/need';
13import useCurrentPointName from 'lib/useCurrentPointName';
14import useEthereumTransaction from 'lib/useEthereumTransaction';
15import { GAS_LIMITS } from 'lib/constants';
16import useLifecycle from 'lib/useLifecycle';
18import ViewHeader from 'components/ViewHeader';
19import MiniBackButton from 'components/MiniBackButton';
20import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
21import View from 'components/View';
23function useAcceptTransfer() {
24 const { contracts } = useNetwork();
25 const { pointCursor } = usePointCursor();
26 const { syncOwnedPoint, syncControlledPoints } = usePointCache();
27 const { wallet } = useWallet();
29 const _contracts = need.contracts(contracts);
30 const _point = need.point(pointCursor);
31 const _address = need.addressFromWallet(wallet);
33 const { construct, ...rest } = useEthereumTransaction(
34 useCallback(
35 () =>
36 azimuth.ecliptic.transferPoint(
37 _contracts,
38 _point,
39 _address,
40 /* reset */ true
41 ),
42 [_contracts, _point, _address]
43 ),
44 useCallback(
45 () => Promise.all([syncOwnedPoint(_point), syncControlledPoints()]),
46 [_point, syncControlledPoints, syncOwnedPoint]
47 ),
48 GAS_LIMITS.TRANSFER
49 );
51 useLifecycle(() => {
52 construct();
53 });
55 return {
56 ...rest,
57 };
60export default function AcceptTransfer() {
61 const { pop } = useHistory();
63 const name = useCurrentPointName();
65 const { completed, bind } = useAcceptTransfer();
67 return (
68 <View inset>
69 <Grid>
70 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
72 <Grid.Item full as={ViewHeader}>
73 Accept Transfer
74 </Grid.Item>
76 <Grid.Item
77 full
78 as={Text}
79 className={cn('f5', {
80 green3: completed,
81 })}>
82 {completed
83 ? `${name} has been accepted.`
84 : `Accept the incoming transfer of ${name}.`}
85 </Grid.Item>
87 <Grid.Item
88 full
89 as={InlineEthereumTransaction}
90 {...bind}
91 onReturn={() => pop()}
92 />
93 </Grid>
94 </View>
95 );