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