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