on e88ec6d help sign in
bridge/src/store/lib/usePointStore.js
74 lines 2.1 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(
31 async point => {
32 syncDetails(point);
33 },
34 [syncDetails]
35 );
37 // sync all of the on-chain info required for a point that the user owns
38 const syncOwnedPoint = useCallback(
39 async point =>
40 Promise.all([
41 syncForeignPoint(point),
42 syncKnownPoint(point),
43 //
44 syncResidentCount(point),
45 syncDetails(point),
46 syncInvites(point),
47 ]),
48 [
49 syncForeignPoint,
50 syncKnownPoint,
51 syncDetails,
52 syncInvites,
53 syncResidentCount,
54 ]
55 );
57 return {
58 ...details,
59 ...birthdays,
60 ...rekeyDates,
61 ...invites,
62 ...controlledPoints,
63 ...ecliptic,
64 ...residents,
65 syncDetails,
66 syncRekeyDate,
67 syncInvites,
68 syncControlledPoints,
69 syncKnownPoint,
70 syncOwnedPoint,
71 syncForeignPoint,
72 syncResidents,
73 };