on bdcbeba help sign in
bridge/src/views/Adopt.js
89 lines 2.4 kB history raw
1import React, { useCallback, useEffect, useMemo } from 'react';
2import { Grid } from 'indigo-react';
3import * as ob from 'urbit-ob';
4import { ecliptic } from 'azimuth-js';
6import View from 'components/View';
7import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
8import ViewHeader from 'components/ViewHeader';
10import { useNetwork } from 'store/network';
11import { usePointCache } from 'store/pointCache';
12import { usePointCursor } from 'store/pointCursor';
13import { useHistory } from 'store/history';
15import { GAS_LIMITS } from 'lib/constants';
16import useEthereumTransaction from 'lib/useEthereumTransaction';
17import * as need from 'lib/need';
19function useAdopt() {
20 const { contracts } = useNetwork();
21 const _contracts = need.contracts(contracts);
23 const { pointCursor } = usePointCursor();
24 const point = need.point(pointCursor);
26 const { syncResidents } = usePointCache();
28 return useEthereumTransaction(
29 useCallback(
30 (adoptee, denied) =>
31 denied
32 ? ecliptic.reject(_contracts, adoptee)
33 : ecliptic.adopt(_contracts, adoptee),
34 [_contracts]
35 ),
36 useCallback(() => syncResidents(point), [syncResidents, point]),
37 GAS_LIMITS.DEFAULT
38 );
41export default function Adopt() {
42 const { pop, data } = useHistory();
44 const { adoptee, denied } = data;
46 const patp = useMemo(() => ob.patp(adoptee), [adoptee]);
48 // const header = //useMemo(() => denied ? 'A Request' : 'Accept Request', [denied]);
49 const { construct, bind, completed } = useAdopt();
51 const body = useMemo(
52 () =>
53 denied ? (
54 <>
55 {completed ? 'Denied' : 'Denying'} adoption request to{' '}
56 <span className="mono">{patp}</span>
57 </>
58 ) : (
59 <>
60 {completed ? 'Approved' : 'Approving'} adoption request to{' '}
61 <span className="mono">{patp}</span>
62 </>
63 ),
64 [patp, denied, completed]
65 );
67 useEffect(() => {
68 construct(adoptee, denied);
69 }, [construct, adoptee, denied]);
71 return (
72 <View pop={() => pop()} inset>
73 <Grid>
74 <Grid.Item full as={ViewHeader} className="mb2">
75 Adopt
76 </Grid.Item>
77 <Grid.Item full className="gray4 f5 mv2">
78 {body}
79 </Grid.Item>
80 <Grid.Item
81 full
82 {...bind}
83 as={InlineEthereumTransaction}
84 onReturn={() => pop()}
85 />
86 </Grid>
87 </View>
88 );