1import { useState, useCallback, useEffect } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
4import { azimuth } from 'azimuth-js';
6import { useNetwork } from 'store/network';
8import useCurrentPermissions from 'lib/useCurrentPermissions';
9import * as need from 'lib/need';
11export function useResidents(point) {
12 const [residents, setResidents] = useState(Nothing());
13 const [residentCount, setResidentCount] = useState(Nothing());
15 const { isParent } = useCurrentPermissions();
16 const { contracts } = useNetwork();
17 const _contracts = need.contracts(contracts);
19 const syncResidentCount = useCallback(async () => {
23 const count = await azimuth.getSponsoringCount(_contracts, point);
24 setResidentCount(Just(count.toNumber()));
25 }, [isParent, setResidentCount, point, _contracts]);
27 const syncResidents = useCallback(async () => {
28 if (Just.hasInstance(residents) || !isParent) {
31 // Galaxies sponsor themselves
32 const children = (await azimuth.getSponsoring(_contracts, point)).filter(
36 setResidents(Just(children));
37 }, [residents, isParent, setResidents, point, _contracts]);
39 const [requests, setRequests] = useState(Nothing);
40 const syncRequests = useCallback(async () => {
41 const reqs = await azimuth.getEscapeRequests(_contracts, point);
42 setRequests(Just(reqs));
43 }, [_contracts, point]);
47 }, [syncResidentCount]);
53 return { residents, residentCount, syncResidents, requests, syncRequests };
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