on d760cbf help sign in
bridge/src/views/Point.js
89 lines 2.5 kB history raw
1import React, { useCallback } from 'react';
2import { Just } from 'folktale/maybe';
3import * as need from 'lib/need';
4import { Grid } from 'indigo-react';
6import { usePointCursor } from 'store/pointCursor';
7import { usePointCache } from 'store/pointCache';
8import { useHistory } from 'store/history';
10import View from 'components/View';
11import Passport from 'components/Passport';
12import { ForwardButton } from 'components/Buttons';
13import FooterButton from 'components/FooterButton';
14import { matchBlinky } from 'components/Blinky';
16import useInvites from 'lib/useInvites';
17import { useSyncOwnedPoints } from 'lib/useSyncPoints';
18import { ROUTE_NAMES } from 'lib/routeNames';
19import { eqAddr } from 'lib/wallet';
21import Actions from './Point/Actions';
22import { useWallet } from 'store/wallet';
24export default function Point() {
25 const history = useHistory();
26 const { pointCursor } = usePointCursor();
27 const { pointCache } = usePointCache();
28 const { wallet } = useWallet();
30 const point = need.point(pointCursor);
32 let canAdmin = false;
33 if (point in pointCache) {
34 canAdmin = wallet.matchWith({
35 Nothing: () => false,
36 Just: wal => {
37 const pointDetails = need.fromPointCache(pointCache, point);
38 const address = need.addressFromWallet(wallet);
39 return (
40 eqAddr(address, pointDetails.owner) ||
41 eqAddr(address, pointDetails.managementProxy)
42 );
43 },
44 });
45 }
47 // fetch the invites for the current cursor
48 const { availableInvites } = useInvites(point);
49 const availableInvitesText = matchBlinky(availableInvites);
51 const showActions = Just.hasInstance(wallet);
53 const goAdmin = useCallback(() => history.push(ROUTE_NAMES.ADMIN), [history]);
55 const goInvite = useCallback(() => history.push(ROUTE_NAMES.INVITE), [
56 history,
57 ]);
59 // sync the current cursor
60 useSyncOwnedPoints([point]);
62 return (
63 <View>
64 <Passport point={Just(point)} />
65 <Grid className="pt2">
66 <Grid.Item
67 full
68 as={ForwardButton}
69 disabled={!canAdmin}
70 onClick={goAdmin}>
71 Admin
72 </Grid.Item>
73 <Grid.Divider />
74 <Grid.Item full as={ForwardButton} detail="Boot your computer" disabled>
75 Boot Arvo
76 </Grid.Item>
77 {showActions && (
78 <Grid.Item full>
79 <Actions />
80 </Grid.Item>
81 )}
82 </Grid>
84 <FooterButton onClick={goInvite}>
85 Invite <sup>{availableInvitesText}</sup>
86 </FooterButton>
87 </View>
88 );