on a8a2d64 help sign in
bridge/src/views/Point.js
146 lines 3.9 kB history raw
1import React, { useCallback } from 'react';
2import { Just } from 'folktale/maybe';
3import { Grid } from 'indigo-react';
4import { azimuth } from 'azimuth-js';
6import { usePointCursor } from 'store/pointCursor';
7import { useWallet } from 'store/wallet';
9import View from 'components/View';
10import Greeting from 'components/Greeting';
11import Passport from 'components/Passport';
12import { ForwardButton, BootUrbitOSButton } from 'components/Buttons';
13import CopyButton from 'components/CopyButton';
14import { matchBlinky } from 'components/Blinky';
15import DownloadSigilButton from 'components/DownloadSigilButton';
17import * as need from 'lib/need';
18import useInvites from 'lib/useInvites';
19import { useSyncOwnedPoints } from 'lib/useSyncPoints';
20import useCurrentPermissions from 'lib/useCurrentPermissions';
21import { useLocalRouter } from 'lib/LocalRouter';
22import useKeyfileGenerator from 'lib/useKeyfileGenerator';
24export default function Point() {
25 const { pop, push, names } = useLocalRouter();
26 const { pointCursor } = usePointCursor();
28 const { wallet } = useWallet();
29 const point = need.point(pointCursor);
31 const { code, notice } = useKeyfileGenerator();
33 const {
34 isParent,
35 isActiveOwner,
36 canManage,
37 canSpawn,
38 } = useCurrentPermissions();
40 // fetch the invites for the current cursor
41 const { availableInvites } = useInvites(point);
43 const goAdmin = useCallback(() => push(names.ADMIN), [push, names]);
45 const goInvite = useCallback(() => push(names.INVITE), [push, names]);
47 const goPartiesSetPoolSize = useCallback(
48 () => push(names.PARTY_SET_POOL_SIZE),
49 [push, names]
50 );
52 const goIssuePoint = useCallback(() => push(names.ISSUE_CHILD), [
53 names.ISSUE_CHILD,
54 push,
55 ]);
57 const inviteButton = (() => {
58 switch (azimuth.getPointSize(point)) {
59 case azimuth.PointSize.Planet:
60 const availableInvitesText = matchBlinky(availableInvites);
61 return (
62 <>
63 <Grid.Item
64 full
65 as={ForwardButton}
66 disabled={!isActiveOwner}
67 onClick={goInvite}>
68 Invite <sup>{availableInvitesText}</sup>
69 </Grid.Item>
70 <Grid.Divider />
71 </>
72 );
73 //
74 case azimuth.PointSize.Star:
75 return (
76 <>
77 <Grid.Item
78 full
79 as={ForwardButton}
80 disabled={!isActiveOwner}
81 onClick={goPartiesSetPoolSize}>
82 Manage Invite Pools
83 </Grid.Item>
84 <Grid.Divider />
85 </>
86 );
87 //
88 default:
89 return null;
90 }
91 })();
93 // sync the current cursor
94 useSyncOwnedPoints([point]);
96 const address = need.addressFromWallet(wallet);
98 return (
99 <View pop={pop} inset>
100 <Greeting point={point} />
101 <Passport
102 point={Just(point)}
103 address={Just(address)}
104 animationMode={'slide'}
105 />
106 <Grid className="pt2">
107 {inviteButton}
108 <Grid.Item
109 full
110 as={ForwardButton}
111 disabled={!canManage}
112 onClick={goAdmin}>
113 Admin
114 </Grid.Item>
115 <Grid.Divider />
117 {isParent && (
118 <>
119 <Grid.Item
120 full
121 as={ForwardButton}
122 disabled={!canSpawn}
123 onClick={goIssuePoint}>
124 Issue Point
125 </Grid.Item>
126 <Grid.Divider />
127 </>
128 )}
129 <Grid.Item full as={BootUrbitOSButton} />
130 <Grid.Divider />
131 <Grid.Item
132 full
133 as={ForwardButton}
134 accessory={code && <CopyButton text={code} />}
135 detail={code || notice}
136 disabled={!code}
137 detailClassName="mono">
138 Login Code
139 </Grid.Item>
140 <Grid.Divider />
141 <Grid.Item full as={DownloadSigilButton} point={point} />
142 <Grid.Divider />
143 </Grid>
144 </View>
145 );