1import { useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
4import { chain } from 'lodash';
6import { useNetwork } from '../network';
7import useSetState from 'lib/useSetState';
9// the default value of a point's invites
10const EMPTY_INVITES = {
11 availableInvites: Nothing(),
12 sentInvites: Nothing(),
13 acceptedInvites: Nothing(),
14 acceptedPoints: Nothing(),
15 pendingPoints: Nothing(),
18export default function useInvitesStore() {
19 const { contracts } = useNetwork();
20 const [invitesCache, addToInvitesCache] = useSetState({});
22 const getInvites = useCallback(
23 point => invitesCache[point] || EMPTY_INVITES,
27 const syncInvites = useCallback(
29 const _contracts = contracts.getOrElse(null);
34 const [availableInvites, invitedPoints] = await Promise.all([
35 azimuth.delegatedSending.getTotalUsableInvites(_contracts, point),
36 azimuth.delegatedSending.getInvited(_contracts, point),
39 const activity = await Promise.all(
40 invitedPoints.map(invitedPoint =>
41 azimuth.azimuth.isActive(_contracts, invitedPoint)
45 const sentInvites = invitedPoints.length;
46 const acceptedInvites = activity.filter(i => !!i).length;
48 const [acceptedPoints, pendingPoints] = chain(invitedPoints)
49 .zipWith(activity, (point, active) => ({
54 .map(arr => arr.map(x => x.point))
59 availableInvites: Just(availableInvites),
60 sentInvites: Just(sentInvites),
61 acceptedInvites: Just(acceptedInvites),
62 pendingPoints: Just(pendingPoints),
63 acceptedPoints: Just(acceptedPoints),
67 [contracts, addToInvitesCache]
70 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