on 2fe1d2f help sign in
bridge/src/store/lib/usePointStore.js
54 lines 1.7 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';
10export default function usePointStore() {
11 const { syncDetails, ...details } = useDetailsStore();
12 const { syncBirthday, ...birthdays } = useBirthdaysStore();
13 const { syncRekeyDate, ...rekeyDates } = useRekeyDateStore();
14 const { syncInvites, ...invites } = useInvitesStore();
15 const ecliptic = useEclipticOwnerStore();
16 const {
17 syncControlledPoints,
18 ...controlledPoints
19 } = useControlledPointsStore();
21 // sync all of the on-chain info required to display a known point
22 const syncKnownPoint = useCallback(
23 async point => Promise.all([syncBirthday(point), syncRekeyDate(point)]),
24 [syncBirthday, syncRekeyDate]
25 );
27 // sync all of the on-chain info required to display a foreign point
28 const syncForeignPoint = useCallback(async point => Promise.all([]), []);
30 // sync all of the on-chain info required for a point that the user owns
31 const syncOwnedPoint = useCallback(
32 async point =>
33 Promise.all([
34 syncKnownPoint(point),
35 syncDetails(point),
36 syncInvites(point),
37 ]),
38 [syncKnownPoint, syncDetails, syncInvites]
39 );
41 return {
42 ...details,
43 ...birthdays,
44 ...rekeyDates,
45 ...invites,
46 ...controlledPoints,
47 ...ecliptic,
48 syncInvites,
49 syncControlledPoints,
50 syncKnownPoint,
51 syncOwnedPoint,
52 syncForeignPoint,
53 };