on f1ff0cf help sign in
bridge/src/store/lib/usePointStore.js
39 lines 1.2 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 foreign point
18 const syncForeignPoint = useCallback(
19 async point => Promise.all([syncDetails(point), syncBirthday(point)]),
20 [syncDetails, syncBirthday]
21 );
23 // sync all of the on-chain info required for a point that the user owns
24 const syncOwnedPoint = useCallback(
25 async point => Promise.all([syncForeignPoint(point), syncInvites(point)]),
26 [syncForeignPoint, syncInvites]
27 );
29 return {
30 ...details,
31 ...birthdays,
32 ...invites,
33 ...controlledPoints,
34 syncInvites,
35 syncControlledPoints,
36 syncOwnedPoint,
37 syncForeignPoint,
38 };