on 5ed1925 help sign in
bridge/src/views/Point.js
131 lines 3.5 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, BootArvoButton } from 'components/Buttons';
13import { matchBlinky } from 'components/Blinky';
14import DownloadSigilButton from 'components/DownloadSigilButton';
16import * as need from 'lib/need';
17import useInvites from 'lib/useInvites';
18import { useSyncOwnedPoints } from 'lib/useSyncPoints';
19import useCurrentPermissions from 'lib/useCurrentPermissions';
20import { useLocalRouter } from 'lib/LocalRouter';
22export default function Point() {
23 const { pop, push, names } = useLocalRouter();
24 const { pointCursor } = usePointCursor();
26 const { wallet } = useWallet();
27 const point = need.point(pointCursor);
29 const {
30 isParent,
31 isActiveOwner,
32 canManage,
33 canSpawn,
34 } = useCurrentPermissions();
36 // fetch the invites for the current cursor
37 const { availableInvites } = useInvites(point);
39 const goAdmin = useCallback(() => push(names.ADMIN), [push, names]);
41 const goInvite = useCallback(() => push(names.INVITE), [push, names]);
43 const goPartiesSetPoolSize = useCallback(
44 () => push(names.PARTY_SET_POOL_SIZE),
45 [push, names]
46 );
48 const goIssuePoint = useCallback(() => push(names.ISSUE_CHILD), [
49 names.ISSUE_CHILD,
50 push,
51 ]);
53 const inviteButton = (() => {
54 switch (azimuth.getPointSize(point)) {
55 case azimuth.PointSize.Planet:
56 const availableInvitesText = matchBlinky(availableInvites);
57 return (
58 <>
59 <Grid.Item
60 full
61 as={ForwardButton}
62 disabled={!isActiveOwner}
63 onClick={goInvite}>
64 Invite <sup>{availableInvitesText}</sup>
65 </Grid.Item>
66 <Grid.Divider />
67 </>
68 );
69 //
70 case azimuth.PointSize.Star:
71 return (
72 <>
73 <Grid.Item
74 full
75 as={ForwardButton}
76 disabled={!isActiveOwner}
77 onClick={goPartiesSetPoolSize}>
78 Manage Invite Pools
79 </Grid.Item>
80 <Grid.Divider />
81 </>
82 );
83 //
84 default:
85 return null;
86 }
87 })();
89 // sync the current cursor
90 useSyncOwnedPoints([point]);
92 const address = need.addressFromWallet(wallet);
94 return (
95 <View pop={pop} inset>
96 <Greeting point={point} />
97 <Passport
98 point={Just(point)}
99 address={Just(address)}
100 animationMode={'slide'}
101 />
102 <Grid className="pt2">
103 {inviteButton}
104 <Grid.Item
105 full
106 as={ForwardButton}
107 disabled={!canManage}
108 onClick={goAdmin}>
109 Admin
110 </Grid.Item>
111 <Grid.Divider />
112 {isParent && (
113 <>
114 <Grid.Item
115 full
116 as={ForwardButton}
117 disabled={!canSpawn}
118 onClick={goIssuePoint}>
119 Issue Point
120 </Grid.Item>
121 <Grid.Divider />
122 </>
123 )}
124 <Grid.Item full as={BootArvoButton} />
125 <Grid.Divider />
126 <Grid.Item full as={DownloadSigilButton} point={point} />
127 <Grid.Divider />
128 </Grid>
129 </View>
130 );