on ea494b6 help sign in
bridge/src/store/lib/usePointStore.js
58 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(async point => {}, []);
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 syncForeignPoint(point),
35 syncKnownPoint(point),
36 //
37 syncDetails(point),
38 syncInvites(point),
39 ]),
40 [syncForeignPoint, syncKnownPoint, syncDetails, syncInvites]
41 );
43 return {
44 ...details,
45 ...birthdays,
46 ...rekeyDates,
47 ...invites,
48 ...controlledPoints,
49 ...ecliptic,
50 syncDetails,
51 syncRekeyDate,
52 syncInvites,
53 syncControlledPoints,
54 syncKnownPoint,
55 syncOwnedPoint,
56 syncForeignPoint,
57 };