1import { useCallback, useState } from 'react';
2import Maybe from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
5import { useNetwork } from '../network';
7// the default value of a point's invites
9 availableInvites: Maybe.Nothing(),
10 sentInvites: Maybe.Nothing(),
11 acceptedInvites: Maybe.Nothing(),
14export default function useInvitesStore() {
15 const { contracts } = useNetwork();
16 const [invitesCache, _setInvitesCache] = useState({});
18 const addToInvitesCache = useCallback(
20 _setInvitesCache(cache => ({
27 const getInvites = useCallback(
28 point => invitesCache[point] || kEmptyInvites,
32 const syncInvites = useCallback(
34 const _contracts = contracts.getOrElse(null);
39 const [availableInvites, invitedPoints] = await Promise.all([
40 azimuth.delegatedSending.getTotalUsableInvites(_contracts, point),
41 azimuth.delegatedSending.getInvited(_contracts, point),
44 const activity = await Promise.all(
45 invitedPoints.map(invitedPoint =>
46 azimuth.azimuth.isActive(_contracts, invitedPoint)
50 const sentInvites = invitedPoints.length;
51 const acceptedInvites = activity.filter(i => i.active).length;
55 availableInvites: Maybe.Just(availableInvites),
56 sentInvites: Maybe.Just(sentInvites),
57 acceptedInvites: Maybe.Just(acceptedInvites),
61 [contracts, addToInvitesCache]
64 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