on fbcd6b6 help sign in
bridge/src/store/lib/usePointStore.js
51 lines 1.5 kB history raw
1import { useCallback } from 'react';
3import useDetailsStore from './useDetailsStore';
4import useBirthdaysStore from './useBirthdaysStore';
5import useInvitesStore from './useInvitesStore';
6import useControlledPointsStore from './useControlledPointsStore';
7import useEclipticOwnerStore from './useEclipticOwnerStore';
9export default function usePointStore() {
10 const { syncDetails, ...details } = useDetailsStore();
11 const { syncBirthday, ...birthdays } = useBirthdaysStore();
12 const { syncInvites, ...invites } = useInvitesStore();
13 const ecliptic = useEclipticOwnerStore();
14 const {
15 syncControlledPoints,
16 ...controlledPoints
17 } = useControlledPointsStore();
19 // sync all of the on-chain info required to display a known point
20 const syncKnownPoint = useCallback(
21 async point => Promise.all([syncBirthday(point)]),
22 [syncBirthday]
23 );
25 // sync all of the on-chain info required to display a foreign point
26 const syncForeignPoint = useCallback(async point => Promise.all([]), []);
28 // sync all of the on-chain info required for a point that the user owns
29 const syncOwnedPoint = useCallback(
30 async point =>
31 Promise.all([
32 syncKnownPoint(point),
33 syncDetails(point),
34 syncInvites(point),
35 ]),
36 [syncKnownPoint, syncDetails, syncInvites]
37 );
39 return {
40 ...details,
41 ...birthdays,
42 ...invites,
43 ...controlledPoints,
44 ...ecliptic,
45 syncInvites,
46 syncControlledPoints,
47 syncKnownPoint,
48 syncOwnedPoint,
49 syncForeignPoint,
50 };