on ca31bdf help sign in
bridge/src/views/Adopt.js
88 lines 2.3 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 { construct, bind, completed } = useAdopt();
50 const body = useMemo(
51 () =>
52 denied ? (
53 <>
54 {completed ? 'Denied' : 'Denying'} adoption request to{' '}
55 <span className="mono">{patp}</span>
56 </>
57 ) : (
58 <>
59 {completed ? 'Approved' : 'Approving'} adoption request to{' '}
60 <span className="mono">{patp}</span>
61 </>
62 ),
63 [patp, denied, completed]
64 );
66 useEffect(() => {
67 construct(adoptee, denied);
68 }, [construct, adoptee, denied]);
70 return (
71 <View pop={() => pop()} inset>
72 <Grid>
73 <Grid.Item full as={ViewHeader} className="mb2">
74 Adopt
75 </Grid.Item>
76 <Grid.Item full className="gray4 f5 mv2">
77 {body}
78 </Grid.Item>
79 <Grid.Item
80 full
81 {...bind}
82 as={InlineEthereumTransaction}
83 onReturn={() => pop()}
84 />
85 </Grid>
86 </View>
87 );