on 8d566ea help sign in
bridge/src/store/lib/usePointStore.js
69 lines 2.0 kB history raw
1import { useCallback } from 'react';
3import useDetailsStore from './useDetailsStore';
4import useBirthdaysStore from './useBirthdaysStore';
5import useRekeyDateStore from './useRekeyDateStore';
6import useInvitesStore from './useInvitesStore';
7import useControlledPointsStore from './useControlledPointsStore';
8import useEclipticOwnerStore from './useEclipticOwnerStore';
9import useResidents from './useResidentsStore';
11export default function usePointStore() {
12 const { syncDetails, ...details } = useDetailsStore();
13 const { syncBirthday, ...birthdays } = useBirthdaysStore();
14 const { syncRekeyDate, ...rekeyDates } = useRekeyDateStore();
15 const { syncInvites, ...invites } = useInvitesStore();
16 const {
17 syncControlledPoints,
18 ...controlledPoints
19 } = useControlledPointsStore();
20 const { syncResidents, syncResidentCount, ...residents } = useResidents();
21 const ecliptic = useEclipticOwnerStore();
23 // sync all of the on-chain info required to display a known point
24 const syncKnownPoint = useCallback(
25 async point => Promise.all([syncBirthday(point), syncRekeyDate(point)]),
26 [syncBirthday, syncRekeyDate]
27 );
29 // sync all of the on-chain info required to display a foreign point
30 const syncForeignPoint = useCallback(async point => {}, []);
32 // sync all of the on-chain info required for a point that the user owns
33 const syncOwnedPoint = useCallback(
34 async point =>
35 Promise.all([
36 syncForeignPoint(point),
37 syncKnownPoint(point),
38 //
39 syncResidentCount(point),
40 syncDetails(point),
41 syncInvites(point),
42 ]),
43 [
44 syncForeignPoint,
45 syncKnownPoint,
46 syncDetails,
47 syncInvites,
48 syncResidentCount,
49 ]
50 );
52 return {
53 ...details,
54 ...birthdays,
55 ...rekeyDates,
56 ...invites,
57 ...controlledPoints,
58 ...ecliptic,
59 ...residents,
60 syncDetails,
61 syncRekeyDate,
62 syncInvites,
63 syncControlledPoints,
64 syncKnownPoint,
65 syncOwnedPoint,
66 syncForeignPoint,
67 syncResidents,
68 };