on master help sign in
bridge/src/lib/useHasNetworkKeysSet.tsx
25 lines 914 B history raw
1import { useEffect, useMemo, useState } from 'react';
2import * as need from 'lib/need';
3import { Just } from 'folktale/maybe';
4import { usePointCache } from 'store/pointCache';
5import { usePointCursor } from 'store/pointCursor';
6import { convertToInt } from 'lib/convertToInt';
8export const useHasNetworkKeysSet = () => {
9 const { pointCursor }: any = usePointCursor();
10 const { getDetails }: any = usePointCache();
11 const point = pointCursor.getOrElse(null);
12 const [networkKeysSet, setNetworkKeysSet] = useState<boolean>(true);
14 useEffect(() => {
15 if (point && Just.hasInstance(getDetails(point))) {
16 const details = need.details(getDetails(point));
17 const networkRevision = convertToInt(details.keyRevisionNumber, 10);
18 setNetworkKeysSet(networkRevision > 0);
19 }
20 }, [getDetails, point, pointCursor]);
22 return useMemo(() => {
23 return networkKeysSet;
24 }, [networkKeysSet]);
25};