1import { useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
5import { useNetwork } from '../network';
6import useSetState from 'lib/useSetState';
8// the default value of a point's invites
10 availableInvites: Nothing(),
11 sentInvites: Nothing(),
12 acceptedInvites: Nothing(),
15export default function useInvitesStore() {
16 const { contracts } = useNetwork();
17 const [invitesCache, addToInvitesCache] = useSetState({});
19 const getInvites = useCallback(
20 point => invitesCache[point] || EMPTY_INVITES,
24 const syncInvites = useCallback(
26 const _contracts = contracts.getOrElse(null);
31 const [availableInvites, invitedPoints] = await Promise.all([
32 azimuth.delegatedSending.getTotalUsableInvites(_contracts, point),
33 azimuth.delegatedSending.getInvited(_contracts, point),
36 const activity = await Promise.all(
37 invitedPoints.map(invitedPoint =>
38 azimuth.azimuth.isActive(_contracts, invitedPoint)
42 const sentInvites = invitedPoints.length;
43 const acceptedInvites = activity.filter(i => !!i).length;
47 availableInvites: Just(availableInvites),
48 sentInvites: Just(sentInvites),
49 acceptedInvites: Just(acceptedInvites),
53 [contracts, addToInvitesCache]
56 return { getInvites, syncInvites };
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list