on b2d092f help sign in
bridge/src/store/lib/usePointStore.js
63 lines 1.8 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 {
16 syncControlledPoints,
17 ...controlledPoints
18 } = useControlledPointsStore();
19 const ecliptic = useEclipticOwnerStore();
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(
29 async point => {
30 syncDetails(point);
31 },
32 [syncDetails]
33 );
35 // sync all of the on-chain info required for a point that the user owns
36 const syncOwnedPoint = useCallback(
37 async point =>
38 Promise.all([
39 syncForeignPoint(point),
40 syncKnownPoint(point),
41 //
42 syncDetails(point),
43 syncInvites(point),
44 ]),
45 [syncForeignPoint, syncKnownPoint, syncDetails, syncInvites]
46 );
48 return {
49 ...details,
50 ...birthdays,
51 ...rekeyDates,
52 ...invites,
53 ...controlledPoints,
54 ...ecliptic,
55 syncDetails,
56 syncRekeyDate,
57 syncInvites,
58 syncControlledPoints,
59 syncKnownPoint,
60 syncOwnedPoint,
61 syncForeignPoint,
62 };